git-svn-id: https://robotics.mvla.net/svn/frc971/2013/trunk/src@4141 f308d9b7-e957-4cde-b6ac-9a88185e7312
diff --git a/971CV/src/org/frc971/HTTPClient.java b/971CV/src/org/frc971/HTTPClient.java
index c6f1b9e..9813595 100644
--- a/971CV/src/org/frc971/HTTPClient.java
+++ b/971CV/src/org/frc971/HTTPClient.java
@@ -11,7 +11,6 @@
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import aos.ChannelImageGetter;
-import aos.JPEGDecoder;
import java.nio.channels.SocketChannel;
import java.nio.ByteBuffer;
@@ -24,7 +23,6 @@
private SocketChannel sock = SocketChannel.open();
private Socket core_sock = sock.socket();
- private String LastBoundary = "";
private BufferedReader sock_in;
private PrintWriter sock_out;
@@ -103,67 +101,25 @@
}
public ImageWithTimestamp GetFrame() {
- /*//read all current data from socket, in case of processing bottleneck
- WriteDebug("Emptying TCP stack...");
- String message = ReadtoBoundary(null);
- //we must end with a boundary
- int len = message.length();
- if (message.substring(len - 4, len - 1) != "\r\n\r\n") {
- WriteDebug("Boundary was not found. Waiting for boundary...");
- message += ReadtoBoundary("\r\n\r\n");
- }
- //Add the last boundary we cut off to the beginning of our message
- message = LastBoundary + message;
- //Divide our large message into string separated by boundary beginnings
- String[] cut = message.split("\r\n--");
- len = cut.length;
- //Save the newest boundary, so we can use it later.
- LastBoundary = cut[len - 1];
- //Keep only our penultimate boundary and the image after it
- //NOTE that message is missing its preceding \r\n--
- message = cut[len - 2];
- cut = message.split("\r\n\r\n");
- //NOTE that boundary is now missing its trailing \r\n\r\n
- String boundary = cut[0];
- String JPEGImage = cut[1];
- //extract timestamp in seconds
- cut = boundary.split("X-Timestamp: ");
- String time_data = cut[1];
- boundary = cut[0];
- float timestamp = Float.parseFloat(time_data);
- //extract size so we can make sure our image data is not corrupted
- cut = boundary.split("Content-Length: ");
- String size_data = cut[1];
- float size = Float.parseFloat(size_data);
- assert (size == JPEGImage.length()) : ("Fatal mismatch between actual and expected image size. Check regular expressions.");
- byte[] ImageArray = JPEGImage.getBytes();
- InputStream in = new ByteArrayInputStream(ImageArray);
- try {
- BufferedImage bImageFromConvert = ImageIO.read(in);
- ImageWithTimestamp to_return = new ImageWithTimestamp();
- to_return.image = IplImage.createFrom(bImageFromConvert);
- to_return.timestamp = timestamp;
- WriteDebug("Image processing successful.");
- return to_return;
- }
- catch (IOException e) {
- System.err.println(e.getMessage());
- return null;
- }
- */
//Use Brian's code to extract an image and timestamp from raw server data.
ImageWithTimestamp final_image = new ImageWithTimestamp();
try {
ChannelImageGetter cgetter = new ChannelImageGetter(sock);
ByteBuffer binary_image = cgetter.getJPEG();
- JPEGDecoder decoder = new JPEGDecoder();
- boolean sorf = decoder.decode(binary_image, final_image.image);
- if (!sorf) {
- WriteDebug("Error: JPEG decode failed.");
+ //Decode ByteBuffer into an IplImage
+ InputStream in = new ByteArrayInputStream(binary_image.array());
+ try {
+ BufferedImage bImageFromConvert = ImageIO.read(in);
+ final_image.image = IplImage.createFrom(bImageFromConvert);
+ final_image.timestamp = cgetter.getTimestamp();
+ WriteDebug("Image processing successful.");
+ return final_image;
+ }
+ catch (IOException e) {
+ System.err.println(e.getMessage());
return null;
}
- final_image.timestamp = cgetter.getTimestamp();
- return final_image;
+
}
catch (IOException e) {
WriteDebug("Error: Failed to initialize ChannelImageGetter.");