Commit b7774160 authored by Jeremy Laviole's avatar Jeremy Laviole

extends natarApplication

parent 694a2677
/usr/share/java/commons-cli-1.4.jar:/usr/share/java/javacv-platform-1.4.jar:/usr/share/java/netty-resolver-4.1.31.Final.jar:/usr/share/java/flycapture-platform-2.11.3.121.jar:/usr/share/java/artoolkitplus-platform-2.3.1.jar:/usr/share/java/netty-transport-4.1.31.Final.jar:/usr/share/java/nectar-core-0.1.jar:/usr/share/java/libfreenect2-platform-0.2.0.jar:/usr/share/java/core-3.3.7.jar:/usr/share/java/jna-4.0.0.jar:/usr/share/java/gstreamer-java-1.5.jar:/usr/share/java/opencv-platform-3.4.0.jar:/usr/share/java/librealsense-platform-1.12.1.jar:/usr/share/java/jedis-2.9.0.jar:/usr/share/java/x86_64-3.3.0.jar:/usr/share/java/flandmark-platform-1.07.jar:/usr/share/java/reactive-streams-1.0.2.jar:/usr/share/java/reactor-core-3.2.3.RELEASE.jar:/usr/share/java/netty-codec-4.1.31.Final.jar:/usr/share/java/toxiclibscore-0022.jar:/usr/share/java/AppleJavaExtensions-1.4.jar:/usr/share/java/commons-pool2-2.4.2.jar:/usr/share/java/videoinput-platform-0.200.jar:/usr/share/java/javacv-processing-0.1.jar:/usr/share/java/video-2.0.jar:/usr/share/java/SVGExtended-3.3.7.3.jar:/usr/share/java/ffmpeg-platform-3.4.1.jar:/usr/share/java/libdc1394-platform-2.2.5.jar:/usr/share/java/netty-buffer-4.1.31.Final.jar:/usr/share/java/netty-common-4.1.31.Final.jar:/usr/share/java/OpenNI-2.3.1.jar:/usr/share/java/http-request-6.0.jar:/usr/share/java/netty-handler-4.1.31.Final.jar:/usr/share/java/libfreenect-platform-0.5.3.jar:/usr/share/java/javacpp-1.4.jar:/usr/share/java/platform-3.4.0.jar:/usr/share/java/lettuce-core-5.1.3.RELEASE.jar
\ No newline at end of file
......@@ -64,9 +64,10 @@
<scope>compile</scope>
</dependency>
<!--It should use nectar-apps-->
<dependency>
<groupId>tech.lity.rea</groupId>
<artifactId>nectar-core</artifactId>
<artifactId>nectar-apps</artifactId>
<version>0.1</version>
</dependency>
......
......@@ -356,7 +356,7 @@ public class CameraOpenNI2 extends CameraRGBIRDepth {
System.out.println("Sending: " + server.getOutput() + " : " + imageInfo.toString());
System.out.println("Exception: " + e);
e.printStackTrace();
redis = server.connectRedis();
redis = server.createRedisConnection();
}
}
......@@ -379,7 +379,7 @@ public class CameraOpenNI2 extends CameraRGBIRDepth {
} catch (Exception e) {
System.out.println("Exception: " + e);
e.printStackTrace();
redis = server.connectRedis();
redis = server.createRedisConnection();
}
}
......
......@@ -6,9 +6,9 @@ import redis.clients.jedis.Jedis;
*
* @author Jeremy Laviole, <laviole@rea.lity.tech>
*/
public abstract class CameraServer extends Thread{
public abstract interface CameraServer {
abstract public Jedis connectRedis();
abstract public Jedis createRedisConnection();
abstract public void sendImage();
abstract public String getOutput();
abstract public long time();
......
......@@ -14,39 +14,31 @@ import org.apache.commons.cli.ParseException;
import redis.clients.jedis.Jedis;
import processing.data.JSONObject;
import tech.lity.rea.nectar.apps.NectarApplication;
/**
*
* @author Jeremy Laviole, <laviole@rea.lity.tech>
*/
public class CameraServerImpl extends CameraServer {
public class CameraServerImpl extends NectarApplication implements CameraServer, Runnable {
Jedis redis, redisSend;
Camera camera;
// Arguments
public static final int REDIS_PORT = 6379;
public static final String REDIS_HOST = "localhost";
private long millisOffset = System.currentTimeMillis();
private String driverName = "";
private String description = "0";
private String format = "";
private int width = 640, height = 480;
private String markerFileName = "";
private String input = "marker";
private String output = "pose";
private String host = REDIS_HOST;
private int port = REDIS_PORT;
private boolean isUnique = false;
private boolean isStreamSet = false;
private boolean isStreamPublish = true;
private Camera.Type type;
boolean running = true;
boolean isVerbose = false;
boolean isSilent = false;
private boolean useDepth = false;
private long colorImageCount = 0;
......@@ -99,11 +91,14 @@ public class CameraServerImpl extends CameraServer {
die(ex.toString());
}
// papart.startTracking();
// papart.startTracking();
}
@Override
public Jedis createRedisConnection(){
return connectRedis();
}
private Options options;
private String buildDriverNames() {
......@@ -118,29 +113,27 @@ public class CameraServerImpl extends CameraServer {
return driversText.toString();
}
private void checkArguments(String[] passedArgs) {
options = new Options();
// public static Camera createCamera(Camera.Type type, String description, String format)
private void addCLIArgs(Options options) {
// options.addRequiredOption("i", "input", true, "Input key of marker locations.");
options.addRequiredOption("d", "driver", true, "Driver to use amongst: " + buildDriverNames());
options.addRequiredOption("id", "device-id", true, "Device id, path or name (driver dependant).");
options.addOption("f", "format", true, "Format, e.g.: for depth cameras rgb, ir, depth.");
options.addOption("r", "resolution", true, "Image size, can be used instead of width and height, default 640x480.");
// Generic options
// Generic options
options.addOption("s", "stream", false, " stream mode (PUBLISH).");
options.addOption("sg", "stream-set", false, " stream mode (SET).");
options.addOption("u", "unique", false, "Unique mode, run only once and use get/set instead of pub/sub");
options.addOption("dc", "depth-camera", false, "Load the depth video when available.");
options.addOption("h", "help", false, "print this help.");
options.addOption("v", "verbose", false, "Verbose activated.");
options.addOption("si", "silent", false, "Silent activated.");
options.addOption("u", "unique", false, "Unique mode, run only once and use get/set instead of pub/sub");
options.addRequiredOption("o", "output", true, "Output key.");
options.addOption("rp", "redisport", true, "Redis port, default is: " + REDIS_PORT);
options.addOption("rh", "redishost", true, "Redis host, default is: " + REDIS_HOST);
}
private void checkArguments(String[] passedArgs) {
options = new Options();
addCLIArgs(options);
addDefaultOptions(options);
CommandLineParser parser = new DefaultParser();
CommandLine cmd;
......@@ -149,6 +142,8 @@ public class CameraServerImpl extends CameraServer {
try {
cmd = parser.parse(options, passedArgs);
parseDefaultOptions(cmd);
driverName = cmd.getOptionValue("d");
type = Camera.Type.valueOf(driverName);
description = cmd.getOptionValue("id");
......@@ -162,21 +157,12 @@ public class CameraServerImpl extends CameraServer {
height = Integer.parseInt(split[1]);
}
if (cmd.hasOption("h")) {
die("", true);
}
if (cmd.hasOption("sg")) {
isStreamSet = true;
isStreamPublish = false;
}
useDepth = cmd.hasOption("dc");
isUnique = cmd.hasOption("u");
isVerbose = cmd.hasOption("v");
isSilent = cmd.hasOption("si");
host = cmd.hasOption("rh") ? cmd.getOptionValue("rh") : host;
port = cmd.hasOption("rp") ? Integer.parseInt(cmd.getOptionValue("rp")) : port;
} catch (ParseException ex) {
die(ex.toString(), true);
......@@ -185,21 +171,6 @@ public class CameraServerImpl extends CameraServer {
}
public Jedis connectRedis() {
try {
redis = new Jedis(host, port);
if (redis == null) {
throw new Exception("Cannot connect to server. ");
}
return redis;
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
return null;
// redis.auth("156;2Asatu:AUI?S2T51235AUEAIU");
}
private void sendParams(Camera cam) {
redis.set(output + ":width", Integer.toString(cam.width()));
redis.set(output + ":height", Integer.toString(cam.height()));
......@@ -240,7 +211,7 @@ public class CameraServerImpl extends CameraServer {
if (camera != null) {
// OpenNI2 camera is not grabbed here
if(camera instanceof CameraOpenNI2){
if (camera instanceof CameraOpenNI2) {
try {
Thread.sleep(1000);
return;
......@@ -248,7 +219,7 @@ public class CameraServerImpl extends CameraServer {
Logger.getLogger(CameraServerImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
// warning, some cameras do not grab ?
camera.grab();
sendColorImage();
......@@ -346,31 +317,6 @@ public class CameraServerImpl extends CameraServer {
return System.currentTimeMillis() - millisOffset;
}
public void die(String why) {
die(why, false);
}
public void die(String why, boolean usage) {
if (usage) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("CameraServer", options);
}
System.out.println(why);
System.exit(-1);
}
public void log(String normal, String verbose) {
if (isSilent) {
return;
}
if (normal != null) {
System.out.println(normal);
}
if (isVerbose && verbose != null) {
System.out.println(verbose);
}
}
/**
* @param passedArgs the command line arguments
*/
......@@ -384,4 +330,5 @@ public class CameraServerImpl extends CameraServer {
return this.output;
}
}
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