在我的应用程序中,我使用opencv来裁剪具有特定坐标的图像,但问题是当我移动左侧的坐标时,它是向上改变,所以我不明白。
//assignment of calculates ration between view resolution and resolution of the photograph
double scaleX = (outPutImage.frame.size.width/newCoordRect.imgWidth);
double scaleY = (outPutImage.frame.size.height/newCoordRect.imgHeight);
//assignment of the values after calculates coordinates
int x = newCoordRect.leftUp.x/(scaleX);
int y = newCoordRect.leftUp.y/(scaleY);
int heigth = ((newCoordRect.rightDown.y-newCoordRect.rightUp.y)/scaleY);
int width = ((newCoordRect.rightDown.x-newCoordRect.leftUp.x)/scaleX);
/* load image */
IplImage *img1 = [[ShareFunction sFunction]CreateIplImageFromUIImage:outPutImage.image];
/* sets the Region of Interest
Note that the rectangle area has to be __INSIDE__ the image */
cvSetImageROI(img1, cvRect(x, y, width, heigth));
/* create destination image
Note that cvGetSize will return the width and the height of ROI */
IplImage *img2 = cvCreateImage(cvGetSize(img1),
img1->depth,
3);
/* copy subimage */
cvCopy(img1, img2, NULL);
/* always reset the Region of Interest */
cvResetImageROI(img1);
retCropImg = [[ShareFunction sFunction]UIImageFromIplImage:img2];
任何想法?
答案 0 :(得分:0)
你的代码似乎是正确的。 看一下图像的方向