ev3dev / ev3dev-lang-python

Pure python bindings for ev3dev
MIT License
422 stars 146 forks source link

Using Webcam for EV3 object detection. #747

Open KooshaKayani opened 4 years ago

KooshaKayani commented 4 years ago

Hey I'm trying to make an object detection code to detect black and silver balls. I'm tried to use pixycam2 but it only detect hue colors. I want to know if there is any way to use pixy as webcam and write a new algorithm with TensorFlow lite and open cv. but I don't know how to use pixy as webcam or if its possible to do so. If not is there any other way to do such a thing like using raspberry pi and then connecting it to ev3 (which I don't know how to do that). Or should I use an other webcam? But I don't know what webcam to use. can someone help me with any of those questions? that would be really appreciated.

QuirkyCort commented 4 years ago

Going for Robocup? Those balls can be rather challenging to detect reliably.

No idea if you can use a pixycam as a webcam, but you should be able to just get a cheap webcam and get it to work with ev3dev. A quick google suggests that the Logitech C270 and Logitech C920 works fine.

The EV3 is very slow compared to a Raspberry Pi. You may get better results if you use the pi to perform the object detection and send the result to the EV3. You can send the results via a network link; just connect them the same way that you would connect an EV3 to a computer.

WasabiFan commented 4 years ago

The advice from @QuirkyCort is good. In addition:

The USB port on the EV3 is only USB1.1, making it inadequate for even moderate video bitrates. It can work, but it won't be pleasant, and as mentioned above the processing on the EV3's slow CPU will be extremely limited.

Doing the computations on an external RasPi would make a lot of sense. I've personally had success with doing color-based detection on Raspberry Pi Zero, which is on the very low end of CPU specs but is very likely to fit into your size/profile budget. If you have extra space and power, a full RasPi is certainly capable -- the RasPi 4s are super powerful, for their class!

To connect a RasPi to the EV3, the easiest option is probably (?) to modify an EV3 cable so you can connect it to the RasPi via UART. I am having trouble finding the posts I know we've had about how to do this, but @dlech may know. Another option may be to plug the RasPi in via USB, using the RasPi's client (OTG) port.

KooshaKayani commented 4 years ago

thanks @QuirkyCort and @WasabiFan I will be trying to connect a raspberry pi to ev3. Do you have any advice for object detection? I'm trying to use TensorFlow light. @QuirkyCort & @WasabiFan can you explain how to connect ev3 and raspberry more clearly cause unfortunately most of the records are old, incomplete or not clear in the internet. thanks koosha.

KooshaKayani commented 4 years ago

Also is there anyway for them to communicate via USB cable?

dlech commented 4 years ago

Raspberry Pi is a Linux computer, so connecting the EV3 to it is the same as any other Linux computer.

KooshaKayani commented 4 years ago

@dlech Is there any way for me to connect raspberry and ev3 via Bluetooth and python? I need to complete a task in raspberry and send the result to ev3 using Bluetooth or any other fast form of communication if its possible.

QuirkyCort commented 4 years ago

Connecting the RPI to EV3: https://www.ev3dev.org/docs/tutorials/connecting-to-the-internet-via-bluetooth/ The RPI is a linux computer, so follow the steps for Ubuntu. If you're not running Ubuntu on your RPI, you may need to modify the steps a little.

Sending data from RPI to EV3: https://realpython.com/python-sockets/ Once connected, you can send data over the network. If both ends are running Python, the above will give you a starting point.

KooshaKayani commented 4 years ago

thanks @QuirkyCort that helps a lot

WesleyJ-128 commented 2 years ago

Do you have any advice for object detection? I'm trying to use TensorFlow light.

You could use GRIP, which gives you a GUI for designing an OpenCV pipeline, then creates Java or Python code to run that pipeline.