问题描述:

in my app i used opencv to cropped an image with specific coordinate, but the problem it was when i move the coord of the left side it was the up side make change so i didn't understand.

//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];

any idea?

网友答案:

your code seems to be right. Have a look at the orientation of the image

相关阅读:
Top