【问题标题】:Assertion failed (image.type() == CV_32F). GPU convolution. OpenCV断言失败(image.type() == CV_32F)。 GPU卷积。开放式CV
【发布时间】:2014-06-26 01:49:47
【问题描述】:

当我尝试使用 GPU 进行卷积时出现此错误。

OpenCV 错误:cv::gpu::convolve 中的断言失败 (image.type() == CV_32F),文件 d:\opencv\sources\modules\gpu\src\imgproc.cpp,第 1413 行

我已将图像类型转换为 CV_32,但我遇到了这个问题。 我在使用 gpu::filter2D 时也遇到了类似的问题。

(我在 GPU 中使用 Sobel 或 Gaussianblur 没有问题。)

但是,当我主要这样做时:

int a=image.type(); a 的值为 21。不是 CV_32F。

请告诉我如何解决此问题!我真的需要你的帮助!!谢谢!!!

using namespace cv;
using namespace std;

int main()
{


// read kernel from text file
int kernel_size=15;
ifstream fin;
fin.open ("PSF00.txt"); 

float kernel0[15][15];
for (int i=0; i<kernel_size; i++)
{
    for (int j=0; j<kernel_size; j++)
    {
        fin >> kernel0[i][j];
    }
}       

// Save 2D Kernel array into MAT format
Mat kernel = Mat(kernel_size, kernel_size, CV_32F, kernel0);    

// load image
Mat image = imread("blurry_00.jpg");        
image.convertTo(image, CV_32F);         

// GPU
gpu::GpuMat gpu_input, gpu_input1, gpu_output, gpu_kernel;

gpu_input.upload(image);
gpu_kernel.upload(kernel);

gpu_input.convertTo(gpu_input1, CV_32F);    

gpu::convolve(gpu_input1, gpu_kernel, gpu_output);  

// Download image from GPU to CPU
Mat dst(gpu_output);                
dst.convertTo(dst, CV_8U);

// Create a window for display.
namedWindow( "Display window (GPU)", WINDOW_AUTOSIZE );
imshow( "Display window (GPU)", dst );

waitKey(0);
return 0;

【问题讨论】:

    标签: c++ opencv gpu


    【解决方案1】:

    我想你已经知道答案了,实际上 21 是 CV_32F。

       #define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT)) 
       #define CV_8S   1  //depth 
       #define CV_32F  5  //cn 
       #define CV_MAT_DEPTH(flags)     ((flags) & CV_MAT_DEPTH_MASK) 
    
       0x21 -> cn = 5, depth = 1
    

    【讨论】:

    • 我已经解决了这个问题。问题是输入图像的通道号应该是1。谢谢。
    • @user3776882 你可能想回答你自己的问题stackoverflow.com/help/self-answer
    猜你喜欢
    • 2017-10-08
    • 2023-03-27
    • 1970-01-01
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    • 2019-07-11
    • 2013-09-28
    • 1970-01-01
    相关资源
    最近更新 更多