I think that if you're installing py_websockets_bot on Linux or the Raspberry Pi, that numpy should already be installed. If you're installing on Windows, then you should see that the instructions call for installing NumPy.
In fact, I'm pretty sure that if you've got the get_image.py example to work then you have NumPy installed, as we return camera images as numpy arrays.
In case you're not familiar with it, numpy is a Python library for efficiently accessing arrays of data. It can take a bit of time to get your head around, but it's very powerful. The nice thing about the current OpenCV Python bindings, is that all images and matrices that you send to it, and get back from it's routines are numpy arrays.
Returning to your program. The meanshift script you've found looks like a good start, and should mostly work. The main bit you need to change is to remove references to VideoCapture (which is getting images from a video file), and instead use the py_websockets_bot get_latest_camera_image routine. So instead of the line
- Code:
ret,frame = cap.read()
you would have
- Code:
frame, frame_time = bot.get_latest_camera_image()
The values you need to put into the inRange routine depend upon the range of colours you want to track. In this case, I think that you might be able to leave the values as they are, as what the program is doing, is looking at a rectangle you define, and then building up a histogram, that records the frequency of all the different colours in the rectangle. This means that if you set the rectangle around the region of the image occupied by your tennis ball, then the histogram will record all of the pixel colours that appear in the tennis ball.
Hope that helps.
Regards
AlanStatistics: Posted by Alan — Wed Sep 24, 2014 10:21 am
]]>