March 14, 2013

Homemade Shooting Gallery 1.0 (LabVIEW Image Processing)

Introduction:

Several years ago I've seen a shooting gallery in the Palace of Miracles. They've solved it with a laser gun (laser with invisible frequency) and a photosensitive target. I wanted to do the same, but much cheaper, without a photosensitive target. So I thought about visible laser dots and image processing with a webcam watching the target. That sounded much cheaper and easier and I also wanted to learn the basics of image processing for other projects, so I've started.

Purpose of the project:

So my project has basically 3 parts: a gun, that emit a red laser dot for a 0.1-0.2 seconds, a target made of paper and a software part with a webcam, that monitors the target, recognizes the laser-dot and calculates your score.

What you need:

for the gun:

  • a laser-diode, like this or these
  • a battery
  • button
  • some kind of timing IC with capacitors and resistor, more about it later
  • bunch of wires
  • some kind of base. Mine was made out of wood.
for the target:
  • just design and print something like this in A3 paper (or bigger) (mine's here)
for the software part:
  • webcam
  • for the image processing LabVIEW with NI-IMAQ and NI Vision Acquisition. I've used LabVIEW 2009, but I suppose other versions work too.

First step: the gun

It's not so hard to build a gun with a button and a laser diode and if you press the button, the diode will show up. But I needed something more. I wanted the laser dot only showed up for 0.1-0.2 second, because you know, that would be more realistic and otherwise people can just move the dot to the middle of the target. Of course it wouldn't be so hard with arduino, but I wanted to do it simpler with only IC(s), resistor and capacitors.
First I looked around on the internet, and found, that almost every timing problem has a solution, called IC 555. I've made very nicely blinking leds and I can even make a led, that shows up when you press the button and after a controllable time it turns off. The only problem was that this time had to be longer than the button-pressing-time. So I asked about it on a mailing list, and got several answers. They recommended a site where is a description about this, but it just didn't want to work. So I asked my digital-electronics-teacher, and he recommended the 74122 IC (actually he recommended 74121, but I could buy only 74122, but it's almost the same). With this I have solved, that if you pressed and release the button, then it shows up for a changeable time. So here is the wiring:

For debugging I connected an other button, which is a simple press-light wiring. After testing on breadboard, I built it and soldered together:



It looks good, but the laser dot was just too dim, and from 5 m I can't even see it, so I've used the debugging-button for the test and I'm still trying to find a good solution.
That is also a problem, that I forgot to unplug it for the night, and till morning the battery discharged, and I had to buy a new one. So I'll integrate a new switch between the battery and the others.

Second step: the LabVIEW programming

As I mentioned one of my previous post I've found a youtube tutorial for image processing. I've edit it a little bit to pattern the middle of the target and the laser dot:
When the program starts to process the image of the webcam, first it makes the picture black-and-white, after that starts looking for the patterns. If it finds these, it gives back the coordinates of the en-frame rectangle. After that it count the coordinate of the middle-point of the target and the dot (for this we only need the top-left and down-right corner of the rectangle. It also shows these coordinates as an array). Sometimes the processing algorithm loses the match for a second and give back 0, so I've made a subVI for filter it and give back the previous value:
So it knows the coordinates of the 2 middle-points. Then it counts the distance between these points, subtracts it from 100 and this is your score. I store it as unsigned int, so if it is less than 0, it's going to be 0.

But I got a strange error. If I cover the camera, => there isn't any pattern, all of the coordinates will be the same, the previous version of the first coordinate. After 10 minute of google, I found all my subVIs are using the same memory, so I have to clone them to solve the problem. Open the subVI, File > VI Properties and change it so:
After that, it worked fine, here is the result:

Summary

As you can see on the video, sometimes it doesn't recognize the dot. It can be because the target's lines are too thick and the dot gets lost between them. I've showed it to my teacher, and he recommended to mark the edge of the target and only looking for the dot inside of the target. He said, that will make the program run faster and smoother. I also have to rethink the gun, so version 2.0 coming soon.

Best regards:
Mark

No comments:

Post a Comment