comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » face detection (via Python bridge)
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
face detection (via Python bridge) [message #93872] Mon, 14 November 2016 06:47 Go to next message
markb77 is currently offline  markb77
Messages: 217
Registered: July 2006
Senior Member
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-pyt hon/

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_cla ssification.html?highlight=detectmultiscale#cv2.CascadeClass ifier.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
Re: face detection (via Python bridge) [message #93874 is a reply to message #93872] Mon, 14 November 2016 08:31 Go to previous messageGo to next message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
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-pyt hon/
>
> 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_cla ssification.html?highlight=detectmultiscale#cv2.CascadeClass ifier.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
Re: face detection (via Python bridge) [message #93875 is a reply to message #93874] Mon, 14 November 2016 11:21 Go to previous messageGo to next message
markb77 is currently offline  markb77
Messages: 217
Registered: July 2006
Senior Member
Thanks for the suggestion, but it's not working yet. It this fails at the Python.Run statement, because the faceCascade object is not defined on the Python side. When I tried to add

Python.faceCasecade = faceCascade

it still didn't work.

% PYTHON_RUN: Exception: name 'faceCascade' is not defined.
Re: face detection (via Python bridge) [message #93878 is a reply to message #93875] Mon, 14 November 2016 15:45 Go to previous messageGo to next message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
On Monday, 14 November 2016 11:21:14 UTC-8, superchromix wrote:
> Thanks for the suggestion, but it's not working yet. It this fails at the Python.Run statement, because the faceCascade object is not defined on the Python side. When I tried to add
>
> Python.faceCasecade = faceCascade
>
> it still didn't work.
>
> % PYTHON_RUN: Exception: name 'faceCascade' is not defined.

Sorry, Mark, I haven't actually installed the library and tried this, I'm tossing ideas off the top of my head…

Hmm, if that line is a direct quote, then it may be a typo (you have an extra "e" in the middle). That might fix it, or perhaps:

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 = cv2.CascadeClassifier.detectMultiScale(gray,scaleFactor=scal eFactor, minNeighbors=minNeighbors,minSize=minSize, flags=flags)')

faces = Python.faces

Of course, to try it more simply for now, how about:

Python.gray = gray

void = Python.Run('faces = cv2.CascadeClassifier.detectMultiScale(gray,scaleFactor=1.1, minNeighbors=5, minSize=[30,30], flags=cv2.cv.CV_HAAR_SCALE_IMAGE)')

faces = Python.faces

Is that any better?

Cheers,
-Dick

Dick Jackson Software Consulting Inc.
Victoria, BC, Canada --- http://www.d-jackson.com
Re: face detection (via Python bridge) [message #94662 is a reply to message #93872] Wed, 09 August 2017 11:31 Go to previous message
lamichhane.rasmi is currently offline  lamichhane.rasmi
Messages: 1
Registered: August 2017
Junior Member
Hi, I think the problem is minSize=[30,30], that you are passing a list and somehow 2nd position is not found. I also have the same problem, let me know if you found any solution.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: idl save
Next Topic: plot solid circle on image

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 07:16:50 PDT 2025

Total time taken to generate the page: 0.00413 seconds