Home  >  Q&A  >  body text

c++ - opencv在访问像素点时终止运行

我进行这样的操作:
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]);

大家讲道理大家讲道理2764 days ago540

reply all(2)I'll reply

  • 阿神

    阿神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.

    reply
    0
  • 阿神

    阿神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.

    reply
    0
  • Cancelreply