Ask Your Question

write content of namedWindow to a Mat / file

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

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

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

berak gravatar image

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

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,;

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

edit flag offensive delete link more


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 -0500 )edit

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

Moster gravatar imageMoster ( 2013-09-20 07:08:31 -0500 )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 -0500 )edit

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

JohannesZ gravatar image

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

edit flag offensive delete link more


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

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

Question Tools


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

Seen: 725 times

Last updated: Sep 23 '13