Trouble with OpenCV. Load a image

Asked By 250 points N/A Posted on -
qa-featured

Hi.

I am a student of CSE. I am doing some project using open CV. I need to load a image and save each of the regions predefined in the program, as a separate image. How do i do it in C++?

For example, suppose I have a form with 8 fields, I shall give the pixels from where to crop and the lengths along with it.

The program should crop the image according to the location.

SHARE
Best Answer by softwaresynthesis
Answered By 0 points N/A #92771

Trouble with OpenCV. Load a image

qa-featured

The concept you are talking about is called Region Of Interest. In short- "ROI". The function for setting region of interest in opencv is

cvSetImageROI();

It takes 2 arguments, first one is the image ( our subject) second one is a rectangle defining the area to be set for ROI.

Answered By 0 points N/A #92773

Trouble with OpenCV. Load a image

qa-featured

OpenCV is a very powerful tool. If you want to do small works you can use CImg.

Link

It is simple and lightweight.

Answered By 250 points N/A #92775

Trouble with OpenCV. Load a image

qa-featured

@Synthesis,

Thanks. But when I type this:

cvSetImageROI(img, 645,1468,565,75);

it says too many arguments.

@Technical

Thanks to you too. But I am afraid I have to do this in OpenCV.

Answered By 0 points N/A #92777

Trouble with OpenCV. Load a image

qa-featured

Thomas,

By rectangle I literally meant a rectangle. Like this one: cvRect(645,1468,565,75)

So you should use : cvSetImageROI(img, cvRect(645,1468,565,75));

Answered By 250 points N/A #92778

Trouble with OpenCV. Load a image

qa-featured

Thanks again synthesis. It was my misinterpretation. But now I have another problem:

cvSetImageROI(img, cvRect(390,290,280,60));
cvSaveImage("part1.bmp",img);

This works fine but when I add another one;

cvSetImageROI(img, cvRect(390,290,280,60));
cvSaveImage("part1.bmp",img);
cvSetImageROI(img, cvRect(1050,924,679,64));
cvSaveImage("part2.bmp",img);

This crashes just after I run it, giving some horrible printings in the screen. Stating cvImg out of bound.  But my whole image is 3072×1024.

Best Answer
Best Answer
Answered By 0 points N/A #92780

Trouble with OpenCV. Load a image

qa-featured

After the first call of setImageROI.

cvSetImageROI(img, cvRect(390,290,280,60));

Your image becomes 280×60. So next when you say

cvSetImageROI(img, cvRect(1050,924,679,64));

It can’t find the 1050 pixel within 280×60

You have to reset the ROI after each call

cvSetImageROI(img, cvRect(390,290,280,60));
cvSaveImage("part1.bmp",img);
cvResetImageROI(img);

cvSetImageROI(img, cvRect(1050,924,679,64));
cvSaveImage("part2.bmp",img);
cvResetImageROI(img);

Answered By 250 points N/A #92781

Trouble with OpenCV. Load a image

qa-featured

You are most welcome Thank you from my heart!

That was a great support.

Answered By 0 points N/A #92783

Trouble with OpenCV. Load a image

qa-featured

You are most welcome

Related Questions