Go to Post Robotics season has monopolized my time for the past several weeks so I have not been keeping up with Segway news lately - Stu Bloom [more]
Home
Go Back   Chief Delphi > Technical > Programming > Python
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 13-01-2016, 18:41
JohnM's Avatar
JohnM JohnM is offline
Registered User
FRC #5854 (Glitch)
Team Role: Programmer
 
Join Date: Mar 2014
Rookie Year: 2013
Location: North Carolina
Posts: 53
JohnM has a spectacular aura aboutJohnM has a spectacular aura about
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?
Reply With Quote
  #2   Spotlight this post!  
Unread 13-01-2016, 19:02
vScourge's Avatar
vScourge vScourge is offline
Videogame Developer
AKA: Adam Pletcher
FRC #4096 (Ctrl-Z)
Team Role: Coach
 
Join Date: Jan 2014
Rookie Year: 2012
Location: Champaign, IL
Posts: 33
vScourge is on a distinguished road
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.
Reply With Quote
  #3   Spotlight this post!  
Unread 13-01-2016, 19:09
dawonn's Avatar
dawonn dawonn is offline
Mentor
AKA: Dereck
FRC #2586 (Calumet Copperbots)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Auburn Hills, Mi
Posts: 53
dawonn is an unknown quantity at this point
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.
Reply With Quote
  #4   Spotlight this post!  
Unread 13-01-2016, 21:59
JohnM's Avatar
JohnM JohnM is offline
Registered User
FRC #5854 (Glitch)
Team Role: Programmer
 
Join Date: Mar 2014
Rookie Year: 2013
Location: North Carolina
Posts: 53
JohnM has a spectacular aura aboutJohnM has a spectacular aura about
Re: How to get image from Axis camera to a Python program?

Quote:
Originally Posted by dawonn View Post
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.
Reply With Quote
  #5   Spotlight this post!  
Unread 14-01-2016, 00:04
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,043
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
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
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #6   Spotlight this post!  
Unread 14-01-2016, 23:05
JohnM's Avatar
JohnM JohnM is offline
Registered User
FRC #5854 (Glitch)
Team Role: Programmer
 
Join Date: Mar 2014
Rookie Year: 2013
Location: North Carolina
Posts: 53
JohnM has a spectacular aura aboutJohnM has a spectacular aura about
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.
Reply With Quote
  #7   Spotlight this post!  
Unread 15-01-2016, 00:29
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,043
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
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
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #8   Spotlight this post!  
Unread 16-01-2016, 11:47
JohnM's Avatar
JohnM JohnM is offline
Registered User
FRC #5854 (Glitch)
Team Role: Programmer
 
Join Date: Mar 2014
Rookie Year: 2013
Location: North Carolina
Posts: 53
JohnM has a spectacular aura aboutJohnM has a spectacular aura about
Re: How to get image from Axis camera to a Python program?

Quote:
Originally Posted by virtuald View Post
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?
Reply With Quote
  #9   Spotlight this post!  
Unread 16-01-2016, 11:49
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,043
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: How to get image from Axis camera to a Python program?

Quote:
Originally Posted by JohnM View Post
Great! Although could you provide a simple example of how to implement this?
Look at the files next to it?
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 06:27.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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