bskari / pi-rc

Turn your Raspberry Pi into a radio controller for RC toys.
GNU General Public License v2.0
139 stars 38 forks source link

Replace gstreamer dependency from watch.py #2

Closed bskari closed 10 years ago

bskari commented 10 years ago

Running watch.py requires that the user installs the gstreamer package. This is a really large package and is problematic for users with smaller SD cards.

I originally used gstreamer because I couldn't find a reliable cross-platform way of capturing images from a webcam. Running a background gstreamer process to continually save images to the hard drive and open them periodically in Python is really hacky and gross. I recently came across an OpenCV package for Python that looks like it can capture from webcams, so that should be investigated further. There's another package, SimpleCV, that looks really easy to use, but I think that installing it with pip requires GCC to be installed as well as Python development headers, while many distributions have packages for Python OpenCV, so I'd prefer to use the latter if possible. I've also heard that the Raspberry Pi camera module and OpenCV are sometimes difficult to work with together, so those should be tested, as well as separate laptops or other computers with webcams.

It would also be nice to add an option to remove the webcam dependency all together, so that the Pi can still search for command codes and users can just watch the car for movement themselves.

ghost commented 10 years ago

@bskari So any thoughts/updates so far? I haven't been able to get pi-rc to work because of gstreamer not working. I've sent you an email with further details. Thanks

bskari commented 10 years ago

I just added a --no-camera option so that you can iterate through and search for command codes without using a camera. It's going to be really slow (taking several hours), and you'll need to watch the car manually to see if it moves, so this might only be an option if you're sitting around watching TV or something, or don't mind getting woken up by driving cars overnight.

I took a quick look at what it would take to get the Raspberry Pi camera working, and it looks like it's going to require more than a trivial amount of work. I have some time this weekend, so I'll try to get it done soon.

bskari commented 10 years ago

Cool, the Raspberry Pi camera should be working. For webcams and other non-Rpi-cameras, I also removed the dependency from gstreater and replaced it with streamer, which is a much smaller package. Let me know if these work!

ghost commented 10 years ago

@bskari Thanks for the update! I really appreciate it. I've attached a USB 2.0 web cam to my Pi, I've compiled the code and ran all of the other commands, the current situation is that it tries to connect to a Raspberry Pi camera instead of the web cam. Heres the output:

root@LavanoidPi: /home/Lavanoid/pi-rc# python watch.py -f 40 -s 127.0.0.1 Sending commands to 127.0.0.1:12345 mmal: mmal_vc_component_create: failed to create component 'vc.ril.camera' (l OMEM) mmal: mmal_component_create_core: could not create component 'vc.ril.camera' mmal: main: Failed to create camera component mmal: Camera is not enabled in this build. Try running "sudo raspi-config" annsure that "camera" has been enabled

Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner self.run() File "watch.py", line 99, in _get_picture_from_command image = Image.open(file_buffer) File "/usr/lib/python 2.7/dist-packages/PIL/Image.py", line 1980, in open raise IOError("cannot identify image file") IOError: cannot identify image file

Then it just hangs. I havent tried the --no-camera option yet. Even with camer enabled in raspi-config, it still doesn't work.

Thank you for your dedication to this project! I really appreciate your work.

ghost commented 10 years ago

I also used the --webcam option but I got this error:

Sending commands to 127.0.0.1:12345 Caught exception, exiting local variable 'webcam' referenced before assignment

Another thing that you could do is add the following to the start to watch.py:

!/usr/bin/python

This removes the need to add "python" to the cmd line. Of course, the files permissions will have to be set as executable ( I use "chmod 0777").

bskari commented 10 years ago

Oops! That's what I get for not testing my code. I think I have it fixed; it works with my laptop with a built in webcam anyway. I don't have a USB webcam that I can test it on my Pi with, so if you can let me know if it works for you, I'd appreciate it. If it doesn't, I should be able to borrow one from a friend.

Oh, and thank for the suggestions about adding the sharp bangs #! and making the files executable! I hadn't even though to do that :smile:

ghost commented 10 years ago

@bskari Thanks for the quick response. The webcam works now. That's great! The scan is typically slow (as is expected) but works. Not sure if optimisation is possible. It saves the .png files too! That's great! Is there anything else that is saved other than the .png files? How is the .json made? Do I just write it manually? I don't mind if I have to or not.

bskari commented 10 years ago

Nope, the only thing that it saves is the .png files. It should only be saving them when it detects motion from the camera, which should hopefully only be happening if the car moves. Do you have the camera pointed at the car and in a place where you can control the lighting, such as a closet?

When it saves the images, it should have in the file name the frequency, number of signal repeats, etc. that you can then use with the control.py program. Once you figure out the exact commands to make the car move in different ways (such as forward and right), you can store those values in a json file. You'll have to write that yourself, but I included an example that you should be able to copy and just fill in the values yourself.

ghost commented 10 years ago

@bskari Yeah, I have a place that I can control the lighting. I see the .png files too! Thank you for the swift response. I've managed to get the car moving by the way, thanks for your effort in this project - it's got to be the most exciting project I've used on my Raspberry Pi.

bskari commented 10 years ago

That's awesome! I'm really excited to hear that you got it working :smile: As far as I know, you're one only person other than me who's used it. Did you write a JSON file? If so, I'd love to have another example JSON file in the repository here. If you have one, would you mind submitting a pull request or just emailing the file and the information about the make and model of the car? That would be awesome!

I'm going to go ahead and close this issue.

ghost commented 10 years ago

I'll email you more details for sure. Thank you again :).