new to opencv python and clarification on certain things

asked 2013-11-03 03:34:27 -0600

JQ gravatar image

updated 2013-11-03 03:49:38 -0600

berak gravatar image

I am a total newbie in opencv+python

I will like to clarify some things in regards to my project

  1. what is a suitable GUI that I can work with using opencv+python? is TkInter sufficient for compiling the codes that I have from opencv+python?

  2. I have been encountering these errors from various documented opencv codes based on these websites https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_objdetect/py_face_detection/py_face_detection.html#face-detection

for this website i seem to be facing this error when i try to compile it on TkInter Traceback (most recent call last): File "C:\Users\Jian Quan\Desktop\simulation\cameratest.py", line 8, in <module> gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) error: ......\src\opencv\modules\imgproc\src\color.cpp:3402: error: (-215) scn == 3 || scn == 4

while for another example that i tried, this is the error I encountered

#!/usr/bin/python import cv2 img = cv2.imread("Lenna.png") hc = cv2.CascadeClassifier("haarcascade_frontalface_alt2.xml") faces = hc.detectMultiScale(img) for face in faces: cv2.rectangle(img, (face[0], face[1]), (face[0] + face[2], face[0] + face[3]), (255, 0, 0), 3) cv2.imshow("Lenna's face", img) if cv2.waitKey(5000) == 27: cv2.destroyWindow("Lenna's face") cv2.imwrite("LennaFace.png", img)

this is the error:

Traceback (most recent call last): File "C:\Users\Jian Quan\Desktop\simulation\test.py", line 11, in <module> cv2.imshow("Lenna's face", img) error: ......\src\opencv\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0

can anyone out there help me clarify the issues that I m facing at the moment? thanks so much

edit retag flag offensive close merge delete

Comments

the 1st error say, that your image does not have 3 or 4 channels(required), but we'd need to see some code to see, what's happening.

the 2nd error, it probably should be:

 cv2.rectangle(img, (face[0], face[1]), (face[0] + face[2], face[1] + face[3]), (255, 0, 0), 3)
berak gravatar imageberak ( 2013-11-03 03:57:19 -0600 )edit

What does it mean 3 or 4 channels? I'm still unclear what does it refer to

JQ gravatar imageJQ ( 2013-11-03 08:18:44 -0600 )edit

b g r -- that's 3 color channels. you passed in an image that had less.

berak gravatar imageberak ( 2013-11-03 08:26:24 -0600 )edit

so how can i overcome it? shouldn't any picture have all 3 different colors of b g r?

JQ gravatar imageJQ ( 2013-11-03 10:00:16 -0600 )edit

unless they are grayscale(1chan) or complex(2chan) again, can't help without seeing code

berak gravatar imageberak ( 2013-11-03 10:03:50 -0600 )edit

import numpy as np import cv2

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')

img = cv2.imread('sachin.jpg') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray, 1.3, 5) for (x,y,w,h) in faces: img = 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] eyes = eye_cascade.detectMultiScale(roi_gray) for (ex,ey,ew,eh) in eyes: cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)

cv2.imshow('img',img) cv2.waitKey(0) cv2.destroyAllWindows()

this is the code for it, pls help me have a look, thanks :)

JQ gravatar imageJQ ( 2013-11-03 11:55:33 -0600 )edit