OpenCV crop function fatal signal 11

asked 2012-12-10 06:08:58 -0500

Hello I am doing an android app which uses OpenCV to detect rectangles/squares, to detect them I am using functions (modified a bit) from squares.cpp. Points of every square found I am storing in vector<vector<point>> squares, then i pass it to the function which choose the biggest one and store it in vector<point> theBiggestSq. The problem is with the cropping function which code i will paste below (i will post the link to youtube showing the problem too). If the actual square is far enough from the camera it works ok but if i will close it a bit in some point it will hang. I will post the print screen of the problem from LogCat and there are the points printed out (the boundaries points taken from theBiggestSq vector, maybe it will help to find the solution).

void cutAndSave(vector<Point> theBiggestSq, Mat image){
    RotatedRect box = minAreaRect(Mat(theBiggestSq));
    // Draw bounding box in the original image (debug purposes)
    //cv::Point2f vertices[4];
    //for (int i = 0; i < 4; ++i)
    //cv::line(img, vertices[i], vertices[(i + 1) % 4], cv::Scalar(0, 255, 0), 1, CV_AA);
    //cv::imshow("box", img);
    //cv::imwrite("box.png", img);
    // Set Region of Interest to the area defined by the box
    Rect roi;
    roi.x = - (box.size.width / 2);
    roi.y = - (box.size.height / 2);
    roi.width = box.size.width;
    roi.height = box.size.height;
    // Crop the original image to the defined ROI

    //bmp=Bitmap.createBitmap(box.size.width / 2, box.size.height / 2, Bitmap.Config.ARGB_8888);
    Mat crop = image(roi);
    //Mat crop = image(Rect(roi.x, roi.y, roi.width, roi.height)).clone();
    //Utils.matToBitmap(crop*.clone()* ,bmp);
    imwrite("/sdcard/OpenCVTest/1.png", bmp);
    imshow("crop", crop);


video of my app and its problems image description

cords printed respectively are: roi.x roi.y roi.width roi.height

Another problem is that the boundaries drawn should have a green colour but as you see on the video they are distorted (flexed like those boundaries would be made from glass?).

Thank you for any help. I am new in openCV doing it from only one month so please be tolerant.

edit retag flag offensive close merge delete