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

cv2.error: D:\Build\OpenCV\opencv-3.3.1\modules\imgproc\src\color.cpp:11016: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor #35

Open
dapsjj opened this issue Dec 14, 2017 · 8 comments

Comments

@dapsjj
Copy link

dapsjj commented Dec 14, 2017

When I use your code,I find there is a error
First,I modified ['-src', '--source', dest='video_source', type=int,……]
to ['-src', '--source', dest='video_source', type=str,……]
Then I use this command "python object_detection_multithreading.py -src E:C.mp4",but the mistake appeared.
E:\test_opencv\object_detector_app-master_PB>python object_detection_multithreading.py -src E:C.mp4
warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:808)
warning: E:C.mp4 (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:809)
[INFO] elapsed time: 0.00
[INFO] elapsed time: 0.00
[INFO] elapsed time: 0.00
[INFO] elapsed time: 0.00
[INFO] elapsed time: 0.00

OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv::cvtColor, file D:\Build\OpenCV\opencv-3.3.1\modules\imgproc\src\color.cpp, line 11016
Exception in thread Thread-1:
Traceback (most recent call last):
File "E:\Anaconda3\lib\threading.py", line 914, in _bootstrap_inner
self.run()
File "E:\Anaconda3\lib\threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "object_detection_multithreading.py", line 77, in worker
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
cv2.error: D:\Build\OpenCV\opencv-3.3.1\modules\imgproc\src\color.cpp:11016: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor

How to fix it?

@QianyuanLiu
Copy link

May you modify your path of the file.

@Aki1987
Copy link

Aki1987 commented Jan 17, 2018

Maybe your computer can not connect to camera by python.
You should check your python code if it could access your camera first.
Best, Thu

@QJXX
Copy link

QJXX commented Nov 3, 2018

I alse have the problem:anyone can help me?
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/pi/opencv-3.3.0/modules/imgproc/src/color.cpp, line 10638
Traceback (most recent call last):
File "faceDetection.py", line 21, in
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.error: /home/pi/opencv-3.3.0/modules/imgproc/src/color.cpp:10638: error: (-215) scn == 3 || scn == 4 in function cvtColor

@facerecogahilarfa
Copy link

import cv2
import sys

cascPath = "/haarcascades/haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascPath)

video_capture = cv2.VideoCapture(0)

while True:
# Capture frame-by-frame
ret, frame = video_capture.read()

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

faces = faceCascade.detectMultiScale(
    gray,
    scaleFactor=1.1,
    minNeighbors=5,
    minSize=(30, 30),
    flags=cv2.cv.CV_HAAR_SCALE_IMAGE
)

# Draw a rectangle around the faces
for (x, y, w, h) in faces:
    cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

# Display the resulting frame
cv2.imshow('Video', frame)

if cv2.waitKey(1) & 0xFF == ord('q'):
    break

When everything is done, release the capture

video_capture.release()
cv2.destroyAllWindows()


after running above code getting below error : Request to any one to help in this

File "C:/Users/Ahil Rayyan/Desktop/Face Recog Project/07_Nov_2018_V0.1/Video testing.py", line 13, in
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

error: OpenCV(3.4.1) C:\Miniconda3\conda-bld\opencv-suite_1533128839831\work\modules\imgproc\src\color.cpp:11147: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor

@dreamlovesft
Copy link

dreamlovesft commented Dec 4, 2018

i also encountered the error when i tred to show my images in my computer ,the code is as follows:

import cv2
import matplotlib.pyplot as plt
extractdir = r'F:/Python exercise/Machine Learning for OpenC/pedestrians128x64'
for i in range(5):
filename = '%s/per0001%d.pmm' % (extractdir, i)
img = cv2.imread(filename)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.subplot(1, 5, i+1 )
plt.imshow(img)
# img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
plt.axis('off')

the result : cv2.error: C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:10606: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor

what can i do to fix it

@varu1234
Copy link

MR QJXX, I also face the same problem. tell me solution if that is you know

@wyhcqq
Copy link

wyhcqq commented Jul 28, 2019

MR QJXX, I also face the same problem. tell me solution if that is you know, please

@wuttisakpo
Copy link

OpenCV(3.4.1) Error: Assertion failed ((scn == 3 || scn == 4) && (depth == 0 || depth == 5)) in cv::cvtColor, file C:\Miniconda3\conda-bld\opencv-suite_1533128839831\work\modules\imgproc\src\color.cpp, line 11214
Traceback (most recent call last)

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

9 participants