I am having problems printing the values ββof the descriptor matrix obtained using the "calculate" method of any opencv descriptor extractor. I want to print the function descriptor to a file one by one, but whenever I access some element of the descriptor matrix using "at", I get a different value for this element. The following is the for loop that I used to check the output of the descriptor matrix when using 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; }
The second "if" is the "if" test, which I did to see the values ββprinted when accessing the descriptor elements. Now printed
cerr << descriptors.row(i) << endl << endl;
when iterating nF - 2, I have the following result:
[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]
And, as expected, the first two seals inside the second "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;
give me [20]
But two other prints
cerr << (int)descriptors.at<uchar>(i, 0);
and
int test = descriptors.at<uchar>(i, 0); cerr << "i, 0: " << test << endl;
give me 0 instead of 20. The full result that I got for the line nF-2, which I showed earlier, when accessing elements with "at" and printing them:
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
This is not at all what I expected. I've already tried a lot: casting with float, double, unsigned int instead of int and assigning variables to these types; transforming the matrix before printing, copying the matrix, then converting, creating a matrix of descriptors with a different type ... but none of them worked. I suspect this has something to do with the descriptor matrix type, although I'm pretty sure it has a uchar type (I checked with elemSize)
Thanks in advance, and sorry for my english and question size.