cygwin_exception::open_stackdumpfile: Dumping stack trace to myfile.exe.stackdump [closed]
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;
}
oh mercy, not opencv's dead c-api !
Can you help me to re-write cote to c++ api?
most tutorial use c-api, so most of my code is writed in this style
Maybe it is deprecated, but it works, and new c++ api does not. The problem is new cv::Mat class.
the c-api died in 2010. please use more recent tutorials
all your problems will go away, once you drop the silly IplImage*
also, please do not use new on cv::Mat, and pass it via reference not as a pointer
I do not know how, but you was right, problems was solved, when I refused IplImage.