GuiltyNeuron / ANPR

license plate detection and recognition
388 stars 146 forks source link

Invalid number of channels in input image: #3

Closed younes200 closed 5 years ago

younes200 commented 5 years ago

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 commented 5 years ago

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

younes200 commented 5 years ago

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

GuiltyNeuron commented 5 years ago

you are welcome bro :)

SaeedArisha commented 4 years ago

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

hiyamgh commented 4 years ago

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

murugan-bala commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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(...)