【发布时间】:2019-07-03 05:51:17
【问题描述】:
我使用的是 OpenCV 4.0.0 版。我正在尝试将一些图像拼接在一起并修剪生成的图像,虽然我能够缝合图像,但我无法修剪生成的图像。
我的程序不断中止并出现以下错误:
libc++abi.dylib:以 cv::Exception 类型的未捕获异常终止:OpenCV(4.0.0) /Users/RAR/opencv/modules/core/src/umatrix.cpp:545:错误:(- 215:断言失败)0
中止陷阱:6
错误发生在下面代码中的stitched = stitched(cv::boundingRect(c));行。
while (cv::countNonZero(sub) > 0) {
cv::erode(minRect, minRect, cv::Mat()); // Erode the minimum rectangular mask
cv::subtract(minRect, thresh, sub); // Subtract the thresholded image from the minmum rectangular mask (count if there are any non-zero pixels left)
std::vector<std::vector<cv::Point>> cnts4;
cv::findContours(minRect.clone(), cnts4, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
c = cnts4[0];
for (auto iter = cnts4.begin(); iter != cnts4.end(); ++iter) {
if (cv::contourArea(*iter) > cv::contourArea(c)) { // Finds the largest contour (the contour/outline of the stitched image)
c = *iter;
}
}
stitched = stitched(cv::boundingRect(c)); // Extract the bounding box and use the bounding box coordinates to extract the final stitched images
}
为什么会出现这个错误?
【问题讨论】:
-
打印边界矩形的坐标。这些坐标似乎超出了
stitched图像的尺寸 -
@shawn-mathew 我打印出边界矩形的坐标以及缝合的行和列,这就是我得到的:
stitched: cols: 4295 rows: 2867 bounding rect[4274 x 2845 from (11, 12)] stitched: cols: 4274 rows: 2845 bounding rect[4272 x 2843 from (12, 13)]如何检查边界矩形的坐标超出拼接图像的尺寸?