gpt4 book ai didi

c++ - OpenCV错误使用逆

转载 作者:太空宇宙 更新时间:2023-11-03 22:10:35 25 4
gpt4 key购买 nike

我正在使用 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 Error: Assertion failed (type == CV_32F || type == CV_64F) in cv::invert, file C:\buildslave64\win64_amdocl\master_PackSlave-win64-vc14-shared\opencv\mod ules\core\src\lapack.cpp, line 798 Press any key to continue . . .

最佳答案

OpenCV Error: Assertion failed (type == CV_32F || type == CV_64F) in cv::invert

意味着您需要将 CV_32F(浮点型)或 CV_64F( double 型)类型的矩阵传递给 invert。但是您传递的是 CV_16S(短),因为您在调用时设置了它:

Sobel(dog[i], grad_x, CV_16S, 1, 0, 3, 1, 0, BORDER_DEFAULT);
^^^^^^

所以你可以

  1. 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);
  2. 或将您传递给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);

关于c++ - OpenCV错误使用逆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39202448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com