Ask Your Question
0

Get only a certain area out of an incoming image

asked 2013-04-10 20:59:23 -0600

Cyadd gravatar image

Hi all,

This is my first foray using OpenCV and C++. What I'm trying to do is I have a camera supplying continuous images, 640 x 480. What I want to do is get the lower right hand quadrant, the 4th, if you will, so a rectangle with corners at (340 x 240),(640 x 240),(340 x 480),(640 x 480), if you took the (0 x 0) point to be the bottom left corner of the entire image, if I put it all down correctly. I was trying to read through the function calls OpenCV has, and I think maybe getRectSubPix() might be what I'm looking for? Can anyone give me a definitive yes / no? Or, is there an easier / better way to pull a portion out of the incoming images?

Secondly, I could use the resize() function to then make this smaller area back into 640 x 480?

Thanks for looking at this. I hope I found the right solution and could use those function calls to do what I want to.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-04-11 01:14:23 -0600

updated 2013-04-11 01:15:09 -0600

If you want only a part of your image, consider using ROI (Region Of Interest):

Mat A = imread("myimage.jpg", CV_LOAD_IMAGE_COLOR); // here we'll know the method used (allocate matrix)
Mat D (A, Rect(10, 10, 100, 100) ); // using a rectangle
Mat E = A(Range:all(), Range(1,3)); // using row and column boundaries

Like presented here. You can use the ROI image directly, the headers of D and E and different from A, but they are pointing to the same data.

edit flag offensive delete link more

Comments

Will this working for video, not just singular images? imread() is just for images, correct?

Cyadd gravatar imageCyadd ( 2013-04-11 16:29:01 -0600 )edit
1

The imread part is for image, but with VideoCapture you can retrieve a matrix too, and use the ROI: for D and E images, nothing change if you are using a video or an image.

Mathieu Barnachon gravatar imageMathieu Barnachon ( 2013-04-12 01:19:41 -0600 )edit

Well dang, thanks. I'll give it a try again on Monday when I'm back at school.

Cyadd gravatar imageCyadd ( 2013-04-13 22:50:32 -0600 )edit

Hey, thanks a bunch, after playing with it just a tad, I was able to pull a corner of the incoming image, and resize it.

Cyadd gravatar imageCyadd ( 2013-04-15 17:40:39 -0600 )edit

Question Tools

Stats

Asked: 2013-04-10 20:59:23 -0600

Seen: 496 times

Last updated: Apr 11 '13