Python-OpenCV cv2 OpenCV Error: Assertion failed (scn == 3 || scn == 4) in unknown function, file ..\..\..\modules\imgproc\src\color.cpp
I am trying to learn contours in python using cv2.
I tried the following code given in a tutorial guide:
import cv2 import numpy as np from matplotlib import pyplot as plt im = cv2.imread('C:\Users\Prashant\Desktop\test.jpg') imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY) ret,thresh = cv2.threshold(imgray,127,255,0) image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) img = cv2.drawContour(im, contours, -1, (0,255,0), 3) cv2.imshow('Image1',img)
I am getting this error:
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 540, in runfile OpenCV Error: Assertion failed (scn == 3 || scn == 4) in unknown function, file ..\..\..\modules\imgproc\src\color.cpp, line 3402 Traceback (most recent call last): File "<stdin>", line 1, in <module> execfile(filename, namespace) File "C:/Users/Prashant/.spyder2/.temp.py", line 15, in <module> imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY) cv2.error: ..\..\..\modules\imgproc\src\color.cpp:3402: error: (-215) scn == 3 || scn == 4
It says your input image should have 3 or 4 channels before applying the function
so check your image shape before applying the function by
print im.shape. if the result is
None type (most of the times, this is the problem), your image is not loaded correctly, most probably because your path is not correct.
The point is that your image should have 3 dimensions,
OpenCV Error: Assertion failed (scn == 3 || scn , I'm getting assertion failed error on cvtColor function. Here is the 3.2.0/modules /imgproc/src/color.cpp:9748: error: (-215) scn == 3 || scn == 4 in function cvtColor Here is the code I'm trying to run. import cv2 import numpy as np img_rgb OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file� Stack Overflow Public questions and answers; Teams Private questions and answers for your team; Enterprise Private self-hosted questions and answers for your enterprise; Jobs Programming and related technical career opportunities
If you are getting this error on a raspberry PI with PI camera, try running this command first:
sudo modprobe bcm2835-v4l2
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file , OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file #13 ~/ opencv-python/opencv/modules/imgproc/src/color.cpp:11079:� Hi every one i am doing a small program using opencv in qt. when i use cvtColor for conversion of bgr to rbg(for qt) i am getting dis error
1st print ret. If it is showing false then your image is not taken properly. If it is showing True Try this command - sudo modprobe bcm2835-v4l2 Or in your /etc/modules file add bcm2835-v4l2 at the bottom.
C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp, COLOR_BGR2GRAY) cv2.error: OpenCV(4.1.0) C:\projects\openc. error: (-215: Assertion failed) !_src.empty() in function 'cv::cvtColor' #933 width and height of the frame of video width = cap.get(3) # float width height = cap.get(4) # float waitKey(1) & 0xFF == ord('q'): break # break out if frame has return NoneType this � > cv2.cvtColor() After this statement: # Read image with opencv img = cv2.imread(img_path) Can you try to print the img variable before passing to cv2.cvtColor() function > print(img) or print(img.shape) to make sure function call to read the image is successful
I had this problem and couldn't find a solution, but on the web, it was working. My solution was almost funny - you can't have two streams. I turned off the web stream and then it was fine!
OpenCV Error: Assertion failed (scn == 3 || scn == 4 , this is the error [OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /io/opencv/modules/imgproc/src/color.cpp, line 10606] size as below. If this is useful, I can create a pull request to act as an utility Function. error: C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\imgproc\src\color.cpp:7456: error: (-215) scn == 3 || scn == 4 in function cv::ipp_cvtColor What I did was: I simply deleted that newly generated image after each run or alternatively changed the type of the image to say png or tiff type. That solved the problem.
Python-OpenCV cv2 OpenCV Error: Error en la aserci�n (scn == 3 , Estoy tratando de aprender contornos en python usando cv2. line 540, in runfile OpenCV Error: Assertion failed (scn == 3 || scn == 4) in unknown function, file ..\..\. modules\imgproc\src\color.cpp:3402: error: (-215) scn == 3 || scn == 4. That doesn't match the requirements of cv2.cvtColor. The range of values you initialize your image with appears to fall into 0-255, which would correspond to data type uint8 . So, just do
Tried converting an image from RGB to GRAYSCALE using opencv , destroyAllWindows() When I run, I get error OpenCV Error: Assertion failed call last): File "shapes.py", line 10, in <module> cv.imshow('image',img) cv2.error: in function imshow I searched various Google links, but none helped for shapes. +dfsg/modules/imgproc/src/color.cpp:3737: error: (-215) scn == 3 || scn == 4 in � Stats. Asked: 2016-08-17 23:12:12 -0500 Seen: 5,408 times Last updated: Aug 17 '16
OpenCV(3.4.1) C:\projects\opencv-python\opencv\modules\imgproc , Get code examples like "OpenCV(3.4.1) C:\projects\opencv-python\opencv\ modules\imgproc\src\color.cpp:11147: error: (-215) scn == 3 || scn == 4 in function C++ queries related to “OpenCV(3.4.1) COLOR_BGR2GRAY) cv2. error cv2 error � error: (-215) scn == 3 || scn == 4 in function cv::cvtColor� OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv:: cvtColor, file ..\opencv\modules\imgproc\src\color.cpp, line 3737. I'm pretty new to C++ and Visual Studios, any help would be appreciated. Thanks in advance!