我收到以下错误:
cv.error: Incorrect number of channels for this conversion code
cv.CvtColor(frame, gray, cv.CV_BGR2GRAY)
最佳答案
查看frame
的 channel 数和 gray
.要么使用调试器,要么在转换之前放置这一行:
printf("frame.nChannels: %d gray.nChannels: %d\n", frame.nChannels, gray.nChannels);
frame
需要是 3 个 channel (RGB)。 gray
需要1个 channel 。除此之外的任何事情,转换都会失败。在这种情况下:frame
至 总是 通过传递 cv.CV_LOAD_IMAGE_COLOR
加载为 RGB作为 cv.LoadImage
的第二个参数, 如果您从文件 gray
,您指定它只有 1 个 channel ,例如gray=cv.CreateImage(cv.GetSize(frame), frame.depth, 1)
https://stackoverflow.com/questions/4839937/