c++ - OPENCV desktop capture Part II -


continuing in previous post here opencv destop capture , hwnd2mat function, method capture desktop source in opencv create bitmap screen image hwnd2mat function. done. function create bitmap screen image.but gives weird effect trailing inside video, want normal video source more this one . i've try find cause it, don't know anymore.

#include "opencv2/imgproc.hpp" #include "opencv2/highgui.hpp" #include <windows.h> #include <iostream>  using namespace std; using namespace cv;  mat hwnd2mat(hwnd hwnd) {     hdc hwindowdc, hwindowcompatibledc;      int height, width, srcheight, srcwidth;     hbitmap hbwindow;     mat src;     bitmapinfoheader  bi;      hwindowdc = getdc(hwnd);     hwindowcompatibledc = createcompatibledc(hwindowdc);     setstretchbltmode(hwindowcompatibledc, coloroncolor);      rect windowsize;    // height , width of screen     getclientrect(hwnd, &windowsize);      srcheight = windowsize.bottom;     srcwidth = windowsize.right;     height = windowsize.bottom / 1;  //change whatever size want resize     width = windowsize.right / 1;      src.create(height, width, cv_8uc4);      // create bitmap     hbwindow = createcompatiblebitmap(hwindowdc, width, height);     bi.bisize = sizeof(bitmapinfoheader);    //http://msdn.microsoft.com/en-us/library/windows/window/dd183402%28v=vs.85%29.aspx     bi.biwidth = width;     bi.biheight = -height;  //this line makes draw upside down or not     bi.biplanes = 1;     bi.bibitcount = 32;     bi.bicompression = bi_rgb;     bi.bisizeimage = 0;     bi.bixpelspermeter = 0;     bi.biypelspermeter = 0;     bi.biclrused = 0;     bi.biclrimportant = 0;      // use created device context bitmap     selectobject(hwindowcompatibledc, hbwindow);     // copy window device context bitmap device context     stretchblt(hwindowcompatibledc, 0, 0, width, height, hwindowdc, 0, 0, srcwidth, srcheight, srccopy); //change srccopy notsrccopy wacky colors !     getdibits(hwindowcompatibledc, hbwindow, 0, height, src.data, (bitmapinfo *)&bi, dib_rgb_colors);  //copy hwindowcompatibledc hbwindow      // avoid memory leak     deleteobject(hbwindow);     deletedc(hwindowcompatibledc);     releasedc(hwnd, hwindowdc);      return src; }  int main(int argc, char **argv) {     hwnd hwnddesktop = getdesktopwindow();     namedwindow("output", cv_window_normal);     int key = 0;      while (key != 30 )     {         mat src = hwnd2mat(hwnddesktop);                 // can image processing here         imshow("output", src);         key = waitkey(30); // can change wait time     }     releasecapture();     destroyallwindows();     return 0; } 

using getdesktopwindow() make infinite-mirror-effect, instead that, using window want capture, , me, i'm using findwindowex(), , use spy++ find window want capture, should works. of course go next bug :).


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -