when I tried to src->release(), I have an error, src->deallocate() is ok, src->deallocate() trow error too. Whats wrong?
int w::getAScreenshotAndFindAPicture(int x, int y, int x2, int y2, const char* c){
cv::Mat* src = this->getScreenshot(x, y, x2, y2);
cv::cvtColor(*src, *src, cv::COLOR_RGBA2RGB, 0);
IplImage* img = new _IplImage(*src);
IplImage* imgTemplates = cvLoadImage(c, 1);
IplImage* imgResult = cvCreateImage(cvSize(img->width - imgTemplates->width + 1, img->height - imgTemplates->height + 1), 32, 1);
cvMatchTemplate(img, imgTemplates, imgResult, 1);
double minval, maxval;
CvPoint minLoc, maxLoc;
cvMinMaxLoc(imgResult, &minval, &maxval, &minLoc, &maxLoc);
cvReleaseImage(&img);
cvReleaseImage(&imgTemplates);
src->release();
// src->deallocate();
// delete src;
std::cout <<"k" <<std::endl;;
return maxval - minval;
}
cv::Mat* w::getScreenshot(int x, int y, int width, int height){
HDC hwindowDC,hwindowCompatibleDC;
HBITMAP hbwindow;
cv::Mat* src = new cv::Mat();
BITMAPINFOHEADER bi;
hwindowDC=GetDC(this->hwnd);
hwindowCompatibleDC=CreateCompatibleDC(hwindowDC);
SetStretchBltMode(hwindowCompatibleDC,COLORONCOLOR);
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, x, y, width, height, SRCCOPY); //change SRCCOPY to NOTSRCCOPY for wacky colors !
GetDIBits(hwindowCompatibleDC,hbwindow,0,height,src->data,(BITMAPINFO *)&bi,DIB_RGB_COLORS); //copy from hwindowCompatibleDC to hbwindow
DeleteObject (hbwindow);
DeleteDC(hwindowCompatibleDC);
ReleaseDC(this->hwnd, hwindowDC);
return src;
}