在我的应用程序中,我使用 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];
有什么想法吗?
最佳答案
你的代码似乎是正确的。 看一下图像的方向
关于c - Opencv cvSetImageROI坐标问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9821141/