14

I am interested in creating my own haar cascade xml file, for use with python, to detect a certain logo (let's say it's the apple logo).

I have tried following the instructions at http://docs.opencv.org/trunk/doc/user_guide/ug_traincascade.html and http://note.sonots.com/SciSoftware/haartraining.html

Problem is, although I get a valid functioning cascade file, it does not detect anything. specifically, when I try to detect the object inside the original image used to create it, it is not detected even then.

I already tried resizing the image, or simply putting it in a larger context by inserting it in a picture.

what am I doing wrong?

at shell, I run:

opencv_createsamples -img original.jpg -bg negatives.dat -vec samples_set.vec  -w 48 -h 48

opencv_traincascade -bg negatives.dat -data mycascade -vec samples_set.vec -w 48 -h 48

which seems to work fine, creating a cascade file. Then, in python:

import cv2
cascade2 = cv2.CascadeClassifier('mycascade.xml')
cv2Image = cv2.imread('original.jpg')
cascade2.detectMultiScale(cv2Image)

and the detection comes up empty. I did try to test with a "standard" xml that comes with python and it works, so something is wrong with mine.

eran
  • 14,496
  • 34
  • 98
  • 144
  • If you are really doing Logo detection I recommend go for features extraction and matching using SIFT/SURF/ORB/MSER .. since logo shapes are usually constant the extracted features shall match well. In my oppionion logo detection with haar features will be very odd to do.Because usually logo's does not have enough features to be trained through opencv like other objects (face, eyes,nose etc). Logos are usually full of edges and corners. But I want to hear about your results too. – isrish Nov 26 '12 at 19:56
  • -w 48 -h 48 seems quite a lot. (default is 24). have you tried smaller values ? it's the 'internal size', not the size of your logo in the createsamples stage – berak Feb 24 '13 at 19:16

1 Answers1

5

I hope you have found your answer by now that it has been 2 years since you've asked your question! anyways I'll share what I know for anybody else who might have the same question. One of the best and fully explained tutorials on this matter is from Coding-Robin and I have personally learned a lot from there. one thing to remember is you should not use the same image which was involved in creating the haar cascade, and the reason is that it simply is already classified as a positive (or negative) sample, so trying to process it is pretty useless.

mid
  • 204
  • 2
  • 12