cygwin_exception::open_stackdumpfile: Dumping stack trace to myfile.exe.stackdump [closed]

asked 2017-09-15 13:43:07 -0600

baravunuw gravatar image

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;
}
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by berak
close date 2017-09-16 03:59:16.909886

Comments

oh mercy, not opencv's dead c-api !

berak gravatar imageberak ( 2017-09-15 13:46:27 -0600 )edit

Can you help me to re-write cote to c++ api?

baravunuw gravatar imagebaravunuw ( 2017-09-15 13:51:01 -0600 )edit

most tutorial use c-api, so most of my code is writed in this style

baravunuw gravatar imagebaravunuw ( 2017-09-15 13:52:00 -0600 )edit

Maybe it is deprecated, but it works, and new c++ api does not. The problem is new cv::Mat class.

baravunuw gravatar imagebaravunuw ( 2017-09-15 14:09:30 -0600 )edit

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

berak gravatar imageberak ( 2017-09-16 03:54:00 -0600 )edit

I do not know how, but you was right, problems was solved, when I refused IplImage.

baravunuw gravatar imagebaravunuw ( 2017-09-19 12:14:36 -0600 )edit