Added marker pose estimation. Not tested yet.
This commit is contained in:
@@ -21,6 +21,9 @@
|
||||
#include "marker.hpp"
|
||||
|
||||
//#define LOG_ENABLED
|
||||
#define MAX_MARKERS 5
|
||||
#define TRANSLATION_VECTOR_POINTS 3
|
||||
#define ROTATION_MATRIX_SIZE 9
|
||||
#define POINTS_PER_CALIBRATION_SAMPLE 54
|
||||
#define CALIBRATION_SAMPLES 10
|
||||
|
||||
@@ -37,17 +40,21 @@ extern "C"{
|
||||
/**
|
||||
* JNI wrapper around the nxtar::getAllMarkers() method.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_ve_ucv_ciens_ccg_nxtar_MainActivity_getMarkerCodesAndLocations(JNIEnv* env, jobject jobj, jlong addrMatIn, jlong addrMatOut, jintArray codes){
|
||||
char codeMsg[128];
|
||||
std::vector<int> vCodes;
|
||||
cv::Mat temp;
|
||||
|
||||
log(TAG, "getMarkerCodesAndLocations(): Requesting native data.");
|
||||
JNIEXPORT void JNICALL Java_ve_ucv_ciens_ccg_nxtar_MainActivity_getMarkerCodesAndLocations(JNIEnv* env, jobject jobj, jlong addrMatIn, jlong addrMatOut, jintArray codes, jlong camMat, jlong distMat, jfloatArray translations, jfloatArray rotations){
|
||||
char codeMsg[128];
|
||||
std::vector<int> vCodes;
|
||||
nxtar::markers_vector vMarkers;
|
||||
cv::Mat temp;
|
||||
|
||||
// Get the native object addresses.
|
||||
cv::Mat& myuv = *(cv::Mat*)addrMatIn;
|
||||
cv::Mat& mbgr = *(cv::Mat*)addrMatOut;
|
||||
log(TAG, "getMarkerCodesAndLocations(): Requesting native data.");
|
||||
cv::Mat& myuv = *(cv::Mat*)addrMatIn;
|
||||
cv::Mat& mbgr = *(cv::Mat*)addrMatOut;
|
||||
cv::Mat& mCam = *(cv::Mat*)camMat;
|
||||
cv::Mat& mDist = *(cv::Mat*)distMat;
|
||||
jint * _codes = env->GetIntArrayElements(codes, 0);
|
||||
jfloat * _tr = env->GetFloatArrayElements(translations, 0);
|
||||
jfloat * _rt = env->GetFloatArrayElements(rotations, 0);
|
||||
|
||||
// Convert the input image to the BGR color space.
|
||||
log(TAG, "getMarkerCodesAndLocations(): Converting color space before processing.");
|
||||
@@ -55,14 +62,32 @@ JNIEXPORT void JNICALL Java_ve_ucv_ciens_ccg_nxtar_MainActivity_getMarkerCodesAn
|
||||
|
||||
// Find all markers in the input image.
|
||||
log(TAG, "getMarkerCodesAndLocations(): Finding markers.");
|
||||
nxtar::getAllMarkers(vCodes, temp);
|
||||
nxtar::getAllMarkers(vMarkers, temp);
|
||||
nxtar::estimateMarkerPosition(vMarkers, mCam, mDist);
|
||||
|
||||
// Copy the marker codes to the output vector.
|
||||
log(TAG, "getMarkerCodesAndLocations(): Copying marker codes.");
|
||||
for(int i = 0; i < vCodes.size() && i < 15; i++){
|
||||
_codes[i] = (jint)vCodes[i];
|
||||
for(size_t i = 0; i < vMarkers.size() && i < MAX_MARKERS; i++){
|
||||
_codes[i] = (jint)vMarkers[i].code;
|
||||
}
|
||||
vCodes.clear();
|
||||
|
||||
// Copy the geometric transformations to the output vectors.
|
||||
for(int i = 0, p = 0; i < vMarkers.size(); i++, p += 3){
|
||||
_tr[p ] = vMarkers[i].translation.at<jfloat>(0);
|
||||
_tr[p + 1] = vMarkers[i].translation.at<jfloat>(1);
|
||||
_tr[p + 2] = vMarkers[i].translation.at<jfloat>(2);
|
||||
}
|
||||
|
||||
for(int k = 0; k < vMarkers.size(); k++){
|
||||
for(int row = 0; row < 3; row++){
|
||||
for(int col = 0; col < 3; col++){
|
||||
_rt[col + (row * 3) + (9 * k)] = vMarkers[k].rotation.at<jfloat>(row, col);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clear marker memory.
|
||||
vMarkers.clear();
|
||||
|
||||
// Convert the output image back to the RGB color space.
|
||||
cv::cvtColor(temp, mbgr, CV_BGR2RGB);
|
||||
@@ -70,6 +95,8 @@ JNIEXPORT void JNICALL Java_ve_ucv_ciens_ccg_nxtar_MainActivity_getMarkerCodesAn
|
||||
// Release native data.
|
||||
log(TAG, "getMarkerCodesAndLocations(): Releasing native data.");
|
||||
env->ReleaseIntArrayElements(codes, _codes, 0);
|
||||
env->ReleaseFloatArrayElements(translations, _tr, 0);
|
||||
env->ReleaseFloatArrayElements(rotations, _rt, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,14 +104,13 @@ JNIEXPORT void JNICALL Java_ve_ucv_ciens_ccg_nxtar_MainActivity_getMarkerCodesAn
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_ve_ucv_ciens_ccg_nxtar_MainActivity_findCalibrationPattern(JNIEnv* env, jobject jobj, jlong addrMatIn, jlong addrMatOut, jfloatArray points){
|
||||
nxtar::points_vector v_points;
|
||||
bool found;
|
||||
cv::Mat temp;
|
||||
|
||||
log(TAG, "findCalibrationPattern(): Requesting native data.");
|
||||
bool found;
|
||||
cv::Mat temp;
|
||||
|
||||
// Get the native object addresses.
|
||||
cv::Mat& myuv = *(cv::Mat*)addrMatIn;
|
||||
cv::Mat& mbgr = *(cv::Mat*)addrMatOut;
|
||||
log(TAG, "findCalibrationPattern(): Requesting native data.");
|
||||
cv::Mat& myuv = *(cv::Mat*)addrMatIn;
|
||||
cv::Mat& mbgr = *(cv::Mat*)addrMatOut;
|
||||
jfloat * _points = env->GetFloatArrayElements(points, 0);
|
||||
|
||||
// Convert the input image to the BGR color space.
|
||||
@@ -118,13 +144,13 @@ JNIEXPORT jboolean JNICALL Java_ve_ucv_ciens_ccg_nxtar_MainActivity_findCalibrat
|
||||
* JNI wrapper around the nxtar::getCameraParameters() method.
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL Java_ve_ucv_ciens_ccg_nxtar_MainActivity_calibrateCameraParameters(JNIEnv* env, jobject jobj, jlong addrMatIn, jlong addrMatOut, jlong addrMatFrame, jfloatArray points){
|
||||
double error;
|
||||
double error;
|
||||
std::vector<nxtar::points_vector> imagePoints;
|
||||
|
||||
// Get native object addresses.
|
||||
log(TAG, "calibrateCameraParameters(): Requesting native data.");
|
||||
cv::Mat& mIn = *(cv::Mat*)addrMatIn;
|
||||
cv::Mat& mOut = *(cv::Mat*)addrMatOut;
|
||||
cv::Mat& mIn = *(cv::Mat*)addrMatIn;
|
||||
cv::Mat& mOut = *(cv::Mat*)addrMatOut;
|
||||
cv::Mat& mFrame = *(cv::Mat*)addrMatFrame;
|
||||
jfloat * _points = env->GetFloatArrayElements(points, 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user