0

in the lower code section I want to blur the rectangles of a face recognition with the help of the function Gaussianblur(frame(roi)).

void drawPred(int classId, float conf, int left, int top, int right, int bottom, Mat& frame)
{
    //Draw a rectangle displaying the bounding box
    rectangle(frame, Point(left, top), Point(right, bottom), Scalar(255, 178, 50),LINE_4);


    //Bluring RoI
    Point leftTop = Point(left, top); 
    Point rightBottom = Point(right, bottom);

    Rect roi = Rect(leftTop, rightBottom); 

    GaussianBlur(frame(roi), frame(roi), Size(5, 5),0);

    //Get the label for the class name and its confidence
    string label = format("%.2f", conf);
    if (!classes.empty())
    {
        CV_Assert(classId < (int)classes.size());
        label = classes[classId] + ":" + label;
    }

    //Display the label at the top of the bounding box
    int baseLine;
    Size labelSize = getTextSize(label, FONT_ITALIC, 0.5, 1, &baseLine);
    top = max(top, labelSize.height);

    putText(frame, label, Point(left, top), FONT_ITALIC, 0.5, Scalar(255, 255, 255), 1);
}

Successfully I am able to execute this code for around 10-15 frames, later at a certain point the code crashes abruptly with the lower error.

OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(3.4.5) 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 cv::Mat::Mat,
file c:\build\3_4_winpack-build-win64-vc15\opencv\modules\core\src\matrix.cpp, line 466

I don't understand what it means and unfortunately don't know how to solve it because my C++ experience isn't good enough. It would help me a lot if you could show me some little tips.

Many thanks and many greetings

deptrai
  • 147
  • 1
  • 9
  • your roi is out of the image – Miki Oct 01 '19 at 14:37
  • Hi. Excuse me very much for asking such bad questions. Can you suggest what one can do when the box is out of the frame? That's my problem. – deptrai Oct 01 '19 at 14:53
  • You can clip it into the image: `Rect roi = Rect(leftTop, rightBottom); cv::Rect frame_roi(0, 0, frame.cols, frame.rows); roi &= frame_roi;`. Then `roi` will be always inside the image (but eventually smaller than the original). – Miki Oct 01 '19 at 15:21

0 Answers0