断言失败(image.type() == CV_32F).GPU卷积.OpenCV

Assertion failed (image.type() == CV_32F). GPU convolution. OpenCV

本文关键字:32F GPU 卷积 OpenCV CV type 失败 断言 image      更新时间:2023-10-16

当我尝试使用GPU进行卷积时,我得到了这个错误。

OpenCV错误:Assertion failed (image.type() == CV_32F) in cv::gpu::convolve,文件d: OpenCV sourcesmodulesgpusrcimgproc.cpp,第1413行

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

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

但是,当我在main中这样做时:

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;

我想你已经知道答案了,实际上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