Comment faire pour capturer le bureau dans OpenCV (ie. transformer une image bitmap dans une Mat)?

Je veux utiliser OpenCV pour le traitement de mon bureau comme si il s'agissait d'un flux vidéo.

Je suis familier avec OpenCV.

Je ne suis pas familier avec l'API Windows.
Je me rends compte il y a d'autres façons de capturer l'écran, mais pour les besoins de ma question, j'en ai besoin pour être fait à l'aide d'OpenCV.

Voici mon (super naïve) code:

HWND hDesktopWnd;
HDC hDesktopDC;
hDesktopWnd=GetDesktopWindow();
hDesktopDC=GetDC(hDesktopWnd);

//get the height and width of the screen
int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
int width = GetSystemMetrics(SM_CXVIRTUALSCREEN);

//create a bitmap
HBITMAP hbDesktop = CreateCompatibleBitmap( hDesktopDC, width, height);

Mat src(height,width,CV_8UC4);
src.data = (uchar*)hbDesktop;

imshow("output",src);  //fails :(

Il y a des questions similaires sur StackOverflow, mais ils sont soit pour le style ancien OpenCV, ou pour le système d'exploitation Android.

Je suis sur windows 7 64x

Opencv 2.4.3

Merci quelqu'un qui peut répondre à cette question.

InformationsquelleAutor john ktejik | 2013-01-03