简体   繁体   中英

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

I got this error when I tried to use GPU for convolution.

OpenCV Error: Assertion failed (image.type() == CV_32F) in cv::gpu::convolve, file d:\\opencv\\sources\\modules\\gpu\\src\\imgproc.cpp, line 1413

I've converted the image type to CV_32 but I have this issue. I also have a similar issue when using gpu::filter2D.

(I have no problem using Sobel or Gaussianblur in GPU.)

However, when I do this in the main:

int a=image.type(); the value of a is 21. not CV_32F.

Please let me know how to resolve this issue! I really need your help!! Thank you!!!

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;

I think you've got the answer, actually 21 is 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM