First commit.
This commit is contained in:
BIN
core/assets/badlogic.jpg
Normal file
BIN
core/assets/badlogic.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 67 KiB |
BIN
core/assets/monkey.g3db
Normal file
BIN
core/assets/monkey.g3db
Normal file
Binary file not shown.
11
core/build.gradle
Normal file
11
core/build.gradle
Normal file
@@ -0,0 +1,11 @@
|
||||
apply plugin: "java"
|
||||
|
||||
sourceCompatibility = 1.6
|
||||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
||||
|
||||
sourceSets.main.java.srcDirs = [ "src/" ]
|
||||
|
||||
|
||||
eclipse.project {
|
||||
name = appName + "-core"
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package ve.ucv.ciens.icaro.ardemo;
|
||||
|
||||
import com.badlogic.gdx.graphics.PerspectiveCamera;
|
||||
import com.badlogic.gdx.math.Matrix4;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
|
||||
public class CustomPerspectiveCamera extends PerspectiveCamera{
|
||||
private final Vector3 tmp = new Vector3();
|
||||
|
||||
public CustomPerspectiveCamera(float fieldOfView, float viewportWidth, float viewportHeight){
|
||||
super(fieldOfView, viewportWidth, viewportHeight);
|
||||
update();
|
||||
}
|
||||
|
||||
public void update(Matrix4 customProjection){
|
||||
this.update(customProjection, true);
|
||||
}
|
||||
|
||||
public void update(Matrix4 customProjection, boolean updateFrustum){
|
||||
projection.set(customProjection);
|
||||
view.setToLookAt(position, tmp.set(position).add(direction), up);
|
||||
combined.set(projection).mul(view);
|
||||
|
||||
if(updateFrustum){
|
||||
invProjectionView.set(combined).inv();
|
||||
frustum.update(invProjectionView);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCustomARProjectionMatrix(final float focalPointX, final float focalPointY, final float cameraCenterX, final float cameraCenterY, final float near, final float far, final float w, final float h){
|
||||
final float FAR_PLUS_NEAR = far + near;
|
||||
final float FAR_LESS_NEAR = far - near;
|
||||
|
||||
projection.val[Matrix4.M00] = -2.0f * focalPointX / w;
|
||||
projection.val[Matrix4.M10] = 0.0f;
|
||||
projection.val[Matrix4.M20] = 0.0f;
|
||||
projection.val[Matrix4.M30] = 0.0f;
|
||||
|
||||
projection.val[Matrix4.M01] = 0.0f;
|
||||
projection.val[Matrix4.M11] = 2.0f * focalPointY / h;
|
||||
projection.val[Matrix4.M21] = 0.0f;
|
||||
projection.val[Matrix4.M31] = 0.0f;
|
||||
|
||||
projection.val[Matrix4.M02] = 2.0f * cameraCenterX / w - 1.0f;
|
||||
projection.val[Matrix4.M12] = 2.0f * cameraCenterY / h - 1.0f;
|
||||
projection.val[Matrix4.M22] = -FAR_PLUS_NEAR / FAR_LESS_NEAR;
|
||||
projection.val[Matrix4.M32] = -1.0f;
|
||||
|
||||
projection.val[Matrix4.M03] = 0.0f;
|
||||
projection.val[Matrix4.M13] = 0.0f;
|
||||
projection.val[Matrix4.M23] = -2.0f * far * near / FAR_LESS_NEAR;
|
||||
projection.val[Matrix4.M33] = 0.0f;
|
||||
}
|
||||
}
|
||||
102
core/src/ve/ucv/ciens/icaro/ardemo/EviDemo.java
Normal file
102
core/src/ve/ucv/ciens/icaro/ardemo/EviDemo.java
Normal file
@@ -0,0 +1,102 @@
|
||||
package ve.ucv.ciens.icaro.ardemo;
|
||||
|
||||
import ve.ucv.ciens.icaro.ardemo.ImageProcessor.CalibrationData;
|
||||
import ve.ucv.ciens.icaro.ardemo.ImageProcessor.MarkerData;
|
||||
|
||||
import com.badlogic.gdx.ApplicationAdapter;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
|
||||
public class EviDemo extends ApplicationAdapter {
|
||||
private static final String TAG = "NXTAR_ANDROID_MAIN";
|
||||
private static final String CLASS_NAME = EviDemo.class.getSimpleName();
|
||||
|
||||
private ImageProcessor cvProc;
|
||||
private Texture tex;
|
||||
private Pixmap frame;
|
||||
private SpriteBatch batch;
|
||||
private MarkerData data;
|
||||
private CalibrationData calib;
|
||||
|
||||
private float[][] calibrationSamples;
|
||||
private int lastSampleTaken;
|
||||
|
||||
public EviDemo(ImageProcessor proc) {
|
||||
super();
|
||||
tex = null;
|
||||
cvProc = proc;
|
||||
frame = null;
|
||||
|
||||
lastSampleTaken = 0;
|
||||
|
||||
calibrationSamples = new float[ProjectConstants.CALIBRATION_SAMPLES][];
|
||||
for(int i = 0; i < calibrationSamples.length; i++){
|
||||
calibrationSamples[i] = new float[ProjectConstants.CALIBRATION_PATTERN_POINTS * 2];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create () {
|
||||
batch = new SpriteBatch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render () {
|
||||
Gdx.gl.glClearColor(1, 0, 0, 1);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
if(cvProc.isCameraCalibrated()) {
|
||||
data = cvProc.findMarkersInFrame();
|
||||
if(data != null) {
|
||||
frame = new Pixmap(data.outFrame, 0, data.outFrame.length);
|
||||
tex = new Texture(frame);
|
||||
|
||||
batch.begin();
|
||||
batch.draw(tex, 0, 0);
|
||||
batch.end();
|
||||
|
||||
frame.dispose();
|
||||
tex.dispose();
|
||||
}
|
||||
} else {
|
||||
calib = cvProc.findCalibrationPattern();
|
||||
|
||||
if(calib != null){
|
||||
|
||||
if(!cvProc.isCameraCalibrated() && calib.calibrationPoints != null){
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".render(): Sample taken.");
|
||||
|
||||
// Save the calibration points to the samples array.
|
||||
for(int i = 0; i < calib.calibrationPoints.length; i += 2){
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".render(): Value " + Integer.toString(i) + " = (" + Float.toString(calib.calibrationPoints[i]) + ", " + Float.toString(calib.calibrationPoints[i + 1]) + ")");
|
||||
calibrationSamples[lastSampleTaken][i] = calib.calibrationPoints[i];
|
||||
calibrationSamples[lastSampleTaken][i + 1] = calib.calibrationPoints[i + 1];
|
||||
}
|
||||
|
||||
// Move to the next sample.
|
||||
lastSampleTaken++;
|
||||
|
||||
// If enough samples has been taken then calibrate the camera.
|
||||
if(lastSampleTaken == ProjectConstants.CALIBRATION_SAMPLES){
|
||||
Gdx.app.log(TAG, CLASS_NAME + "render(): Last sample taken.");
|
||||
|
||||
cvProc.calibrateCamera(calibrationSamples);
|
||||
}
|
||||
}
|
||||
|
||||
frame = new Pixmap(calib.outFrame, 0, calib.outFrame.length);
|
||||
tex = new Texture(frame);
|
||||
|
||||
batch.begin();
|
||||
batch.draw(tex, 0, 0);
|
||||
batch.end();
|
||||
|
||||
frame.dispose();
|
||||
tex.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
core/src/ve/ucv/ciens/icaro/ardemo/ImageProcessor.java
Normal file
60
core/src/ve/ucv/ciens/icaro/ardemo/ImageProcessor.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package ve.ucv.ciens.icaro.ardemo;
|
||||
|
||||
import com.badlogic.gdx.math.Matrix3;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
|
||||
public interface ImageProcessor {
|
||||
public class MarkerData{
|
||||
public byte[] outFrame;
|
||||
public int[] markerCodes;
|
||||
public Vector3[] translationVectors;
|
||||
public Matrix3[] rotationMatrices;
|
||||
}
|
||||
|
||||
public class CalibrationData{
|
||||
public byte[] outFrame;
|
||||
public float[] calibrationPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Finds up to {@link ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS} markers in the input
|
||||
* image and returns their codes and pose estimation in the CVMarkerData structure. The
|
||||
* markers are higlihted in the input image.</p>
|
||||
*
|
||||
* @param frame The JPEG encoded input image.
|
||||
* @return A data structure containing the processed output image, the
|
||||
* detected marker codes and their respective locations.
|
||||
*/
|
||||
public MarkerData findMarkersInFrame();
|
||||
|
||||
/**
|
||||
* <p>Attempts to detect a checkerboard calibration pattern in the input image.
|
||||
* If the pattenr is found the method returns an image with the pattern
|
||||
* highlighted and the spatial location of the calibration points in the
|
||||
* output data structure.</p>
|
||||
*
|
||||
* @param frame The JPEG encoded input image.
|
||||
* @return A data structure containing the processed output image and the
|
||||
* location of the calibration points. If the pattern was not found, the returnd
|
||||
* calibration points array is null.
|
||||
*/
|
||||
public CalibrationData findCalibrationPattern();
|
||||
|
||||
/**
|
||||
* <p>Obtains the intrinsic camera parameters necesary for calibration.</p>
|
||||
*/
|
||||
public boolean calibrateCamera(float[][] calibrationSamples);
|
||||
|
||||
/**
|
||||
* <p>Indicates if OpenCV has been sucessfully initialized and used
|
||||
* to obtain the camera parameters for calibration.</p>
|
||||
*
|
||||
* @return True if and only if OpenCV initialized succesfully and calibrateCamera has been called previously.
|
||||
*/
|
||||
public boolean isCameraCalibrated();
|
||||
|
||||
public float getFocalPointX();
|
||||
public float getFocalPointY();
|
||||
public float getCameraCenterX();
|
||||
public float getCameraCenterY();
|
||||
}
|
||||
24
core/src/ve/ucv/ciens/icaro/ardemo/ProjectConstants.java
Normal file
24
core/src/ve/ucv/ciens/icaro/ardemo/ProjectConstants.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package ve.ucv.ciens.icaro.ardemo;
|
||||
|
||||
public abstract class ProjectConstants{
|
||||
public static final int SERVICE_DISCOVERY_PORT = 9988;
|
||||
public static final int VIDEO_STREAMING_PORT = 9989;
|
||||
public static final int MOTOR_CONTROL_PORT = 9990;
|
||||
public static final int SENSOR_REPORT_PORT = 9991;
|
||||
public static final int APP_CONTROL_PORT = 9992;
|
||||
public static final String MULTICAST_ADDRESS = "230.0.0.1";
|
||||
|
||||
public static final int EXIT_SUCCESS = 0;
|
||||
public static final int EXIT_FAILURE = 1;
|
||||
|
||||
public static final boolean DEBUG = false;
|
||||
|
||||
public static final int[] POWERS_OF_2 = {64, 128, 256, 512, 1024, 2048};
|
||||
public static final float MAX_ABS_ROLL = 60.0f;
|
||||
|
||||
public static final String FONT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890:,";
|
||||
|
||||
public static final int MAXIMUM_NUMBER_OF_MARKERS = 5;
|
||||
public static final int CALIBRATION_PATTERN_POINTS = 54;
|
||||
public static final int CALIBRATION_SAMPLES = 10;
|
||||
}
|
||||
Reference in New Issue
Block a user