我进行这样的操作:image_backup_.at<Vec3b>(xpos + i, ypos + j - 1)[k]
就会终止程序,然后debug下发现call stack:定位到上一行image_backup_.at<Vec3b>(xpos + i, ypos + j - 1)[k]
和CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
阿神2017-04-17 15:32:29
The parameters of the at function are at (row, column), not x, y, so an out-of-bounds error occurs, and you need to replace the two.
If you must use x and y, you can use at(cv::Point(x,y)).
In addition, opencv will throw exceptions. You can use catch(std::exception e) to catch exceptions and view error information.
阿神2017-04-17 15:32:29
Function named at generally has bounds checking. The check here is implemented through assertions, namely CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
. According to the expression semantics, the reason for assertion failure is that the coordinates are out of bounds "i>=size".
Please check the value range of xpos + i
and ypos + j - 1
. Note: Due to unsigned conversion during checking, values less than 0 will become a larger value.