Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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('alz.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

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('alz.xml')
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