English 中文(简体)
循环中的cvSetImageROI
原标题:cvSetImageROI in a loop

我刚刚开始学习OpenCV,我想问一下如何在循环中使用cvSetImageROI。问题是,我想将图像划分为9个相等的区域,并检查每个区域的直线或曲线。然而,我不知道如何在循环中使用cvSetImageROI,以便它自动转到下一个区域。

cvSetImageROI(image, one);

这是用于获取区域的函数。这里,“图像”是区域应该来自的图像,“一”是要实现的特定区域的矩形区域。如果我想检查图像的所有9个区域,我如何可能从一个矩形区域移动到另一个区域?

非常感谢!

最佳回答

您可以做的是将图像(宽度、高度)拆分为矩形,其中width_step=original_width/3,height_step=original_height/3。

然后用这样的循环:

for (i = 0; i < 3; i++)
   for (j = 0; j < 3; j++) 
   {
     CvRect rect;
     rect.x = i * width_step;
     rect.y = j * height_step;
     if (i < 2)
        rect.width = width_step;
     else
        rect.width = image.width - rect.x;
     if (j < 2)
        rect.height = height_step;
     else
        rect.height = image.height - rect.y; 
     cvSetImageROI(image, rect);
   }

you go over each region. Hope this helps, the code has not been tested.

问题回答

暂无回答




相关问题
Python/OpenCV: Converting images taken from capture

I m trying to convert images taken from a capture (webcam) and do some processing on them with OpenCV, but I m having a difficult time.. When trying to convert the image to grayscale, the program ...

How to smooth a histogram?

I want to smooth a histogram. Therefore I tried to smooth the internal matrix of cvHistogram. typedef struct CvHistogram { int type; CvArr* bins; float thresh[CV_MAX_DIM][2]; /* ...

Testing complex datatypes?

What s are some ways of testing complex data types such as video, images, music, etc. I m using TDD and wonder are there alternatives to "gold file" testing for rendering algorithms. I understand that ...

Displaying OpenCV iplimage data structures with wxPython

Here is my current code (language is Python): newFrameImage = cv.QueryFrame(webcam) newFrameImageFile = cv.SaveImage("temp.jpg",newFrameImage) wxImage = wx.Image("temp.jpg", wx.BITMAP_TYPE_ANY)....

What is the memory structure of OpenCV s cvMat?

Imagine I have the following: CvMat* mat = cvCreateMat(3,3,CV_16SC3) This is a 3x3 matrix of integers of channel 3. Now if you look at OpenCV documentation you will find the following as the ...

Face detection and comparison

I m running a small research on face detection and comparison for my article. Currently, I m using rapid face detection based on haar like features based on OpenCV cascade (I ll implement learning ...

热门标签