2016-01-16 181 views
0

林试图复制垫到其它基质的一部分,这是我的代码:断言失败

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

ROI:X:1200 Y:608瓦特:356个H: 89(从级联检测数据)

这是回报:

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

+0

我想你只需要熟悉你的调试器... –

回答

0

你需要调用copyTo之前初始化矩形的大小相同的OcrProcess

// 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); 

或者更简单地说,使用clone

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

测试了,仍然同样的问题。 –

+0

然后你还有另一个问题:你的矩形走出图像边界。 – Miki