Hey all,
I'm using Processing for a quick exercise and am getting to the point of tearing my hair out trying to figure out how to accomplish something. I have two computers communicating via UDP using the code from the topic "Webcam via UDP" for the computer sending video out from a Capture. The other computer is using the code at the bottom of this post to receive it. I'm using FasterMovie for the video. What I would like to do is capture a frame from the other computer via UDP, get the next frame from the video object, render the video frame, and then render the captured frame on top of it. Getting weird errors along the way, such as this:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at hypermedia.net.UDP.callReceiveHandler(UDP.java:648)
at hypermedia.net.UDP.listen(UDP.java:570)
at hypermedia.net.UDP.run(UDP.java:606)
at java.lang.Thread.run(Thread.java:613)
Caused by: java.lang.NullPointerException
at WebCamOverUDP.receive(WebCamOverUDP.java:92)
... 8 more
I get this each call to draw... Any help would be greatly appreciated!
Thanks.
Code:
import processing.video.*;
import hypermedia.net.*;
import java.io.*;
import javax.imageio.*;
FasterMovie vid;
PImage vidFrame;
Capture cam;
UDP udp;
PGraphics workspace;
PImage localFrame;
PImage remoteFrame;
int canvasWidth = 640;
int canvasHeight = 480;
int capWidth = 200;
int capHeight = 140;
boolean gettingNewImage = false;
void setup() {
size(canvasWidth, canvasHeight, JAVA2D);
background(0);
colorMode(RGB, 255);
udp = new UDP(this, 6000, "224.0.0.1");
udp.listen(true);
println("isMulticast? " + udp.isMulticast());
println("isJoined? " + udp.isJoined());
vid = new FasterMovie(this, "Group5.mov", false);
remoteFrame = new PImage(capWidth, capWidth);
workspace = createGraphics(capWidth, capHeight, JAVA2D);
}
void movieImageAvailable(PImage _video) {
vidFrame = _video;
}
synchronized void draw() {
// If we are not currently getting a new frame, we wanna show what we have.
if(!gettingNewImage && remoteFrame != null) {
image(vid, 0, 0, canvasWidth, canvasHeight);
image(remoteFrame, 150, 150);
}
}
synchronized void receive( byte[] data ) {
println("Got datagram with " + data.length + " bytes of data" );
// Read incoming data into a ByteArrayInputStream
ByteArrayInputStream bais = new ByteArrayInputStream( data );
InputStreamReader r = new InputStreamReader(bais);
gettingNewImage = true;
// Load up pixel array for remoteFrame
remoteFrame.loadPixels();
try {
// Try to build a BufferedImage based on the incoming data (This takes care of makeing JPEG data -> pixel data)
BufferedImage img = ImageIO.read(bais);
// Move pixel data into the remoteFrame
img.getRGB(0, 0, capWidth, capHeight, remoteFrame.pixels, 0, capWidth);
} catch (IOException ioe) {
println("Read Exception: " + ioe.getMessage());
}
// Update the remoteFrame with new info
remoteFrame.updatePixels();
gettingNewImage = false;
}