-
-
Save xamox/2438871 to your computer and use it in GitHub Desktop.
''' | |
This is how to track a white ball example using SimpleCV | |
The parameters may need to be adjusted to match the RGB color | |
of your object. | |
The demo video can be found at: | |
http://www.youtube.com/watch?v=jihxqg3kr-g | |
''' | |
print __doc__ | |
import SimpleCV | |
display = SimpleCV.Display() | |
cam = SimpleCV.Camera() | |
normaldisplay = True | |
while display.isNotDone(): | |
if display.mouseRight: | |
normaldisplay = not(normaldisplay) | |
print "Display Mode:", "Normal" if normaldisplay else "Segmented" | |
img = cam.getImage().flipHorizontal() | |
dist = img.colorDistance(SimpleCV.Color.BLACK).dilate(2) | |
segmented = dist.stretch(200,255) | |
blobs = segmented.findBlobs() | |
if blobs: | |
circles = blobs.filter([b.isCircle(0.2) for b in blobs]) | |
if circles: | |
img.drawCircle((circles[-1].x, circles[-1].y), circles[-1].radius(),SimpleCV.Color.BLUE,3) | |
if normaldisplay: | |
img.show() | |
else: | |
segmented.show() |
When I run the code, I get an error that says "ImportError: No module named SimpleCV," and I already have SimpleCV installed on my RPi...any help or suggestions?
Thanks a lot dude... this was really helpful!!!! Please continue to share more things as such so we(the beginners) can from your experiences and codes!
This is awesome, thank you!!
how would you change the colour of the ball it is trying to track?
This is truly great, but my windows is lagging compared to your video. I'm going to try this on a PCDuino mini, with a wifi arduCAM once I recieve my order from China; it will be a while. I tried editing the line, as posted above and got a black screen:
if circles:
circles.draw()
img.drawCircle((circles[-1].x, circles[-1].y), circles[-1].radius(),SimpleCV.Color.BLUE,3)
I also tried it without the parameters with the same black screen result, can you please fill in what I have omitted?
Really just depends. This is a very simple example and maybe shouldn't even be considered tracking persay, but more detection like you mention. You could just change the line:
if circles:
circles.draw()
That will highlight all the circles found in the image that are white. If you want to say track frame to frame you probably want to keep a queue or list of the previous x,y values of all the circles found, then use something like scipy's euclidean distance (http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.spatial.distance.euclidean.html), to find the next closest circle in the frame. This is still pretty simple as you are assuming frame to frame it is has moved. There are also more "true" type tracking examples located in the simpleCV repo:
https://github.com/sightmachine/SimpleCV/tree/master/SimpleCV/examples/tracking