2016-01-16 38 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