Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

best way to check Mat empty/size and ROI size

Is below if a good way to check if i am going out of bounds when copying Mats into a ROI ? Below solved a lot of problems but it still crashes occasionally with:

 Camera dropped frame!
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <=      roi.height && roi.y + roi.height <= m.rows) in Mat, file /tmp/opencv-20160502-20452-13c59z2/opencv-2.4.12/modules/core/src/matrix.cpp, line 323
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /tmp/opencv-20160502-20452-13c59z2/opencv-2.4.12/modules/core/src/matrix.cpp:323: error: (-215) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function Mat


 int pos_x = std::max(face_i.tl().x, 0); // Used to be x-10
 int pos_y = std::max(face_i.tl().y, 0); // Used to be y-10

        // Do our subviews first:
        if(!face_resized.empty() && pos_x>0 && pos_y>0) { // Check for face
            Mat srcBGR = Mat(face_resized.size(), CV_8UC3);
            cvtColor(face_resized, srcBGR, CV_GRAY2BGR);

            cv::Rect roi = cv::Rect(50,50, srcBGR.cols/2, srcBGR.rows/2);
            cv::Rect roi_dst = cv::Rect(pos_x,pos_y,srcBGR.cols/2,srcBGR.rows/2);
            cv::Mat subview = srcBGR(roi); //
            subview.copyTo(original(roi_dst));

            }

best way to check Mat empty/size and ROI size

Is below if a good way to check if i am going out of bounds when copying Mats into a ROI ? Below solved a lot of problems but it still crashes occasionally with:

 Camera dropped frame!
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <=      roi.height && roi.y + roi.height <= m.rows) in Mat, file /tmp/opencv-20160502-20452-13c59z2/opencv-2.4.12/modules/core/src/matrix.cpp, line 323
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /tmp/opencv-20160502-20452-13c59z2/opencv-2.4.12/modules/core/src/matrix.cpp:323: error: (-215) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function Mat


 int pos_x = std::max(face_i.tl().x, 0); // Used to be x-10
 int pos_y = std::max(face_i.tl().y, 0); // Used to be y-10

        // Do our subviews first:
        if(!face_resized.empty() && pos_x>0 && pos_y>0) { // Check for face
            Mat srcBGR = Mat(face_resized.size(), CV_8UC3);
            cvtColor(face_resized, srcBGR, CV_GRAY2BGR);

            cv::Rect roi = cv::Rect(50,50, srcBGR.cols/2, srcBGR.rows/2);
            cv::Rect roi_dst = cv::Rect(pos_x,pos_y,srcBGR.cols/2,srcBGR.rows/2);
            cv::Mat subview = srcBGR(roi); //
            subview.copyTo(original(roi_dst));

            }