c - Opencv cvSetImageROI坐标问题

标签 c opencv image-processing uiimage crop

在我的应用程序中,我使用 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/

相关文章:

c - C 中的指针可以使用符号 [] 吗?

c++ - 简单密集光流程序 calcOpticalFlowFarneback() openCV 3.2 cpp

python - 在 ubuntu 上使用 Anaconda for python 3.4 安装 opencv

numpy - 当我尝试使用 Keras 预处理功能向图像添加噪声时出现错误参数错误

c - 使用 if 语句打印数组中的最后一个元素

c - 程序在代码块上运行并且停止后

字符串文字的C优化

python - 如何在OpenCV中使用C++在scikit-image中实现SametimeTransform而无需使用EstimateRigidTransform?

image-processing - 基于几何形式检测图像上的物体

c++ - 为什么图像没有合并