Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Python (http://www.chiefdelphi.com/forums/forumdisplay.php?f=187)
-   -   How to get image from Axis camera to a Python program? (http://www.chiefdelphi.com/forums/showthread.php?t=141658)

JohnM 13-01-2016 18:41

How to get image from Axis camera to a Python program?
 
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?

vScourge 13-01-2016 19:02

Re: How to get image from Axis camera to a Python program?
 
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.

dawonn 13-01-2016 19:09

Re: How to get image from Axis camera to a Python program?
 
This is the code from a demo I did with my team a while back.

https://github.com/dawonn/HelloPythonOpenCV


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. :)

JohnM 13-01-2016 21:59

Re: How to get image from Axis camera to a Python program?
 
Quote:

Originally Posted by dawonn (Post 1523076)
This is the code from a demo I did with my team a while back.

https://github.com/dawonn/HelloPythonOpenCV


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.

virtuald 14-01-2016 00:04

Re: How to get image from Axis camera to a Python program?
 
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

JohnM 14-01-2016 23:05

Re: How to get image from Axis camera to a Python program?
 
Okay I got some code to work that I found someplace else. Here's what I have.

Code:

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[b+2:]
        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.

virtuald 15-01-2016 00:29

Re: How to get image from Axis camera to a Python program?
 
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-visi...mjpg_client.py

JohnM 16-01-2016 11:47

Re: How to get image from Axis camera to a Python program?
 
Quote:

Originally Posted by virtuald (Post 1524047)
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-visi...mjpg_client.py

Great! Although could you provide a simple example of how to implement this?

virtuald 16-01-2016 11:49

Re: How to get image from Axis camera to a Python program?
 
Quote:

Originally Posted by JohnM (Post 1524792)
Great! Although could you provide a simple example of how to implement this?

Look at the files next to it?


All times are GMT -5. The time now is 19:49.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi