使用接口上的C 旋转图像

  • 本文关键字:旋转 图像 接口 c++ opencv
  • 更新时间 :
  • 英文 :


我正在使用接口project上的c 中的openCV开发旋转图像。因此,我对此代码有一些问题。P>

            IplImage* source_image = cvLoadImage(ip, 1);
            IplImage *rotate_image = cvCreateImage(cvGetSize(source_image), IPL_DEPTH_8U, 1);
            cvNamedWindow("rotate_image", CV_WINDOW_FREERATIO);
             int angle = 180;
             cvCreateTrackbar("Angle", rotate_image,&angle,360);
             int image_height = source_image.rows / 2;
             int image_width = source_image.cols / 2;

             IplImage *rotatetion = cvCreateImage(cvGetSize(source_image), IPL_DEPTH_8U, 1);
             rotatetion = cv2DRotationMatrix(Point(image_height,image_width),(angle - 180), 1);
             IplImage *rotated_image = cvCreateImage(cvGetSize(rotatetion), IPL_DEPTH_8U, 1);
             cvWarpAffine(dialateImage,Rotated_Image,Rotatetion,dialateImage.size());
             cvShowImage("rotateImage", rotated_image);

来自https://docs.opencv.org/2.4/doc/tutorials/imgproc/imgproc/imgtrans/warp_affine/warp_affine.html

Mat rot_mat( 2, 3, CV_32FC1 );
Mat warp_mat( 2, 3, CV_32FC1 );
Mat src, warp_dst, warp_rotate_dst;
/// Load the image
src = imread( argv[1], 1 );
/// Set the dst image the same type and size as src
warp_dst = Mat::zeros( src.rows, src.cols, src.type() );
/// Compute a rotation matrix with respect to the center of the image
Point center = Point( warp_dst.cols/2, warp_dst.rows/2 );
double angle = -50.0;
double scale = 0.6;
/// Get the rotation matrix with the specifications above
rot_mat = getRotationMatrix2D( center, angle, scale );
/// Rotate the warped image
warpAffine( warp_dst, warp_rotate_dst, rot_mat, warp_dst.size() );

不要像@miki所说的那样使用过时的c api并提出一个明确的问题,而不是"这个代码没有锻炼"。

尝试this.worked。

                         IplImage* source_image;                     
                         IplImage *dest = cvCloneImage(source_image);
                         CvPoint2D32f center;
                         center.x = dest->width / 2;
                         center.y = dest->height / 2;
                         CvMat *mapMatrix = cvCreateMat(2, 3, CV_32FC1);

                         double angle = System::Convert::ToDouble(numericUpDown1->Value);
                         cv2DRotationMatrix(center, angle, 1.0, mapMatrix);
                         cvWarpAffine(source_image, dest, mapMatrix, CV_INTER_LINEAR + CV_WARP_FILL_OUTLIERS, cvScalarAll(0));
                         cvReleaseMat(&mapMatrix);
                         cvShowImage("Rotated", dest);

最新更新