Ask Your Question

Get AOI/ROI of image/frame from Byte* buffer?

asked 2013-05-15 07:10:37 -0600

MattiasR gravatar image

updated 2013-05-15 07:12:19 -0600

I am currently using directshow as the frame grabber from webcam, and for each frame my software developed with opencv/c++ is called. The data from directshow is a pointer to a BYTE buffer.

For each call to opencv I have to get the whole image (1600x1200 I think), but the AOI/ROI is about 100x100 pixels.

The buffer representing the image is of a RGB 24bit type.

So. Is there a way to copy only the ROI/AOI of the frame with opencv?

I need the high resolution, so I cant just change camera.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-05-15 07:54:01 -0600

updated 2013-05-16 02:45:57 -0600

I would suggest first of all including the frame grabbing by using the VideoCapture class. It will push your captured frame towards a single matrix element, giving you the chance of applying the region of interest operator before your processing.

Some example code:

VideoCapture cap(0); // open the default camera
Mat frame;
cap >> frame; // get a new frame from camera
Rect region_of_interest(50,50,100,100); // generates a 100x100 pixels region of interest, starting at position [50,50] for top left corner.
Mat sub = frame(region_of_interest).clone(); // sub will now contain the region only

Does this suit your needs?


Looking at the logitech forums, it seems there is indeed a C++ interfacing possible with the camera's. This topic goes deeper that.

It states that:

Yes, its called DirectShow - it used to be part of the Direct X SDK but its now on the Platform SDK (and pressumeably the Windows\Vista SDK). The main sample to look at is AmCap - you could probably just google that. DirectShow is COM based so theres VB code too...though C++ is better

So my guess would be to download that amcap code example, look at the source and then try to reconstruct the code you would need to set parameters for your cam.

edit flag offensive delete link more


yes it might fit my needs. But! With directshow I am able to change the resolution of the cam. With only opencv i cant. Can I use this together with directshow?

MattiasR gravatar imageMattiasR ( 2013-05-15 09:03:52 -0600 )edit

Normally a camera manufacturer provides an API to set the parameters of your camera. If a C or C++ API is provided, it can be done quite easily combined with openCV. Pass me the type and name of camera?

StevenPuttemans gravatar imageStevenPuttemans ( 2013-05-15 15:30:08 -0600 )edit

Logitech HD Webcam C510

MattiasR gravatar imageMattiasR ( 2013-05-16 02:26:35 -0600 )edit

Please take a look at my question againg. the thing is that I am using directshow, and it works great. both when configuring the cam (resolution etc) and when capturing frames. What I have problem with is get ROI/AOI of a BYTE buffer. is "frame" a BYTE buffer?

MattiasR gravatar imageMattiasR ( 2013-05-16 06:58:17 -0600 )edit

Question Tools


Asked: 2013-05-15 07:10:37 -0600

Seen: 1,274 times

Last updated: May 16 '13