• face detection (via Python bridge)

    From kartiksareen@gmail.com@21:1/5 to Dick Jackson on Wed Dec 20 17:57:47 2017
    On Monday, 14 November 2016 17:31:47 UTC+1, Dick Jackson wrote:
    Hi Mark,

    I've been working with some Python libraries, and when a colleague had a similar problem, she resorted to something like this (it's like using "Execute" in IDL… not optimal, perhaps, but it might do the job!):

    Python.gray = gray
    Python.scaleFactor = 1.1
    Python.minNeighbors = 5
    Python.minSize = [30,30]
    Python.flags = cv2.cv.CV_HAAR_SCALE_IMAGE

    void = Python.Run('faces = faceCascade.detectMultiScale(gray,scaleFactor=scaleFactor, minNeighbors=minNeighbors,minSize=minSize, flags=flags)')

    faces = Python.faces


    Does that work for you?

    Cheers,
    -Dick

    Dick Jackson Software Consulting Inc.
    Victoria, BC, Canada --- http://www.d-jackson.com


    On Monday, 14 November 2016 06:47:13 UTC-8, superchromix wrote:
    hi,

    I'm having some trouble using the IDL-Python bridge. I'm trying to run the face detection example from this blog post:

    https://realpython.com/blog/python/face-recognition-with-python/

    but my code is crashing at the point where it tries to detect the faces.

    Here is the code:

    pro test_python_face_detect

    cv2 = Python.Import('cv2')

    imagePath = 'C:\temp\FaceDetect\abba.png'
    cascPath = 'C:\temp\FaceDetect\haarcascade_frontalface_default.xml'

    ; Create the haar cascade
    faceCascade = cv2.CascadeClassifier(cascPath)

    ; Read the image
    image = cv2.imread(imagePath)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    ; Detect faces in the image

    faces = faceCascade.detectMultiScale(gray,scaleFactor=1.1, $
    minNeighbors=5,minSize=[30,30], $
    flags = cv2.cv.CV_HAAR_SCALE_IMAGE)


    end

    The error I'm getting is:

    % PYTHON_CALLMETHOD: Exception: Required argument 'rejectLevels' (pos 2) not found.

    The code works fine when run from Python.

    I think it's likely that there are multiple things going wrong with my code. One of them is that IDL is not recognizing that I'm calling the detectMultiScale method using another calling convention (there are two different ways of calling
    detectMultiScale, for some reason). See the docs here:

    http://docs.opencv.org/2.4/modules/objdetect/doc/cascade_classification.html?highlight=detectmultiscale#cv2.CascadeClassifier.detectMultiScale

    Next, the IDL-Python bridge is not recognizing the keywords correctly, since the keywords are case sensitive.

    What else? I don't know.

    Does anyone have a suggestion on how to make this work? I would really like to be able to do face detection within IDL.

    thanks
    Mark

    Hello Sir,

    I am getting some kind similar kind of error...Code below..


    import cv2
    import time
    import sys
    import numpy as np

    cascPath = "C:\\Users\\Mudit\\Desktop\\Thesis\\CNN-master\\haarcascade_frontalface_default.xml"
    faceCascade = cv2.CascadeClassifier(cascPath)

    video_capture = cv2.VideoCapture(0)

    while True:
    # Capture frame-by-frame
    ret, frame = video_capture.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = faceCascade.detectMultiScale(gray, 1.3, 5)
    # Draw a rectangle around the faces
    for (x, y, w, h) in faces:
    cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

    # Display the resulting frame
    cv2.imshow('Video', frame)
    if cv2.waitKey(1000) & 0xFF == ord('q'):
    break

    # When everything is done, release the capture
    cv2.imshow('Video', frame)
    video_capture.release()
    cv2.destroyAllWindows()

    Error:

    OpenCV Error: Assertion failed (!empty()) in cv::CascadeClassifier::detectMultiScale, file C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp, line 1698
    Traceback (most recent call last):
    File "C:/Users/Mudit/PycharmProjects/CNN/webcamcheck.py", line 15, in <module>
    faces = faceCascade.detectMultiScale(gray, 1.3, 5)
    cv2.error: C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1698: error: (-215) !empty() in function cv::CascadeClassifier::detectMultiScale

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)