Ask Your Question
0

How to access the A-KAZE descriptor values?

asked 2017-12-18 08:41:55 -0600

updated 2017-12-18 08:45:04 -0600

berak gravatar image

Hi, I am trying really hard to access the A-KAZE descriptor values, but all I tryied until now had no effect. I am putting my code here, praying for somebody to help me getting the descriptor values, haha. When I try to use the .at<> function from Mat class, I get this error:

"OpenCV Error: Assertion failed (((((sizeof(size_t)<<28)|0x8442211) >> ((traits::Depth<_Tp>::value) & ((1 << 3) - 1))*4) & 15) == elemSize1()) in cv::Mat::at, file c:\opencv\build\include\opencv2\core\mat.inl.hpp, line 1096"

The 1096 line code means:

 _Tp& Mat::at(int i0, int i1) {
        CV_DbgAssert(dims <= 2);
        CV_DbgAssert(data);
        CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
        CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) <
    (unsigned)(size.p[1] * channels()));
        ***CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value)
    == elemSize1());***
        return ((_Tp*)(data + step.p[0] * i0))[i1]; }

Finally, my source code:

# include "stdafx.h"
# include "opencv2/opencv.hpp"
# include <opencv2/features2d.hpp>
# include <opencv2/imgcodecs.hpp>
# include <vector>
# include "src/utils.h"
#include <string>
#include "iostream"

using namespace std;
using namespace cv;
Mat img = imread("lenna.png", IMREAD_GRAYSCALE);
namedWindow("window", WINDOW_NORMAL);
//imshow("image", img);

Mat homography;
FileStorage fs("../data/H1to3p.xml", FileStorage::READ);
fs.getFirstTopLevelNode() >> homography;

vector<KeyPoint> kpts1;
Mat desc1;

int rows = 0, cols = 0;

Ptr<AKAZE> akaze = AKAZE::create();
akaze->detectAndCompute(img, noArray(), kpts1, desc1);

int col = desc1.total()/kpts1.size();
int row = kpts1.size();

Mat descriptor(row, col, CV_8UC3, cv::Scalar::all(0));

akaze->compute(img, kpts1, descriptor);

//cv::getDescriptorSize(desc1);
Vec3b features = desc1.at<Vec3b>(2, 2);

int nr_kpts = kpts1.size();


//int nr_desc = desc1.size();
//for (int i = 0; i == nr_kpts - 1; i++)
//  cout << kpts1[i];
std::cout << "A-KAZE Results " << descriptor.at<float>(0,0);
waitKey(0);
return 0;
edit retag flag offensive close merge delete

Comments

1

check if image is loaded :

Mat img = imread("lenna.png", IMREAD_GRAYSCALE);
if (img.empty())
    cout << "Image is empty : check file path!";

FileStorage fs("../data/H1to3p.xml", FileStorage::READ);
if (!fs.isOpened())
        cout << "xml file is empty : check file path!";
LBerger gravatar imageLBerger ( 2017-12-18 08:49:24 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-12-18 08:51:19 -0600

berak gravatar image

AKAZE descriptors are uchar Mat's, both Vec3b features = desc1.at<Vec3b>(2, 2); and descriptor.at<float>(0,0); are wrong.

the only correct way would be:

descriptor.at<uchar>(m,n); //  m in [0..descriptor.rows]  n in [0..60]

please try to avoid this kind of coding at all, just print out the whole Mat, like:

cout << descriptor << endl; //
edit flag offensive delete link more

Comments

But what if I want to store this descriptor in a variable to be saved, let's say, in a text file. What kind of variable this should be? Would this work?

textFileVariable << desc1 << endl;

One more thing, the [] caracters would be saved with the descriptor values? If yes, how can I avoid them?

Luis Souza gravatar imageLuis Souza ( 2017-12-18 09:12:18 -0600 )edit

have a look here

if you want to save/read your desciptors to a file, use cv::FileStorage.

berak gravatar imageberak ( 2017-12-18 09:41:37 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-12-18 08:41:55 -0600

Seen: 742 times

Last updated: Dec 18 '17