Commit c8ad7d8c authored by Jeremy Laviole's avatar Jeremy Laviole

update to 0.1.2c

parent e7438c65
......@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>tech.lity.rea</groupId>
<artifactId>natar-multi-camera-server</artifactId>
<version>0.1.2b</version>
<version>0.1.2c</version>
<packaging>jar</packaging>
<properties>
......@@ -67,7 +67,7 @@
<dependency>
<groupId>tech.lity.rea</groupId>
<artifactId>natar-core</artifactId>
<version>0.1.2a-SNAPSHOT</version>
<version>0.1.2c</version>
</dependency>
<dependency>
......
......@@ -19,13 +19,6 @@
*/
package tech.lity.rea.nectar.camera;
import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.codec.ByteArrayCodec;
import io.lettuce.core.codec.RedisCodec;
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bytedeco.javacv.FrameGrabber;
......@@ -183,6 +176,13 @@ public class CameraOpenNI2 extends CameraRGBIRDepth {
// return;
// }
// ((WithTouchInput) depthCamera).newTouchImage();
try {
Thread.sleep((long) 30);
} catch (InterruptedException ex) {
Logger.getLogger(CameraOpenNI2.class.getName()).log(Level.SEVERE, null, ex);
}
}
// WARNING, in thread it does not wait for a new image ?
......@@ -190,8 +190,8 @@ public class CameraOpenNI2 extends CameraRGBIRDepth {
public void grabColor() {
try {
// System.out.println("Sleeping color cam");
Thread.sleep((long) ((1.0f / (float) colorCamera.frameRate) * 1000f));
// Thread.sleep((long) ((1.0f / (float) colorCamera.frameRate) * 5000f));
// Thread.sleep((long) ((1.0f / (float) colorCamera.frameRate) * 100f));
Thread.sleep((long) 30);
// System.out.println("awake color cam");
} catch (InterruptedException ex) {
Logger.getLogger(CameraOpenNI2.class.getName()).log(Level.SEVERE, null, ex);
......@@ -312,76 +312,27 @@ public class CameraOpenNI2 extends CameraRGBIRDepth {
gray16Buffer.rewind();
}
CameraServer server;
Jedis redis;
// RedisConnection redis;
StatefulRedisConnection<byte[], byte[]> getSet;
StatefulRedisPubSubConnection<byte[], byte[]> pubsub;
RedisCommands<byte[], byte[]> getSetSync;
RedisPubSubCommands<byte[], byte[]> pubsubSync;
RedisClient client;
public void sendToRedis(CameraServer camServer, String host, int port) {
server = camServer;
VideoEmitter colorVideoEmitter;
VideoEmitter depthVideoEmitter;
int time = 0;
public void sendToRedis(RedisClient client, String keyColor, String keyDepth) {
this.client = client;
colorVideoEmitter = new VideoEmitter(client, keyColor);
depthVideoEmitter = new VideoEmitter(client, keyDepth);
// this.redis = redis;
// client = RedisClient.create("redis://localhost");
client = RedisClient.create("redis://" + host + ":" + Integer.toString(port));
// StatefulRedisConnection<String, String> connection = client.connect();
// RedisStringCommands sync = connection.sync();
// String value = (String) sync.get("key");
ByteArrayCodec codec = io.lettuce.core.codec.ByteArrayCodec.INSTANCE;
getSet = client.connect(codec);
getSetSync = getSet.sync();
pubsub = client.connectPubSub(codec);
pubsubSync = pubsub.sync();
}
protected void sendColor(byte[] imageData) {
colorImageCount++;
byte[] id = server.getOutput().getBytes();
JSONObject imageInfo = new JSONObject();
imageInfo.setLong("timestamp", server.time());
imageInfo.setLong("imageCount", colorImageCount);
try {
getSetSync.set(id, imageData);
pubsubSync.publish(id, imageInfo.toString().getBytes());
// redis.set(id, imageData);
// redis.publish(id, imageInfo.toString().getBytes());
} catch (Exception e) {
System.out.println("Sending: " + server.getOutput() + " : " + imageInfo.toString());
System.out.println("Exception: " + e);
e.printStackTrace();
redis = server.createRedisConnection();
}
colorVideoEmitter.sendRawImage(imageData, time++);
}
protected void sendDepth(byte[] imageData) {
depthImageCount++;
String name = server.getOutput() + ":depth:raw";
byte[] id = (name).getBytes();
JSONObject imageInfo = new JSONObject();
imageInfo.setLong("timestamp", server.time());
imageInfo.setLong("imageCount", depthImageCount);
try {
getSetSync.set(id, imageData);
pubsubSync.publish(id, imageInfo.toString().getBytes());
// redis.set(id, imageData);
// redis.publish(id, imageInfo.toString().getBytes());
} catch (Exception e) {
System.out.println("Exception: " + e);
e.printStackTrace();
redis = server.createRedisConnection();
}
depthVideoEmitter.sendRawImage(imageData, time++);
}
class FrameListener implements VideoStream.NewFrameListener {
......@@ -436,7 +387,7 @@ public class CameraOpenNI2 extends CameraRGBIRDepth {
frameData.get(frameDataBytes);
// Juste forward the bytes if on server...
if (server != null) {
if (colorVideoEmitter != null) {
sendColor(frameDataBytes);
return;
}
......@@ -462,7 +413,7 @@ public class CameraOpenNI2 extends CameraRGBIRDepth {
byte[] frameDataBytes = new byte[frameSize];
frameData.get(frameDataBytes);
if (server != null) {
if (depthVideoEmitter != null) {
sendDepth(frameDataBytes);
return;
}
......
......@@ -2,6 +2,8 @@ package tech.lity.rea.nectar.camera;
import processing.core.*;
import java.nio.ByteBuffer;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -9,18 +11,18 @@ import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.ParseException;
import redis.clients.jedis.Jedis;
import processing.data.JSONObject;
import tech.lity.rea.nectar.utils.NectarApplication;
import static tech.lity.rea.nectar.utils.NectarApplication.log;
/**
*
* @author Jeremy Laviole, <laviole@rea.lity.tech>
*/
public class CameraServerImpl extends NectarApplication implements CameraServer, Runnable {
public class CameraServerImpl extends NectarApplication implements Runnable {
Jedis redis, redisDepth, redisSend;
Camera camera;
......@@ -51,15 +53,25 @@ public class CameraServerImpl extends NectarApplication implements CameraServer,
redis = connectRedis();
redisDepth = connectRedis();
RedisClientImpl redisClient = new RedisClientImpl();
redisClient.setRedisHost(host);
redisClient.setRedisPort(Integer.parseInt(port));
redisClient.setRedisAuth("");
try {
// application only using a camera
// screen rendering
// camera = CameraFactory.createCamera(Camera.Type.OPENCV, "0", "");
camera = CameraFactory.createCamera(type, description, format);
camera.setSize(width, height);
System.out.println("Start camera");
boolean simpleCam = true;
if (useDepth) {
if (camera instanceof CameraRGBIRDepth) {
System.out.println("Start OpenNI depth camera");
dcamera = (CameraRGBIRDepth) camera;
dcamera.setUseColor(true);
dcamera.setUseDepth(true);
......@@ -69,8 +81,11 @@ public class CameraServerImpl extends NectarApplication implements CameraServer,
dcamera.getDepthCamera().height(),
2, 1);
// dcamera.getColorCamera().addObserver(new ImageObserver());
// dcamera.getDepthCamera().addObserver(new DepthImageObserver());
dcamera.actAsColorCamera();
simpleCam = false;
} else {
die("Camera not recognized as a depth camera.");
}
......@@ -78,9 +93,13 @@ public class CameraServerImpl extends NectarApplication implements CameraServer,
if (camera instanceof CameraOpenNI2) {
CameraOpenNI2 cameraNI = (CameraOpenNI2) camera;
cameraNI.sendToRedis(this, host, Integer.parseInt(port));
cameraNI.sendToRedis(redisClient, output, output + ":depth");
}
// if (simpleCam) {
// camera.addObserver(new ImageObserver());
// }
camera.start();
sendParams(camera);
initMemory(width, height, 3, 1);
......@@ -94,12 +113,10 @@ public class CameraServerImpl extends NectarApplication implements CameraServer,
}
@Override
public Jedis createRedisConnection(){
public Jedis createRedisConnection() {
return connectRedis();
}
private static Options options;
private String buildDriverNames() {
......@@ -171,15 +188,6 @@ public class CameraServerImpl extends NectarApplication implements CameraServer,
}
}
public static void die(String why, boolean usage) {
if (usage) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("CameraServer", options);
}
System.out.println(why);
System.exit(-1);
}
private void sendParams(Camera cam) {
redis.set(output + ":width", Integer.toString(cam.width()));
......@@ -217,36 +225,51 @@ public class CameraServerImpl extends NectarApplication implements CameraServer,
}
int lastTime = 0;
//
// class ImageObserver implements Observer {
//
// @Override
// public void update(Observable o, Object o1) {
// sendColorImage();
// }
// }
//
// class DepthImageObserver implements Observer {
//
// @Override
// public void update(Observable o, Object o1) {
// log("", "New Depth Image.");
// sendDepthImage();
// }
// }
public void sendImage() {
if (camera != null) {
// OpenNI2 camera is not grabbed here
// // OpenNI2 camera is not grabbed here
if (camera instanceof CameraOpenNI2) {
try {
Thread.sleep(1000);
Thread.sleep(100);
return;
} catch (InterruptedException ex) {
Logger.getLogger(CameraServerImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
} else {
// warning, some cameras do not grab ?
camera.grab();
// warning, some cameras do not grab ?
camera.grab();
sendColorImage();
if (useDepth) {
sendDepthImage();
sendColorImage();
if (useDepth) {
sendDepthImage();
}
}
}
}
private void sendColorImage() {
ByteBuffer byteBuffer;
// byteBuffer = dcamera.getColorCamera().getIplImage();
// IplImage smaller = dcamera.getColorCamera().getIplImage().sc
if (useDepth) {
if (dcamera.getColorCamera().getIplImage() == null) {
log("null color Image -d", "");
......@@ -339,6 +362,7 @@ public class CameraServerImpl extends NectarApplication implements CameraServer,
static public void main(String[] passedArgs) {
CameraServerImpl cameraServer = new CameraServerImpl(passedArgs);
System.out.println("Start in main Thread...");
new Thread(cameraServer).start();
}
......@@ -346,5 +370,4 @@ public class CameraServerImpl extends NectarApplication implements CameraServer,
return this.output;
}
}
......@@ -25,6 +25,7 @@ import processing.core.PMatrix3D;
import processing.core.PVector;
import tech.lity.rea.nectar.camera.Camera;
import tech.lity.rea.nectar.camera.CameraRGBIRDepth;
import tech.lity.rea.nectar.camera.LockedUpdater;
import tech.lity.rea.nectar.camera.SubCamera;
import tech.lity.rea.nectar.camera.SubDepthCamera;
import toxi.geom.Vec3D;
......@@ -97,8 +98,8 @@ public abstract class DepthCameraDevice {
camera.close();
}
public void setTouch(Object kinectTouchInput) {
camera.getDepthCamera().setTouchInput(kinectTouchInput);
public void setTouch(LockedUpdater touchInput) {
camera.getDepthCamera().setTouchInput(touchInput);
}
// public void setStereoCalibration(String fileName) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment