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.










share|improve this question

















  • 1




    Is your ret value True or False?
    – Employee
    14 hours ago














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.










share|improve this question

















  • 1




    Is your ret value True or False?
    – Employee
    14 hours ago












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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 18 hours ago









Chamara Madushanka

13




13







  • 1




    Is your ret value True or False?
    – Employee
    14 hours ago












  • 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












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






share|improve this answer










New contributor




Sanchit.Jain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

















  • 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










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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






share|improve this answer










New contributor




Sanchit.Jain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

















  • 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














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






share|improve this answer










New contributor




Sanchit.Jain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

















  • 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












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






share|improve this answer










New contributor




Sanchit.Jain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









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







share|improve this answer










New contributor




Sanchit.Jain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer








edited 12 hours ago









Employee

364214




364214






New contributor




Sanchit.Jain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered 17 hours ago









Sanchit.Jain

161




161




New contributor




Sanchit.Jain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Sanchit.Jain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Sanchit.Jain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • 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










  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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














































































這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto