Ask Your Question
0

Haar Detection: The node does not represent a user object (unknown type?)

asked 2013-04-06 05:15:14 -0600

Lonelycode gravatar image

Hi,

I've been creating my own Haar classifiers using OpenCV and wanted to use them in SimpleCV. OpenCV has two formats for creating Haar Cascades (a deprecated version that is output when using opencvhaartraining (which is now deprecated and no longer supported) and opencvtraincascade (which can perform both Haar-like feature training and LBP).

The new version (opencv_trainscascade) has an ouput flag called -baseFormatSave which is meant to save haar cascades in the old format.

Now, I have tried to import new cascades and old cascades, and neither of these work with SimpleCV, instad outputting the above error.

The code I'm using is here:

import SimpleCV

cam = SimpleCV.Camera()

while True:
    img = cam.getImage()
    faces = img.findHaarFeatures('/path/to/cascade_oldformat.xml')
    if faces:
        for face in faces:
            face.draw()
    img.show()

OpenCV also outputs this error if you load the haarcascade wrongly, the way I've managed to get it working with the new cascades is like this:

import cv2 as base_cv
from SimpleCV import *

cam = Camera()

while True:
    img = cam.getImage()
    im2 = img.rotate90().grayscale() # Make it compatible with OpenCV Array
    haar = base_cv.CascadeClassifier('cascade.xml') # New cascade format
    detected = haar.detectMultiScale(im2.getGrayNumpy())
    if type(detected) is not tuple:
        for face in detected:
            img.dl().rectangle((face[0], face[1]), (face[2], face[3]), Color.RED)
    img.show()

As you can see it's a bit of a mash-up between OpenCV doing the detecting and SimpleCV giving me the nice API for the camera.

When I look at the source for the HaarClassifier it uses a Load() function form cv2 to import the file - maybe it should check the format first (most classifiers that are available in the wild were created a long time ago).

Also, since you can now create LBP classifiers with opencv_trainscascade it would be ideal to be able to use them in the same API?

My question: It would be much easier if we could import the cascades in the new format in the first place - I was wondering if anyone has come across a solution for this or if there's something I'm missing?

Thanks :-)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-04-08 08:49:30 -0600

kscottz gravatar image

I was actually trying to do this a week ago and I had the same problems. For old-style cascades you will want to use the HaarCascade Class. I am fairly confident that it will not work with the newer cascades, but I know you can toss the cascade trainer a flag to make it default to the old cascades. I would like to update this fairly soon, and bake in a few cascade creating tools. I have filed a ticket for it here. If you fix it send me a pull request and I will gladly merge it in.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-04-06 05:15:14 -0600

Seen: 6,400 times

Last updated: Apr 08 '13