我正在使用Visual C ++进行SIFT实现。我的代码在反向时抛出错误:
/// Load the source image
src = imread("C:/Users/Adithyaanirudhha/Documents/Visual Studio 2015/Projects/ConsoleApplication2/pa.jpg", 1);
if (display_caption("Original Image") != 0) { return 0; }
dst = src.clone();
width = src.size().width;
height = src.size().height;
Size size(height,width);
if (display_dst(DELAY_CAPTION) != 0) { return 0; }
cvtColor(src, src, CV_RGB2GRAY);
/// Applying Gaussian blur
//for(int j=0;j<4;j++)
//{
//resize(src, src, size / 2);
k = 2 ^ (1 / 2);
for(int i=0;i<3;i++)
{
//if (display_caption("Gaussian Blur") != 0) { return 0; }
GaussianBlur(src, dst, Size(), 1.6*k, 1.6*k);
if (display_dst(DELAY_BLUR*10) != 0) { return 0; }
k = k * k;
dst.copyTo(dest[m]);
//dest[m] = dst;
m++;
}
//}
width2 = dog[1].size().width;
height2 = dog[1].size().height;
Size sizes(width2,height2);
Mat dog_inv(sizes,0,CV_64F);
for (int n = 0; n < 2; n++)
{
if(m1!=3 || m1 != 6 || m1 != 9)
subtract(dest[m1 + 1], dest[m1], dog[n],noArray(),-1);
}
for (int i = 0; i < 2; i++)
{
Sobel(dog[i], grad_x, CV_16S, 1, 0, 3, 1, 0, BORDER_DEFAULT);
convertScaleAbs(grad_x, grad_x);
transpose(grad_x, temp);
Sobel(dog[i], grad_x_2, CV_16S, 2, 0, 3, 1, 0, BORDER_DEFAULT);
convertScaleAbs(grad_x_2, grad_x_2);
c = invert(dog[i],dog_inv, DECOMP_LU);
Sobel(dog[i], grad_x_2_1, CV_16S, 2, 0, 3, 1, 0, BORDER_DEFAULT);
convertScaleAbs(grad_x_2_1, grad_x_2_1);
//imshow(window_name,src);
//grad_x_2_1 = grad_x_2_1.inv(CV_32F);
multiply(grad_x_2_1, grad_x, x_max, 1, 1);
multiply(temp, x_max, p1, 1, 1);
transpose(x_max,temp);
//multiply(temp, grad_x_2, p2, 1, 1);
multiply(p2, x_max, p2, 1, 1);
imshow(window_name, dog[1]);
/*for (int y = 0; y < dog[i].rows; y++)
{
for (int x = 0; x < dog[i].cols; x++)
{
dog[i].at<Vec3b>(y, x) = (-1 * (p1.at<Vec3b>(y, x)) + 0.5*(p2.at<Vec3b>(y, x)) + dog[i].at<Vec3b>(y, x));
}
}*/
//imshow(window_name, dog[1]);
//imshow(window_name, src);
,错误是:
OpenCV错误:cv :: invert中的断言失败(类型== CV_32F || type == CV_64F) 文件C:\ buildslave64 \ win64_amdocl \ master_PackSlave-win64-vc14-shared \ opencv \ mod ules \ core \ src \ lapack.cpp,第798行 按任意键继续 。 。
答案 0 :(得分:3)
OpenCV错误:在cv :: invert
中断言失败(类型== CV_32F || type == CV_64F)
表示您需要向invert
传递CV_32F
(浮点)或CV_64F
(双精度)类型的矩阵。但是你传递CV_16S
(短),因为你在调用时设置了这个:
Sobel(dog[i], grad_x, CV_16S, 1, 0, 3, 1, 0, BORDER_DEFAULT);
^^^^^^
所以你可以
将Sobel
返回的矩阵类型更改为CV_32F
Sobel(dog[i], grad_x, CV_32F, 1, 0, 3, 1, 0, BORDER_DEFAULT);
c = invert(dog[i],dog_inv, DECOMP_LU);
或将传递给invert
的矩阵转换为正确的类型
Sobel(dog[i], grad_x, CV_16S, 1, 0, 3, 1, 0, BORDER_DEFAULT);
Mat tmp;
dog[i].convertTo(tmp, CV_32F);
c = invert(tmp,dog_inv, DECOMP_LU);