Domanda

I'm just beginning to learn OpenCV and I would like to ask about how can I possibly use cvSetImageROI in a loop. The problem is that, I would like to divide an image into 9 equal regions and check each region for lines or curves. However, I don't know how to use cvSetImageROI in a loop so that it will automatically go to the next region.

cvSetImageROI(image, one);

This is the function used for getting the regions. Here, "image" is the image from where the region should come from and "one" is the area in rectangle of the specific region to be achieved. How can I possibly move from one rectangle area to another if I would like to check all the 9 regions of the image?

Thank you very much!

È stato utile?

Soluzione

What you could do is split the image(width, height) in rectangles with a width_step = original_width / 3 and height_step = original_height / 3.

Then with a loop like this:

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top