View Single Post
  #3   Spotlight this post!  
Unread 10-01-2012, 21:11
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: How to get images to classmate for vision processing?

If you choose to forgo the dashboard (which I think you do, seeing as you are trying to get images back to the classmate for processing) you can configure the ethernet camera to work over one of the open ports outlined in the documentation (which I do believe includes port 80, specifically for the camera). Personally, I found better response times by attempting to fetch a static image in quick succession than accessing the mjpg stream.

Here's a code listing for a crudely hacked-together dashboard I made last year (and haven't had much of a chance to work on since):
Code:
package edu.wpi.first.team._1984.dashboard;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.imageio.ImageIO;

/**
 * Class which encapsulates access to the robot's ethernet camera.
 *
 * @author sid
 */
public class AxisCamera
{
    protected String host;
    protected String res = "320x240";
    protected String grabPage = "/axis-cgi/jpg/image.cgi?resolution=";
    protected String streamPage = "/mjpg/video.mjpg";

    protected BufferedImage lastImg;
    protected int[] lastImgArr;

    public AxisCamera(String h)
    {
        host = h;
        grabPage += res;
    }

    public AxisCamera(String h, String r)
    {
        host = h;
        grabPage += r;

        lastImg = null;
        lastImgArr = null;
    }

    public AxisCamera(String h, String gp, String r, String sp)
    {
        host = h;
        grabPage = gp + r;
        streamPage = sp;

        lastImg = null;
        lastImgArr = null;
    }

    public BufferedImage grab() throws IOException
    {
        return lastImg = ImageIO.read(new URL(host + grabPage));
    }

    public int[] grabArray() throws IOException
    {
        BufferedImage img = grab();

        int[] data = new int[img.getWidth() * img.getHeight()];
        img.getRGB(0, 0, img.getWidth(), img.getHeight(), data, 0, img.getWidth());

        lastImg = img;
        lastImgArr = data;

        return data;
    }

    public InputStream openMjpgStream() throws IOException
    {
        return new URL(host + streamPage).openStream();
    }
}
Usage would be as:
Code:
AxisCamera cam = new AxisCamera("http://10.19.84.10", "320x240");
BufferedImage img = cam.grab();

Alternatively, you could try to pick frames out of the mjpg stream, but if you are going to process the data, it would be more economical of bandwidth to only request a frame when required.