error: (-215) scn == 3 || scn == 4 in function cv::cvtColor
up vote
-1
down vote
favorite
I am working on a project image processing and i get an error when run this code.
I use python and opencv in the project.The error was,
error: D:BuildOpenCVopencv-3.2.0modulesimgprocsrccolor.cpp:9748: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor
and this is the code i used,
import cv2
import numpy as np
face_cascade = cv2.CascadeClassifier('C:\Users\Hp\Downloads\haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(1)
while True:
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for(x,y,w,h) in faces:
cv2.rectangle(img, (x,y),(x+w, y+h),(255,0,0), 2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
cv2.imshow('img',img)
k = cv2.waitkey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
Please help i was stucked here for 5 hrs.
Thanks.
python opencv image-processing
add a comment |
up vote
-1
down vote
favorite
I am working on a project image processing and i get an error when run this code.
I use python and opencv in the project.The error was,
error: D:BuildOpenCVopencv-3.2.0modulesimgprocsrccolor.cpp:9748: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor
and this is the code i used,
import cv2
import numpy as np
face_cascade = cv2.CascadeClassifier('C:\Users\Hp\Downloads\haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(1)
while True:
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for(x,y,w,h) in faces:
cv2.rectangle(img, (x,y),(x+w, y+h),(255,0,0), 2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
cv2.imshow('img',img)
k = cv2.waitkey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
Please help i was stucked here for 5 hrs.
Thanks.
python opencv image-processing
1
Is your ret value True or False?
– Employee
14 hours ago
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I am working on a project image processing and i get an error when run this code.
I use python and opencv in the project.The error was,
error: D:BuildOpenCVopencv-3.2.0modulesimgprocsrccolor.cpp:9748: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor
and this is the code i used,
import cv2
import numpy as np
face_cascade = cv2.CascadeClassifier('C:\Users\Hp\Downloads\haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(1)
while True:
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for(x,y,w,h) in faces:
cv2.rectangle(img, (x,y),(x+w, y+h),(255,0,0), 2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
cv2.imshow('img',img)
k = cv2.waitkey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
Please help i was stucked here for 5 hrs.
Thanks.
python opencv image-processing
I am working on a project image processing and i get an error when run this code.
I use python and opencv in the project.The error was,
error: D:BuildOpenCVopencv-3.2.0modulesimgprocsrccolor.cpp:9748: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor
and this is the code i used,
import cv2
import numpy as np
face_cascade = cv2.CascadeClassifier('C:\Users\Hp\Downloads\haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(1)
while True:
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for(x,y,w,h) in faces:
cv2.rectangle(img, (x,y),(x+w, y+h),(255,0,0), 2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
cv2.imshow('img',img)
k = cv2.waitkey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
Please help i was stucked here for 5 hrs.
Thanks.
python opencv image-processing
python opencv image-processing
asked 18 hours ago
Chamara Madushanka
13
13
1
Is your ret value True or False?
– Employee
14 hours ago
add a comment |
1
Is your ret value True or False?
– Employee
14 hours ago
1
1
Is your ret value True or False?
– Employee
14 hours ago
Is your ret value True or False?
– Employee
14 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
The img
variable does not contain the correct dimensions. If you have only one camera in your system use cv2.VideoCapture(0)
instead of cv2.VideoCapture(1)
.
New contributor
So what should i use instead of 'img'?can you please give the code which i should use?And i have disabled my internal webcam.So i also think it should be cv2.VideoCapture(0).Thanks.
– Chamara Madushanka
16 hours ago
I just wanted to say that img variable was getting a none type object because cv2.VideoCapture was not working. That error was occurred at that line because img variable was pointing to a none type object.
– Sanchit.Jain
15 hours ago
Is the code still giving same error after changing cv2.VideoCapture?
– Sanchit.Jain
15 hours ago
I think the problem was in cam.After changing that cv2.VideoCapture(1) to cv2.VideoCapture(0) it worked.Thanks..
– Chamara Madushanka
8 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The img
variable does not contain the correct dimensions. If you have only one camera in your system use cv2.VideoCapture(0)
instead of cv2.VideoCapture(1)
.
New contributor
So what should i use instead of 'img'?can you please give the code which i should use?And i have disabled my internal webcam.So i also think it should be cv2.VideoCapture(0).Thanks.
– Chamara Madushanka
16 hours ago
I just wanted to say that img variable was getting a none type object because cv2.VideoCapture was not working. That error was occurred at that line because img variable was pointing to a none type object.
– Sanchit.Jain
15 hours ago
Is the code still giving same error after changing cv2.VideoCapture?
– Sanchit.Jain
15 hours ago
I think the problem was in cam.After changing that cv2.VideoCapture(1) to cv2.VideoCapture(0) it worked.Thanks..
– Chamara Madushanka
8 hours ago
add a comment |
up vote
0
down vote
The img
variable does not contain the correct dimensions. If you have only one camera in your system use cv2.VideoCapture(0)
instead of cv2.VideoCapture(1)
.
New contributor
So what should i use instead of 'img'?can you please give the code which i should use?And i have disabled my internal webcam.So i also think it should be cv2.VideoCapture(0).Thanks.
– Chamara Madushanka
16 hours ago
I just wanted to say that img variable was getting a none type object because cv2.VideoCapture was not working. That error was occurred at that line because img variable was pointing to a none type object.
– Sanchit.Jain
15 hours ago
Is the code still giving same error after changing cv2.VideoCapture?
– Sanchit.Jain
15 hours ago
I think the problem was in cam.After changing that cv2.VideoCapture(1) to cv2.VideoCapture(0) it worked.Thanks..
– Chamara Madushanka
8 hours ago
add a comment |
up vote
0
down vote
up vote
0
down vote
The img
variable does not contain the correct dimensions. If you have only one camera in your system use cv2.VideoCapture(0)
instead of cv2.VideoCapture(1)
.
New contributor
The img
variable does not contain the correct dimensions. If you have only one camera in your system use cv2.VideoCapture(0)
instead of cv2.VideoCapture(1)
.
New contributor
edited 12 hours ago
Employee
364214
364214
New contributor
answered 17 hours ago
Sanchit.Jain
161
161
New contributor
New contributor
So what should i use instead of 'img'?can you please give the code which i should use?And i have disabled my internal webcam.So i also think it should be cv2.VideoCapture(0).Thanks.
– Chamara Madushanka
16 hours ago
I just wanted to say that img variable was getting a none type object because cv2.VideoCapture was not working. That error was occurred at that line because img variable was pointing to a none type object.
– Sanchit.Jain
15 hours ago
Is the code still giving same error after changing cv2.VideoCapture?
– Sanchit.Jain
15 hours ago
I think the problem was in cam.After changing that cv2.VideoCapture(1) to cv2.VideoCapture(0) it worked.Thanks..
– Chamara Madushanka
8 hours ago
add a comment |
So what should i use instead of 'img'?can you please give the code which i should use?And i have disabled my internal webcam.So i also think it should be cv2.VideoCapture(0).Thanks.
– Chamara Madushanka
16 hours ago
I just wanted to say that img variable was getting a none type object because cv2.VideoCapture was not working. That error was occurred at that line because img variable was pointing to a none type object.
– Sanchit.Jain
15 hours ago
Is the code still giving same error after changing cv2.VideoCapture?
– Sanchit.Jain
15 hours ago
I think the problem was in cam.After changing that cv2.VideoCapture(1) to cv2.VideoCapture(0) it worked.Thanks..
– Chamara Madushanka
8 hours ago
So what should i use instead of 'img'?can you please give the code which i should use?And i have disabled my internal webcam.So i also think it should be cv2.VideoCapture(0).Thanks.
– Chamara Madushanka
16 hours ago
So what should i use instead of 'img'?can you please give the code which i should use?And i have disabled my internal webcam.So i also think it should be cv2.VideoCapture(0).Thanks.
– Chamara Madushanka
16 hours ago
I just wanted to say that img variable was getting a none type object because cv2.VideoCapture was not working. That error was occurred at that line because img variable was pointing to a none type object.
– Sanchit.Jain
15 hours ago
I just wanted to say that img variable was getting a none type object because cv2.VideoCapture was not working. That error was occurred at that line because img variable was pointing to a none type object.
– Sanchit.Jain
15 hours ago
Is the code still giving same error after changing cv2.VideoCapture?
– Sanchit.Jain
15 hours ago
Is the code still giving same error after changing cv2.VideoCapture?
– Sanchit.Jain
15 hours ago
I think the problem was in cam.After changing that cv2.VideoCapture(1) to cv2.VideoCapture(0) it worked.Thanks..
– Chamara Madushanka
8 hours ago
I think the problem was in cam.After changing that cv2.VideoCapture(1) to cv2.VideoCapture(0) it worked.Thanks..
– Chamara Madushanka
8 hours ago
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237158%2ferror-215-scn-3-scn-4-in-function-cvcvtcolor%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Is your ret value True or False?
– Employee
14 hours ago