打印关键点描述符矩阵opencv的值

Alb*_*o A 8 c++ opencv matrix unsigned-char feature-descriptor

我在打印通过使用任何opencv描述符提取器的'compute'方法获得的描述符矩阵的值时遇到一些麻烦.我想逐个打印一个特征的描述符,但是当我用'at'访问描述符矩阵的某个元素时,我会收到该元素的不同值.以下是'for'循环,用于在使用'at'时测试描述符矩阵的输出值:

for(int i=0; i<nF; i++){

    if(lpx != keypoints[i].pt.x && lpy != keypoints[i].pt.y){
        usedFeatures++;
        cerr << descriptors.row(i) << endl << endl; // printing row of descriptor matrix
        fileS << keypoints[i].pt.y << " " << keypoints[i].pt.x << " ";
        fileS << keypoints[i].size << " " << keypoints[i].angle << endl;

        if(i == nF - 2){
            //printing subvector of descriptor matrix made of the element at row i and col 0
            cerr << "get row i, col 0 " << descriptors.row(i).col(0) << endl;

            //same as before just inverting the order of access
            cerr << "get col 0, row i: " << descriptors.col(0).row(i) << endl;


            //printing the value of the element with 'at'
            cerr << (int)descriptors.at<uchar>(i, 0);

            //creating a new int and giving it the value of element (i, 0) of descriptor matrix. Should be the same
            //value shown on the subvector before
            int test = descriptors.at<uchar>(i, 0);

            //printing value of element
            cerr << "i, 0: " << test << endl;
        }
Run Code Online (Sandbox Code Playgroud)

第二个'if'是一个测试'if'我在访问描述符元素时看到的值.现在,由印刷

cerr << descriptors.row(i) << endl << endl;
Run Code Online (Sandbox Code Playgroud)

在nF - 2迭代中,我得到以下结果:

[20, 11, 0, 18, 51, 3, 0, 3, 133, 50, 0, 0, 0, 0, 0, 11, 133, 18, 0, 0, 0, 0, 0, 3,
119, 2, 0, 0, 0, 0, 0, 2, 19, 5, 0, 4, 55, 27, 1, 1, 133, 25, 0, 1, 4, 1, 0, 22, 133,
18, 0, 0, 0, 0, 0, 14, 131, 13, 1, 0, 0, 0, 0, 1, 12, 1, 0, 1, 56, 133, 25, 13, 133,
14, 0, 0, 3, 8, 20, 80, 133, 38, 0, 0, 0, 0, 0, 51, 106, 11, 1, 0, 0, 0, 0, 23, 0, 0,
0, 0, 19, 126, 70, 11, 23, 0, 0, 0, 0, 9, 83, 133, 53, 1, 0, 0, 0, 0, 2, 133, 26, 
3, 2, 0, 0, 0, 0, 28]
Run Code Online (Sandbox Code Playgroud)

正如预期的那样,前两个打印在第二个'if'中:

cerr << "get row i, col 0 " << descriptors.row(i).col(0) << endl;

cerr << "get col 0, row i: " << descriptors.col(0).row(i) << endl;
Run Code Online (Sandbox Code Playgroud)

给我[20]

但另外两个印刷品

cerr << (int)descriptors.at<uchar>(i, 0);
Run Code Online (Sandbox Code Playgroud)

int test = descriptors.at<uchar>(i, 0);
cerr << "i, 0: " << test << endl;
Run Code Online (Sandbox Code Playgroud)

给我0而不是20.我之前显示的对于nF-2行的完整结果,当使用'at'访问元素并打印它们时:

 0 0 160 65 0 0 48 65 0 0 0 0 0 0 144 65 0 0 76 66
 0 0 64 64 0 0 0 0 0 0 64 64 0 0 5 67 0 0 72 66
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 48 65 0 0 5 67 0 0 144 65 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 64 64 0 0 238 66
 0 0 0 64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 64
Run Code Online (Sandbox Code Playgroud)

这与我的期望完全不同.我已经尝试了很多东西:使用float,double,unsigned int而不是仅使用int进行转换,并分配给这些类型的变量; 在打印矩阵之前转换矩阵,复制矩阵然后转换,创建具有不同类型的描述符矩阵......但它们都没有工作.我怀疑它与描述符矩阵的类型有关,虽然我几乎可以肯定它有uchar类型(我用elemSize检查)

在此先感谢,对不起我的英语和问题的大小.

Alb*_*o A 7

找到了答案.这确实是一个类型问题.返回的描述符矩阵的类型不像我想的那样是uchar,它实际上是浮点数.获得价值

(float)descriptors.at<float>(i, 0);
Run Code Online (Sandbox Code Playgroud)

给了我正确的价值.有趣的是我可以发誓我以前尝试过漂浮它,它没有用.我一定只尝试过int,double和unsigned int.