How to access pixel values of CV_32F/CV_64F Mat?

前端 未结 2 1374
庸人自扰
庸人自扰 2020-12-16 15:28

I was working on homography and whenever I try to check the values of H matrix (type CV_64F) using H.at(i, j) I get random numbers(sometimes garbag

2条回答
  •  既然无缘
    2020-12-16 15:49

    The example below initializes a Hilbert matrix:

    Mat H(100, 100, CV_64F);
    for(int i = 0; i < H.rows; i++)
        for(int j = 0; j < H.cols; j++)
            H.at(i,j)=1./(i+j+1);
    

    Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends on the image from which you are trying to retrieve the data. The table below gives a better insight in this:

    If matrix is of type CV_8U then use Mat.at(y,x).

    If matrix is of type CV_8S then use Mat.at(y,x).

    If matrix is of type CV_16U then use Mat.at(y,x).

    If matrix is of type CV_16S then use Mat.at(y,x).

    If matrix is of type CV_32S then use Mat.at(y,x).

    If matrix is of type CV_32F then use Mat.at(y,x).

    If matrix is of type CV_64F then use Mat.at(y,x).

    (Taken from OpenCV docs)

提交回复
热议问题