python


Python-Opencv error: (-215) scn == 3 || scn == 4 in function cv::cvtColor


import numpy as np
import cv2
import thread, winsound
face_cascade = cv2.CascadeClassifier('C:\Users\Saddaqat\Desktop\Softwares\opencv\build\share\OpenCV\haarcascades\haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('C:\Users\Saddaqat\Desktop\Softwares\opencv\build\share\OpenCV\haarcascades\haarcascade_eye.xml')
def beep():
for i in xrange(4):
winsound.Beep(1500, 250)
cam = cv2.VideoCapture(0)
count = 0
iters = 0
while(True):
ret, cur = cam.read()
gray = cv2.cvtColor(cur, cv2.COLOR_BGR2GRAY)
faces = face
_cascade.detectMultiScale(gray,scaleFactor = 1.1, minNeighbors=1, minSize=(10,10))
for (x,y,w,h) in faces:
#cv2.rectangle(cur,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h,x:x+w]
roi_color = cur[y:y+h,x:x+w]
eyes = eye_cascade.detectMultiScale(roi_gray)
if len(eyes) == 0:
print "Eyes closed"
else:
print "Eyes open"
count += len(eyes)
iters += 1
if iters == 2:
iters = 0
if count == 0:
print "Drowsiness Detected!!!"
thread.start_new_thread(beep,())
count = 0
for (ex,ey,ew,eh) in eyes:
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh), (0,255,0),2)
cv2.imshow('frame', cur)
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
//
I am facing this error Kindly resolve this error . thanks and love in advance ;)
Traceback (most recent call last):
File "C:\Users\Saddaqat\Desktop\fatigue detection code", line 17, in
gray = cv2.cvtColor(cur, cv2.COLOR_BGR2GRAY)
error: ........\opencv\modules\imgproc\src\color.cpp:3739: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor
Well, for me it looks like the VideoCapture is not working. You should check after reading the image, if it could have read something:
ret, cur = cam.read()
if not ret:
print "VideoCapture read no frame."
break
If that's the case, there has been some answers here in SO that might help you, for example: OpenCV 2.4 VideoCapture not working on Windows
Basically, they say that you might have problems with the ffmpeg. Maybe you have to add it to Windows path, and/or rename it to have the OpenCV version on it.

Related Links

How are features ranked in RFECV in scikit learn(sklearn)?
Solr requests hang when started via python subprocess
How to extract internet email headers from outlook emails?
Tensorboard get blank page
Python Matplotlib Streamplot providing start points
Reduce inner points in numpy coordinate dataset (speed up concave hull)
Blitting several layers pygame
floating and integer power difference in Python
how to skip certain line in text file and keep reading the next line in python?
match key and insert into new column
Python - Storing the values of CSV file in List
Should telegram-code be defined as a message option?
I get translated text when I do a GET request (in Python). How to get English content?
Store two types of value in single Django model field
egg_info failed with error code 1
Open SAP with Python GUI Script win32com.client.Dispatch(“Sapgui.ScriptingCtrl.1”)

Categories

HOME
python
ajax
cluster-computing
project-management
otrs
visualization
playframework
user
triggers
proguard
onenote-api
packer
oclint
wicket
jboss-eap-7
iso
game-maker-studio-1.4
apache-karaf
aptana
google-api-java-client
scalajs-react
croppic
rhandsontable
vcard
reply
reactiveui
multichoiceitems
pitest
superscript
ioc-container
entity-system
helix-3d-toolkit
graph-databases
hotmail
google-drive-realtime-api
passenger
oscommerce
nodeclipse
redhat-datavirt
swagger-editor
visualstudio.testtools
nsexception
openweathermap
lumen-5.3
ajp
rollback
opencpu
festival
createobject
pdflib
rstudio-server
slam-algorithm
visible
django-filer
unsatisfiedlinkerror
gradle-eclipse
image-editing
gemini
mpeg-4
test-class
geodjango
site-prism
rad
sevenzipsharp
paypal-nvp
calibration
ubercart
ticket-system
cpan
c++-actor-framework
gyroscope-framework
firebug-lite
java-collections-api
libssh2
internal
angulartics
fogbugz-api
onselect
sttwitter
multiple-conditions
objcmongodb
web-safe-fonts
deploying
caliper
text-size
electronic-signature
printing-web-page
collect
search-path
carbide
grooveshark
webrat
nt4
odbc-sql-server-driver
interface-design
rd

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App