Invalid number of channels in input image

前端 未结 2 1297
猫巷女王i
猫巷女王i 2021-01-18 07:22

I am receiving an error when running my program, I think specifically about color manipulation in the OpenCV library.

I\'m trying to build a program that takes a vid

相关标签:
2条回答
  • 2021-01-18 07:54

    As error message said, the image given in input to the color conversion function has an invalid number of channels.

    The point is that you are acquiring frames as single 8bit channel

    Camera.set(cv::CAP_PROP_FORMAT, CV_8UC1)
    

    and then you try to convert this frame in grayscale

    cv::cvtColor(image, gray, cv::COLOR_BGR2GRAY)
    

    You have 2 easy options to solve this issue:

    1. you change the camer acquisition format in order to have color informations in your frames, for example using CV_32S or CV_32F
    2. you skip the color conversion as you already have grayscale image, thus no need to convert it.

    Take a look to this link for OpenCV color manipulation

    0 讨论(0)
  • 2021-01-18 08:13

    You want to do color manipulation but your image has the type CV_8U1. It has to be at least a three channel image like CV_8UC3 or CV_32F. Try a different CV_Type

    Camera.set(cv::CAP_PROP_FORMAT, CV_32F);
    
    0 讨论(0)
提交回复
热议问题