-1

I would need haar cascade classifier to detect coins, in particular euros, if they exists. I have been trying to generate my own for days bur results are always bad. Or maybe, do you know a good tutorial? Thank you

SagittariusA
  • 5,289
  • 15
  • 73
  • 127
  • Why are you voting my question down if this (http://stackoverflow.com/questions/9015498/need-haar-casscades-for-nose-eyes-lipsmouth) asked the same? – SagittariusA Jan 27 '16 at 11:25

1 Answers1

1

You're probably not going to find many cascades pre-made for coins, or even specifically for euros. I'd recommend training your own.

As for tutorials, I used the opencv 3.0 traincascade tutorial when I was creating my LBP cascade, but it also makes HAARs. I also used mergevec to inflate my positive count.

Basically what I did when I was making mine was this:

I generated positive vectors using opencv_createsamples (which is in the opencv install) and mergevec. I basically just created all my vectors off of small batches of individual positive images and all the negative images, which game me some positive images to work off of. Then, I used mergevec and merged those vectors together to get a single vector file that opencv_traincascade could use.

Then, I ran opencv_traincascade with that new positive vector from the mergevec, and the negatives that I had. I think I ended up with about 7000 negatives and about 13000 positives, which is probably a bit overkill but I got a really nice cascade out of it. Try to keep the width and height below about 100x100, otherwise it will take all week to train.

Rachel L
  • 327
  • 3
  • 13
  • thank you from heart for you kind reply. I wish more people gentle like you would make a little effort to reply, even if some questions may sound silly for them. Anyway, I have been studying and following this (http://www.memememememememe.me/training-haar-cascades/) tutorial for days which explains exactly what you've written.First trial was really disappointing.Now my mac has been training again, for more than 8 hours; with 1100 positives and 1700 negatives.I can't find so many euro images on google images and I would not know where to download so many images as backgound/negatives – SagittariusA Jan 27 '16 at 22:34
  • At last I know I'm on the right way... we'll see. Thank you again! – SagittariusA Jan 27 '16 at 22:34
  • 1
    What I did to get a bunch of images was to actually take a short video of the object, and then split the frames out (you can actually do that through opencv, just by using `videocapture` and saving each frame as something like `/destinationfolder/imagenameXYZ`, and just increment that for each frame. You need to then go through and cull the really bad images, but it's easier than finding a billion images online. Background is easy compared to that - `http://tutorial-haartraining.googlecode.com/svn/trunk/data/negatives/` works, just make sure none of the negatives have any coins in them. – Rachel L Jan 27 '16 at 22:37
  • Ok, I'll try with a video as you have suggested. Just one thing: I imagine that videocapture program will use the web cam, won't it? But if I have a video of the coin, then also a table, or anorher surface, upon which the coin lies will be visible. What about it? Is it a problem? Or shall I crop the photo/frame around the coin so that only this last is visible? – SagittariusA Jan 27 '16 at 22:44
  • 1
    `Videocapture capture(0);` brings up a webcam, `Videocapture capture("file/name/here.avi");` will open up a video file you made (I filmed it on my phone and then transferred it over). You do want the image as cropped as possible, with a single color for background (black's best and the default for `opencv_createsamples`, but you can change it to any color, like blue or white etc), and it can be done either in that opencv program that's getting the frames, or post using an image editor like `paint.net`. – Rachel L Jan 27 '16 at 23:03
  • Did you finish the haar cascade? I am looking for one for euro bank notes and I wonder if I will have to train a new one – Biribu Feb 11 '17 at 11:23
  • I finished my cascade (and it worked fine). You will need to make a new one for euro bank notes, but it should be the same method - film it, grab the frames, cull the bad images, crop the good ones, and there are your positive images. The background group (that tutorial-haartraining) should still work, just remove any images with the euro notes in them. – Rachel L Feb 11 '17 at 19:33
  • Thank you Rachel. One question, when you say: film it, grab the frames.... film what? bank notes? how many pictures did you use for coins? should they be all images equal in size? did you rotate and crop the images so they have all same W and H? I have tried a couple of times with createsamples option and 3-4 pictures but it doesn't work fine. I have some kind of problems with W and H option, I think. I found some webpages with background images, I think I can get about 3k without banknotes in them. – Biribu Feb 15 '17 at 07:48
  • I basically just recorded video of the objects in question and then pulled the frames out so I had a bunch of different still photos of them at different angles (Opencv program that for looped through the video and saved each frame). I used 10000 images for the positive photos (with notes) and 3000 images for the negative photos (without). I cropped out everything in the positive images so with width and the height was the same (150 px), but left the rotation in. – Rachel L Feb 15 '17 at 17:56
  • I did the video thing yesterday and I got about 6k images of a single banknote and side. I am running now the training command. I think it will take another 3-4 days yet so I will tell then. I haven't cropped my positive images. I will try if I don't get any good result. What I don't really understand is about cropping the positive images. – Biribu Feb 16 '17 at 07:54
  • Maybe my english is not good enough to explain this, I will try my best: Width in a banknote is about 2 times its height. so if I take a picture on its horizontal position and crop it to have just the banknote, it would be something like: 150x60(WxH), if now I rotate it 90º, take a picture and crop it, it would be 60x150(WxH). Is this ok? Should I have to rotate the image to have it 150x60 instead? Also, if I rotate the image (original one) to 45º, how should I crop the image? width and height will be higher than the other 2 images... Do you understand what I mean? – Biribu Feb 16 '17 at 07:55
  • I understand what you mean - I got lucky in that my cascade was looking at fairly square objects, so this wasn't an issue. I think you can all leave them at the same rotation and createsamples will turn it for you when it generates the positves, but I'm not 100% sure. – Rachel L Feb 16 '17 at 17:09
  • Well, after some days to get my haar cascade file. I tried to recognize a 5 euro banknote and I just got lucky in one image. In others 4 I tried, nothing. Even that some of those 4 where from the positive folder... What did you do with the background of your images? you painted in black? Mine where brown (table color) with some light reflection, could it affect to the result of the algorithm? Damm it, I have 1400 positive images for one face of one banknote, if I have to repaint all of them I will retire myself doing that. – Biribu Feb 20 '17 at 07:47
  • Black's what I used and the default for `createsamples`, but you can use any color. It could be that the brown's too close, but I can't be sure without seeing it. You might also want to try more positive images - I used 10000 for my one object. You might also want to play around with your `minNeighbors`, and min and max size variables in your `cascade.detectMultiScale` call in your code - lowering the number of `minNeighbors` should give you more detections (though with a higher chance of false positives). – Rachel L Feb 20 '17 at 18:08