Ask Your Question

dan's profile - activity

2019-07-25 23:36:38 -0600 received badge  Notable Question (source)
2019-01-12 06:49:04 -0600 received badge  Popular Question (source)
2017-05-21 22:11:34 -0600 asked a question OpenCV Error: Assertion failed(dims <= 2.....

Hi everyone,

I am trying to map a depth image to color space, the flowing is my code, here W is Calibration parameters. When I run this code, I got a debug error:R6010:

image description

and an opencv error:

OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] && (unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3) - 1))*4) & 15) == elemSize1()) in cv::Mat::at, file e:\opencv\opencv\build\include\opencv2\core\mat.inl.hpp, line 894

I debug the code and find that in row 0 and column 476 of the image a breakpoint is triggered.

Can you help me to point where the problem is and solve it ? Thank you very much.

void Depth2RGB(cv::Mat &src, cv::Mat &dst, const double *W)
{
 double  z;
 int u, v, d;
 uint16_t u_rgb, v_rgb;
 cv::Mat newdepth(dst.rows, dst.cols, CV_8UC1, cv::Scalar(0));
 for (v = 0; v < src.rows; v++)
 {   for (u = 0; u < src.cols; u++)
    {  d = src.at<uchar>(u, v);
        z = (double)d;
        u_rgb = (uint16_t)((W[0] * (double)u + W[1] * (double)v + W[2] + W[3] / z));
        v_rgb = (uint16_t)((W[4] * (double)u + W[5] * (double)v + W[6] + W[7] / z));
        if (u_rgb < 0 && u_rgb >= newdepth.cols && v_rgb < 0 && v_rgb >= newdepth.rows)
        {
            uint16_t *val = (uint16_t *)newdepth.ptr<uchar>(v_rgb)+u_rgb; *val = d;
        }
    }
}
dst = newdepth;
imshow("d2c", dst);
waitKey(20);
}
int main()
{
  Mat src= imread("1.bmp");
  imshow("src", src);
  waitKey();
  if (src.empty())
  {
    fprintf(stderr, "Can not load image ");
    return -1;
  }
const double W[16] = { 1.00000486081, 0.00119301961750504, -0.00679073956934362, 20.1426810061574,
    - 0.00109315663386171,  0.999967551797230,  0.0105309424407768, - 0.675608328833681,
    0.00675706670150231, - 0.0104701823751460,  0.999919983976284,  3.88086541318805,
    0,  0, 0,   1.00000000000002 };
Mat dst(480, 640, CV_8UC1);
Depth2RGB(src, dst, W);

return 0;
}