title: OpenCV c++ hwnd2mat(screenshot) -> blobFromImage : Error
body: <p>I am working on screen capture object recognition system. 
  My code:</p>
  
  <pre><code>#include "opencv2/imgproc.hpp"
  #include "opencv2/highgui.hpp"
  #include "opencv2/dnn.hpp"
  #include &lt;opencv2/core/utils/trace.hpp&gt;
  #include &lt;Windows.h&gt;
  #include &lt;iostream&gt;
  
  
  using namespace std;
  using namespace cv;
  using namespace cv::dnn;
  
  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;    // get the height and width of the screen
      GetClientRect(hwnd, &amp;windowsize);
  
      srcheight = windowsize.bottom;
      srcwidth = windowsize.right;
      height = windowsize.bottom/1;  //change this to whatever size you want to resize to
      width = windowsize.right/1;
  
      src.create(height,width,CV_8UC4);
  
      // create a 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 is the line that makes it 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 the previously created device context with the bitmap
      SelectObject(hwindowCompatibleDC, hbwindow);
      // copy from the window device context to the bitmap device context
      StretchBlt( hwindowCompatibleDC, 0,0, width, height, hwindowDC, 0, 0,srcwidth,srcheight, SRCCOPY); //change SRCCOPY to NOTSRCCOPY for wacky colors !
      GetDIBits(hwindowCompatibleDC,hbwindow,0,height,src.data,(BITMAPINFO *)&amp;bi,DIB_RGB_COLORS);  //copy from hwindowCompatibleDC to hbwindow
  
      // avoid memory leak
      DeleteObject (hbwindow);
      DeleteDC(hwindowCompatibleDC);
      ReleaseDC(hwnd, hwindowDC);
  
      return src;
  }
  
  string CLASSES[] = {"background", "aeroplane", "bicycle", "bird", "boat",
  "bottle", "bus", "car", "cat", "chair", "cow", "diningtable",
  "dog", "horse", "motorbike", "person", "pottedplant", "sheep",
  "sofa", "train", "tvmonitor"};
  
  float confidenceThreshold = 0.2;
  
  int main(int argc, char **argv) {
      CV_TRACE_FUNCTION();
  
      String modelTxt = "resources/Caffe/MobileNetSSD_deploy.prototxt";
      String modelBin = "resources/Caffe/MobileNetSSD_deploy.caffemodel";
  
      Net net = readNetFromCaffe(modelTxt, modelBin);
      if (net.empty()) {
          std::cerr &lt;&lt; "Can't load network by using the following files: " &lt;&lt; std::endl;
          std::cerr &lt;&lt; "prototxt:   " &lt;&lt; modelTxt &lt;&lt; std::endl;
          std::cerr &lt;&lt; "caffemodel: " &lt;&lt; modelBin &lt;&lt; std::endl;
          exit(-1);
      }
  
      HWND hwndDesktop = GetDesktopWindow();
      //    namedWindow("output", WINDOW_NORMAL);     // Zeby mozna bylo zmieniac rozmiar okna "real-time"
      int key = 0;
  
      //    while( key != 27 ) {
      Mat frame = hwnd2mat(hwndDesktop);
      //        resize(frame, frame, Size(800, 450));
  
  
      //      Mat frame = imread("resources/auto.png");
  
      Mat img2;
      resize(frame, img2, Size(300,300));
  
      Mat inputBlob = blobFromImage(img2, 0.007843, Size(300,300), Scalar(127.5, 127.5, 127.5), false);
  
      net.setInput(inputBlob, "data");
  
      Mat detection = net.forward("detection_out");
      Mat detectionMat(detection.size[2], detection.size[3], CV_32F, detection.ptr&lt;float&gt;());
  
      ostringstream ss;
      for (int i = 0; i &lt; detectionMat.rows; i++) {
  
          float confidence = detectionMat.at&lt;float&gt;(i, 2);
          if (confidence &gt; confidenceThreshold) {
              int idx = static_cast&lt;int&gt;(detectionMat.at&lt;float&gt;(i, 1));
              int xLeftBottom = static_cast&lt;int&gt;(detectionMat.at&lt;float&gt;(i, 3) * frame.cols);
              int yLeftBottom = static_cast&lt;int&gt;(detectionMat.at&lt;float&gt;(i, 4) * frame.rows);
              int xRightTop = static_cast&lt;int&gt;(detectionMat.at&lt;float&gt;(i, 5) * frame.cols);
              int yRightTop = static_cast&lt;int&gt;(detectionMat.at&lt;float&gt;(i, 6) * frame.rows);
  
              Rect object((int)xLeftBottom, (int)yLeftBottom,
                          (int)(xRightTop - xLeftBottom),
                          (int)(yRightTop - yLeftBottom));
  
              rectangle(frame, object, Scalar(0, 255, 0), 2);
  
              cout &lt;&lt; CLASSES[idx] &lt;&lt; ": " &lt;&lt; confidence &lt;&lt; endl;
  
              ss.str("");
              ss &lt;&lt; confidence;
              String conf(ss.str());
              String label = CLASSES[idx] + ": " + conf;
              int baseLine = 0;
              Size labelSize = getTextSize(label, FONT_HERSHEY_SIMPLEX, 0.5, 1, &amp;baseLine);
              putText(frame, label, Point(xLeftBottom, yLeftBottom-10),
                      FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0,255,0));
          }
      }
  
  
  
      imshow("output", frame);
  //        key = waitKey(60);
      waitKey();
  //    }
  
  }
  </code></pre>
  
  <p>When i use exteranl image everything works fine but when i use function called hwnd2mat it throws me exception:</p>
  
  <pre><code>Error: Assertion failed (inputs[0]-&gt;size[1] % blobs[0].size[1] == 0) in forward
  </code></pre>
  
  <p>I don't know what does it mean. I tried to resize image but it doesnt work.</p>
  
  <p>I am using OpenCV-3.4.1 and MobileNetSSD model.
  Thanks in advance.</p>