Ask Your Question
0

write content of namedWindow to a Mat / file

asked 2013-09-20 06:23:50 -0600

JohannesZ gravatar image

Hi there,

in my openCV application (2.4, windows 7 32 bit), I am drawing some openGL content in a cv::namedWindow structure. I works fine, but I am wondering if it is possible to write all of the window content to a cv::Mat or an image file via imwrite?

This would be fine because I don't want to make screenshots everytime I log my results.

Thanks for your help! Johannes

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2013-09-20 06:40:39 -0600

berak gravatar image

updated 2013-09-20 06:43:45 -0600

probably easier, to retrieve the pixels from the opengl context, than from the highgui window:

Mat screen(h,w,CV_8UC3);
glReadPixels (0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, screen.data);

(i'm not sure, but w might need to be a multiple of 4 for this)

edit flag offensive delete link more

Comments

Thanks for your answer. The problem is that the application crashes all the time I call glReadPixels... hm.

JohannesZ gravatar imageJohannesZ ( 2013-09-20 06:56:22 -0600 )edit

You have no error message or something written in the console?

Moster gravatar imageMoster ( 2013-09-20 07:08:31 -0600 )edit

Ok, the image can be written now, but it is black. I will try that w is a multiple of 4.

JohannesZ gravatar imageJohannesZ ( 2013-09-20 07:22:08 -0600 )edit
0

answered 2013-09-23 02:12:07 -0600

JohannesZ gravatar image

Moster, thanks for your advice with glReadPixels! It works now. I also found this on stackoverflow:

http://stackoverflow.com/questions/9097756/converting-data-from-glreadpixels-to-opencvmat

edit flag offensive delete link more

Comments

Then feel free to accept an answer so that this question returns a solved result :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-09-23 04:09:55 -0600 )edit

Question Tools

Stats

Asked: 2013-09-20 06:23:50 -0600

Seen: 977 times

Last updated: Sep 23 '13