开发者

GreyScale translation issues

开发者 https://www.devze.com 2023-02-07 17:09 出处:网络
I\'m getting the following error: cv.error: Incorrect number of c开发者_运维问答hannels for this conversion code

I'm getting the following error:

cv.error: Incorrect number of c开发者_运维问答hannels for this conversion code

from the following piece of code:

cv.CvtColor(frame, gray, cv.CV_BGR2GRAY)

any recommendations?


Check the number of channels of frame and gray. Either use a debugger, or put this line before the conversion:

printf("frame.nChannels: %d gray.nChannels: %d\n", frame.nChannels, gray.nChannels);

frame needs to be 3 channels (RGB). gray needs to be 1 channel. Anything other than that and the conversion will fail. In this case:

  • You can force frame to always be loaded as RGB by passing cv.CV_LOAD_IMAGE_COLOR as the second argument to cv.LoadImage, if you're loading it from a file
  • Make sure when you create gray, you specify that it only has 1 channel, e.g. gray=cv.CreateImage(cv.GetSize(frame), frame.depth, 1)

Look at OpenCV API for the respective functions for more info. The section on Python is Chapter 3, but since the Python wrappers simply re-use the underlying C code, the first part is also relevant.


Looks like frame is not an RGB image, is it?

0

精彩评论

暂无评论...
验证码 换一张
取 消