0
votes

Im trying to copy a part of Mat to other matrix, this is my code:

Mat OCRprocess;
OCRImage(Rect(plates[i].x, plates[i].y, plates[i].width, plates[i].height)).copyTo(OCRprocess);

ROI: x: 1200 y: 608 w: 356 h: 89 (data from cascade detector)

This is return:

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 cv::Mat::Mat, file C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\ core\src\matrix.cpp, line 495

1
I think you just need to get familiar with your debugger...Nicu Stiurca

1 Answers

0
votes

You need to initialize OcrProcess of the same size of the rectangles before calling copyTo:

// Your rect
Rect r(plates[i].x, plates[i].y, plates[i].width, plates[i].height);
// Initialize the destination image
Mat OCRprocess(r.height, r.width, OCRImage.type());
// Copy
OCRImage(Rect).copyTo(OCRprocess);

Or, more simply, using clone:

Mat OCRprocess = OCRImage(Rect(plates[i].x, plates[i].y, plates[i].width, plates[i].height)).clone();