Go to Post You lame pig farmer! I'm not talking about a bunch of dudes sitting around eating their packed lunches that Mommy made. - Paul Copioli [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Events   CD-Media   CD-Spy   FRC-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 01-31-2011, 07:20 PM
Patrick Chiang Patrick Chiang is offline
Programming
FRC #3070 (Team Pronto)
Team Role: Mentor
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Seattle
Posts: 160
Patrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to all
Java Swing display image stream

Tthe camera can output a stream of images into a specific IP address (depending on where we plug it).

Now, our team is aiming to write an entirely Java/Swing-based Dashboard. So far, we are successful in using sockets and connectors to open up a connection from the robot (server side) to the driver station (client side). And we've managed to pass values and strings over the network through this connection.

The problem is, we can't find a way for us to get camera code. My understanding is that we need to get the client side computer to somehow connect to the image IP address, get the image, and display it on the Swing dashboard. We have no idea how to do this (which classes to use, how to get the image, do we need external libraries for decompressing MPEG stream...etc)

Help?
Reply With Quote
  #2   Spotlight this post!  
Unread 01-31-2011, 08:45 PM
Greg McKaskle Greg McKaskle is offline
Registered User
no team (Team NI)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 3,914
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Java Swing display image stream

The Axis site has CGI details in the VAPIX reference manual. Basically, you initiate a session with the camera's web server, it sends you images, and you display them using an MJPG compatible viewer.

Greg McKaskle
Reply With Quote
  #3   Spotlight this post!  
Unread 01-31-2011, 08:51 PM
sjspry sjspry is offline
Registered User
FRC #1984
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Kansas
Posts: 125
sjspry has a spectacular aura aboutsjspry has a spectacular aura aboutsjspry has a spectacular aura about
Re: Java Swing display image stream

The easiest way to get the image is to request <ip>/axis-cgi/jpg/image.cgi?resolution=320x240. Make sure to have the camera connected to the bridge. ALSO make sure you set the anonymous viewing option of the Axis to true, so you don't have to authenticate.

Then, call:
Quote:
ImageIO.read(new URL("<ip>/axis-cgi/jpg/image.cgi?resolution=<res>"));
ImageIO.read() returns a BufferedImage object, which you can paint with Graphics.paint(Image) from inside a component. This method works very fast, I can get upwards of 30fps (seeing as the camera and computer are on the same LAN) and this offers basically the same performance, as the mjpeg stream is not any more compressed.

Since I don't think I could adequately explain it here, I've attached my dashboard project. The files you should look at are probably AxisCamera.java (getting the image), JImagePanel.java (painting the image), and AxisCameraProcessor.java's run method (for getting/painting the image). Post if you need something clarified; basically, the JImagePanel takes an array of pixels (as ints) which have been grabbed from the camera and processed, and loads them into a BufferedImage via the BufferedImage's setRGB() method (the code as-is could be sped up by minimizing the amount of intermediate copies), which the JImagePanel then displays in its paint method via Graphics.drawImage().

Also, make sure you look at BigBrotherGUI.java, starting at line 50. If you want to run it, this sets the IP of the camera (and the port of the custom Dashboard, but ignore that for now -- I have most things working, but they're not in a state to be shared yet, as in, not very portable as far as code goes).


There's some other stuff (parts of AxisCameraProcessor and ImageOps) you can ask about if you want, it's object detection by filtering colors and then using blob detection (right now it should be wired up for motion detection, hook it up to the camera, it's kinda cool). There's also some edge detection laying around. I would suggest, though, using something like OpenCV if you really wanted to have some vision for autonomous.

The overall project layout is kind of lousy, but I tried to document it. You can ignore large parts of JImagePanel as of now, most of the shape/text/etc code was from when I was going to have the robot do image processing (and send back markup commands), before I learned it was so slow and then moved it to the computer. Otherwise, I think I documented most things or made them self-explanatory (except the GUI code, I guess, but that's "just how it works"). If you need help with your GUI code go ahead and post what you need and your attempt here, I'll try to help the best I can (or use NetBean's Matisse, which is good for getting something made quick).


EDIT: I'm not sure how you'd go about displaying the mjpeg stream (as in, if you could use ImageIO in some way or not), but I really don't see the benefit in doing so. The real bottleneck will be any processing you do, and if you don't do any, then both methods will be very similar in speed. The only thing that seems to slow it down noticeably is increasing the size of the image.
Attached Files
File Type: zip BigBrother.zip (86.8 KB, 189 views)

Last edited by sjspry : 01-31-2011 at 08:53 PM.
Reply With Quote
  #4   Spotlight this post!  
Unread 01-31-2011, 09:00 PM
wdell wdell is offline
Registered User
AKA: William Dell
FRC #3999 (Shadetree Mechanics)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Killeen, Texas
Posts: 55
wdell has a spectacular aura aboutwdell has a spectacular aura about
Re: Java Swing display image stream

Gah, I can't find it! I had the code around here for a simple java based web browser that would show you how to do it.

Eh, found the code online at http://www.dreamincode.net/code/snippet919.htm. If you look through that you will see how to set up a Swing panel to display a web page, which is how the camera natively outputs it's picture. Should be enough to get you started.

Edit: A bit more searching and I found this, which seems to be a better example.

Last edited by wdell : 01-31-2011 at 09:14 PM.
Reply With Quote
  #5   Spotlight this post!  
Unread 01-31-2011, 10:18 PM
Patrick Chiang Patrick Chiang is offline
Programming
FRC #3070 (Team Pronto)
Team Role: Mentor
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Seattle
Posts: 160
Patrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to all
Re: Java Swing display image stream

Thanks guys!

I find Netbean's in-built GUI builder a good way to do Swing. Doesn't teach me HOW to actually use Swing, but is useful for getting stuff done, which is what matters at the moment. (Like using Dreamweaver to build a website instead of notepad.)

So far, I've written some code based on some parts of the BigBrother project, namely the parts I think I understand. (Which is AxisCamera, parts of AxisCameraProcessor). Everything is compilable and debug-ready and I'll see what happens when I get to the shop tomorrow afternoon. And if it works, we'll be sharing our dashboard code so everyone can use it.
Reply With Quote
  #6   Spotlight this post!  
Unread 02-01-2011, 03:20 PM
drakesword drakesword is offline
Registered User
AKA: Bryant
FRC #0346 (Robohawks)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: USA
Posts: 200
drakesword is on a distinguished road
Re: Java Swing display image stream

We are looking at using Processing as our front and back end for our camera.
Processing.org
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 11:37 PM.

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


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