no Member getMat()
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'"
SOLVED cv::Mat
doesn't have getMat()
need to use cv::InputArray or cv::OutputArray
(Thanks @berak for mentioning that) or initialize the Mat 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 ...
are you confusing
cv::InputArray
(which has a getMat()) withcv::Mat
(which does not) ?can we see a bit more code ? what is
_descriptors
, and why are you calling getMat() on it ?that could be the problem.. in the Original Method I try to reproduce it actually seems to be
cv::OutputArray.
I try to test that. Well actually_descriptors
is acv::Mat
and I call it because I try to reproduce a Method (or parts of it) for a Application. When declaring_descriptors
as anOutputArray
it has to be initialized, how could I do that?ah, makes sense. but we need to see more code now.
Posted the Edit, actually you could also see the Sift.cpp from OpenCV-Contrib, because the Methods are quite similar to that. One thought I got now was that to use a Mat all the way and initialize that with the Parameters from the create of the OutputArray. Well either it is wrong to use a Mat all the way or I got a mistake now. because I get a Error all the time. Could that be because I do
Mat descriptors((int)features.size(), dsize, CV_32F);
or could that be because of my code?Well, when I turn on Guard Malloc from XCode I get the Error far Earlier. At the point
float dy = (float)(img.at<sift_wt>(y-1,x) - img.at<sift_wt>(y+1,x));
while the variables dont seem to cause aEXC_BAD_ACCESS
The Image size is255x255
the values of x and y arey = 251 and x = 213
anyone a clue about that?btw, NaN is produced if you divide by zero.
please make a small, reproducable example (seperate from your current code, which we only can debug as a whole, which noone will do.) , and then ask a new question.
Ok, so it seems, that somehow in the
hal::fastAtan2
function it divides by zero? I'll try to make a little example of my code, with the KeyPoint where it crashes and post it in a new question.atan has poles at pi/2. maybe you did not stay inside the valid range ?
Until now, I just looked up Y[k] and X[k] and the Ori[k]. In the case where the Function makes an Error. I tried to look up also dx and dy which "should" be the values entered in X and Y. Well when the Error comes
Y[k] = NaN
X[k] = 8.12862e+34
which is as thedx and dy
. I also checked the Values ofr and c
(which are the coordinates for thedy and dx
grab. But with 103 and 363 it is still in a 724x724 Image.again, too many unknowns to tell. (wth is sift_wt ?)
maybe try to cross-check your gradient calculation against Sobel() ?