Hello, I would like to be able to get the stream of from the axis camera plugged into the router into a Python program so I can perform some image processing on it with OpenCv.
How would I got about doing this? And is there any example code?
Hello, I would like to be able to get the stream of from the axis camera plugged into the router into a Python program so I can perform some image processing on it with OpenCv.
How would I got about doing this? And is there any example code?
I’m not sure this is a full answer but…
You can use a lot of OpenCV image manipulation features by way of the recently-released GRIP. I’ve been playing with this and it’s really slick. Powerful, easy to use, and written in Java so it will run on a DS, RoboRio, or other onboard processor. It can output to NetworkTables, which puts the data in easy reach of any Python program.
Another similar option is RoboRealm. Every team gets a code for a free license (see your TIMS). It’s also easy and powerful, writes to NetworkTables and even lets you run Python code right inside the app. We did exactly that with an Axis in the 2014 game to identify the hot goal during autonomous. The only downside is it’s a PC-only app, so you’ll need to do processing on your DS or similar onboard computer.
Hope that helps.
This is the code from a demo I did with my team a while back.
I highly recommend that you record videos of interest and then develop your algorithm with the videos. It will save you a lot of time and effort. Then once you think the vision system is working, link it to your robot and let it rip.
Yes will do. Thanks. Will test this tomorrow.
Our OpenCV code from last year running on the RoboRIO: https://github.com/frc1418/2015-vision
You will need to install OpenCV to use it, see https://github.com/robotpy/roborio-opencv
Okay I got some code to work that I found someplace else. Here’s what I have.
import cv2
import urllib
import numpy as np
stream=urllib.urlopen('http://10.58.54.108/mjpg/video.mjpg')
bytes=''
while True:
bytes+=stream.read(1024)
a = bytes.find('\xff\xd8')
b = bytes.find('\xff\xd9')
if a!=-1 and b!=-1:
jpg = bytes[a:b+2]
bytes= bytes**
i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.CV_LOAD_IMAGE_COLOR)
i = cv2.cvtColor(i, cv2.COLOR_BGR2HSV)
cv2.imshow('i',i)
if cv2.waitKey(1) == 27:
exit(0)
My question I have now is that does the rest of my code for my program go in that while loop? I don’t think I clarified in my other post that this program will be running on the driver station.**
Yes, you would put your code in that loop. But… I wouldn’t use that code, it’s not going to be particularly efficient.
You might want to try this instead: https://github.com/frc1418/2015-vision/blob/master/robot-vision/mjpg_client.py
Great! Although could you provide a simple example of how to implement this?
Look at the files next to it?