I'm trying to call the Method getMat()
in a Mat Object. But my compiler throws the Error: "No Member named 'getMat' in 'cv::Mat'"
Here is the Code I'm using.
int dsize = descriptorSize();
_descriptors.create((int)features.size(), dsize, CV_32F);
SOLVED cv::Mat
doesn't have getMat()
need to use cv::InputArray or cv::OutputArray
(Thanks @Berak for mentioning that) or initialize the Mat descriptors = _descriptors.getMat();
the Mat I call the function on is initialized out of the main method Mat _descriptors;
itself. Please look Edit3 for present Error
Edit added Code from the Method
descriptorSize():
//Actually this Method just passes back the Size of the Descriptor size in floats(128)
int descriptorSize() {
return SIFT_DESCR_WIDTH*SIFT_DESCR_WIDTH*SIFT_DESCR_HIST_BINS;
}
After the initialization of descriptors
it is passed to the Method CalcDescriptors
which just sends a pointer of a Value to another Method called CalcSiftDescriptor
calcSiftDescriptor(img, ptf, angle, size*0.f, d, n, descriptors.ptr<float>((int) i));
in this method the pointer is used at this part:
for(i = 0; i < d; i++){
for(j = 0; j < d; j++){
int idx = ((i+1)*(d+2) + (j+1))*(n+2);
hist[idx] += hist[idx+n];
hist[idx+1] += hist[idx+n+1];
for(k = 0; k < n; k++){
dst[(i*d + j)*n + k] = hist[idx+k];
}
}
}
EDIT2
For those, who want to see the full code:
GitHub
EDIT3
After using Mat descriptors((int)features.size(), dsize, CV_32F);
It works till one point.
in the line hist[idx] += v_rco000;
I get a EXC_BAD_ACCESS(code=1, address=....)
Probably thats because idx
seems to be a value which is not logical idx = -2146483626
. The calculation of idx looks like this:
int idx = ((r0+1)*d+2)+c0+1)*(n+2)+o0;
As it seems in the Debugger the value that causes the problem is o0
. In the following, I post the Area of Code until o0 is calculated. It is totally similar to the workflow in the sift.cpp from OpenCV Contrib.
Point pt(cvRound(ptf.x), cvRound(ptf.y));
float cos_t = cosf(ori*(float)(CV_PI/180));
float sin_t = sinf(ori*(float)(CV_PI/180));
float bins_per_rad = n / 360.f;
float exp_scale = -1.f/(d * d * 0.5f);
float hist_width = SIFT_DESCR_SCL_FCTR * scl;
int radius = cvRound(hist_width * 1.4142135623730951f * (d + 1) * 0.5f);
// Clip the radius to the diagonal of the image to avoid autobuffer too large exception
radius = std::min(radius, (int) sqrt(((double) img.cols)*img.cols + ((double) img.rows)*img.rows));
cos_t /= hist_width;
sin_t /= hist_width;
int i, j, k, len = (radius*2+1)*(radius*2+1), histlen = (d+2)*(d+2)*(n+2);
int rows = img.rows, cols = img.cols;
AutoBuffer<float> buf(len*6 + histlen);
float *X = buf, *Y = X + len, *Mag = Y, *Ori = Mag + len, *W = Ori + len;
float *RBin = W + len, *CBin = RBin + len, *hist = CBin + len;
for( i = 0; i < d+2; i++ )
{
for( j = 0; j < d+2; j++ )
for( k = 0; k < n+2; k++ )
hist[(i*(d+2) + j)*(n+2) + k] = 0.;
}
for( i = -radius, k = 0; i <= radius; i++ )
for( j = -radius; j <= radius; j++ )
{
// Calculate sample's histogram array coords rotated relative to ori.
// Subtract 0.5 so samples that fall e.g. in the center of row 1 (i.e.
// r_rot = 1.5) have full weight placed in row 1 after interpolation.
float c_rot = j * cos_t - i * sin_t;
float r_rot = j * sin_t + i * cos_t;
float rbin = r_rot + d/2 - 0.5f;
float cbin = c_rot + d/2 - 0.5f;
int r = pt.y + i, c = pt.x + j;
if( rbin > -1 && rbin < d && cbin > -1 && cbin < d &&
r > 0 && r < rows - 1 && c > 0 && c < cols - 1 )
{
float dx = (float)(img.at<sift_wt>(r, c+1) - img.at<sift_wt>(r, c-1));
float dy = (float)(img.at<sift_wt>(r-1, c) - img.at<sift_wt>(r+1, c));
X[k] = dx; Y[k] = dy; RBin[k] = rbin; CBin[k] = cbin;
W[k] = (c_rot * c_rot + r_rot * r_rot)*exp_scale;
k++;
}
}
len = k;
cv::hal::fastAtan2(Y, X, Ori, len, true);
cv::hal::magnitude32f(X, Y, Mag, len);
cv::hal::exp32f(W, W, len);
for( k = 0; k < len; k++ )
{
float rbin = RBin[k], cbin = CBin[k];
float obin = (Ori[k] - ori)*bins_per_rad;
float mag = Mag[k]*W[k];
int r0 = cvFloor( rbin );
int c0 = cvFloor( cbin );
int o0 = cvFloor( obin );
rbin -= r0;
cbin -= c0;
obin -= o0;
if( o0 < 0 )
o0 += n;
if( o0 >= n )
o0 -= n;
With an angle of ori = 91.8339233
the value in o0 = -2147483644
While Debugging, I found, that Ori[k] = NAN
When printing it before the Error is thrown. But I dont know how it could be a NAN
-Value.
What I'm asking now, is this Error produce through the Mat descriptors
which I created? Or is the origin of this Error somewhere else?