简体   繁体   中英

OpenCV: src.size() == dst.size() && dst.type() == CV_32FC1 Error in .Net C#

I have an image loaded from a video:

 Image<Gray, byte> imGray=cap.QueryGrayFrame();  

Now, I want to use the cvCornerHarris function from openCv as following:

 Image<Gray, byte> harRes = new Image<Gray, byte>(imGray.Size);  
 CvInvoke.cvCornerHarris(imGray, harRes, 8, 3, 0.04); 

But I get an cvException:

OpenCV: src.size() == dst.size() && dst.type() == CV_32FC1 Error

在此处输入图片说明

How should I fix this?

I am not sure about the C# wrapper, but in C++, you can change the pixel format using this line:

imGray.convertTo(A, CV_32F);

The error says, the size of images should match (which your code do the same) and the pixel format should be float32, which probably yours are not.

You can deduce from the given exception, that the type of the destination image should be CV_32FC1 .

In your case, the destination image is harRes , which you have declared as:

Image<Gray, byte> harRes = new Image<Gray, byte>(imGray.Size);

The type of this image is CV_8UC1 .

It should be declared as:

Image<Gray, float> harRes = new Image<Gray, float>(imGray.Size);

Now its type is CV_32FC1 , which is the type expected by the function cvCornerHarris .

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