Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid number of channels in input image: #3

Closed
younes200 opened this issue Aug 11, 2019 · 8 comments
Closed

Invalid number of channels in input image: #3

younes200 opened this issue Aug 11, 2019 · 8 comments

Comments

@younes200
Copy link

younes200 commented Aug 11, 2019

Hi,
After traning the Licence_plate_recognition model, runing python3 main.py -mode predict -i test.jpg -model mlp.pkl ended with the error :

Traceback (most recent call last):
  File "main.py", line 35, in <module>
    digits = histogram_of_pixel_projection(img)
  File "/Users/Projects/ml/ANPR/Licence_plate_recognition/tools.py", line 74, in histogram_of_pixel_projection
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(4.1.0) /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/color.simd_helpers.hpp:92: error: (-2:Unspecified error) in function 'cv::impl::(anonymous namespace)::CvtHelper<cv::impl::(anonymous namespace)::Set<3, 4, -1>, cv::impl::(anonymous namespace)::Set<1, -1, -1>, cv::impl::(anonymous namespace)::Set<0, 2, 5>, cv::impl::(anonymous namespace)::SizePolicy::NONE>::CvtHelper(InputArray, OutputArray, int) [VScn = cv::impl::(anonymous namespace)::Set<3, 4, -1>, VDcn = cv::impl::(anonymous namespace)::Set<1, -1, -1>, VDepth = cv::impl::(anonymous namespace)::Set<0, 2, 5>, sizePolicy = cv::impl::(anonymous namespace)::SizePolicy::NONE]'
> Invalid number of channels in input image:
>     'VScn::contains(scn)'
> where
>     'scn' is 1

Any thoughts ? thank you in advance.
/Y

@GuiltyNeuron
Copy link
Owner

I guess that is a problem related to img format,are you using the test.jpg image ?

@younes200
Copy link
Author

younes200 commented Aug 13, 2019

My bad, wrong img format :)
Thanks Achraf for sharing you code !

@GuiltyNeuron
Copy link
Owner

you are welcome bro :)

@SaeedArisha
Copy link

Hello, guys can you please provide insight on how you fixed this error

@hiyamgh
Copy link

hiyamgh commented Jun 7, 2020

yes please how was the error fixed ? is it because the image was .jpg ?

@murugan-bala
Copy link

type error: OpenCV(4.2.0) c:\projects\opencv-python\opencv\modules\imgproc\src\color.simd_helpers.hpp:92: error: (-2:Unspecified error) in function '__cdecl cv::impl::anonymous-namespace'::CvtHelper<struct cv::impl::anonymous namespace'::Set<3,4,-1>,struct cv::impl::A0xe227985e::Set<1,-1,-1>,struct cv::impl::A0xe227985e::Set<0,2,5>,2>::CvtHelper(const class cv::_InputArray &,const class cv::_OutputArray &,int)'

Invalid number of channels in input image:
'VScn::contains(scn)'
where
'scn' is 1

pls help me..

@kevinkit
Copy link

scn is 1 means that there is only one channel present, ergo a gray scale image, however it requires a RGB image with 3 channels.
To fix this convert your images form grayscale to RGB first (stack the grayscale images as 3D Matrix or use cvtColor with COLOR_GRAY2RGB

@shivam-parashar
Copy link

I think the problem is simple. You're converting an already gray_image to a gray_image.
So just make a check if no_of_channels==3: then cvtColor(...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants