Choosing which image to take as input with a dialogue box.
So, I am trying to browse through a directory and choose which image I want to take as input. My code:
import numpy as np
import cv2 as cv
import easygui
face_cascade = cv.CascadeClassifier('face.xml')
def todo():
img = easygui.fileopenbox()
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 7, 7)
for (x,y,w,h) in faces:
cv.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]
cv.imshow('img',img)
cv.waitKey(0)
cv.destroyAllWindows()
todo()
When I input an image I get error
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
TypeError: src is not a numpy array, neither a scalar
what do you think,
easygui.fileopenbox()
returns ?(hint: it's probably NOT an image)
next: put
cv.destroyAllWindows()
OUT of the loopsorry to say so, but you have to understand, what you're doing here, with every single line of your code.
simply copy/pasting things won't get you anywhere.
Have a look at http://easygui.sourceforge.net/api.html --> you need to use the correct set of parameters on the
fileboxopen()
function. However this is totally unrelated to OpenCV ...uni_code=easygui.fileopenbox()
Added this. Still get error
@Philia to me that error clearly states that your generated img_path is incorrect and not in the string format, as
imread
is expecting. You have to supply the correct input type.