From f7c1749379a8fd65c5c2162247689894387d8593 Mon Sep 17 00:00:00 2001 From: Ethan Rublee Date: Sat, 27 Nov 2010 08:40:10 +0000 Subject: [PATCH] Bringing the CVCamera up to speed with new changes to android-jni - added settings and centered the camera. --- android/apps/CVCamera/AndroidManifest.xml | 6 + android/apps/CVCamera/Makefile | 7 +- android/apps/CVCamera/jni/Application.mk | 2 +- android/apps/CVCamera/jni/Processor.cpp | 436 +++++++++--------- android/apps/CVCamera/jni/Processor.h | 44 +- android/apps/CVCamera/sample.local.env.mk | 2 +- .../com/theveganrobot/cvcamera/CVCamera.java | 89 ++-- 7 files changed, 292 insertions(+), 294 deletions(-) diff --git a/android/apps/CVCamera/AndroidManifest.xml b/android/apps/CVCamera/AndroidManifest.xml index 0acd4e9ec6..227f23ac36 100644 --- a/android/apps/CVCamera/AndroidManifest.xml +++ b/android/apps/CVCamera/AndroidManifest.xml @@ -12,6 +12,12 @@ + + + + diff --git a/android/apps/CVCamera/Makefile b/android/apps/CVCamera/Makefile index 89d847d277..f1861aa720 100644 --- a/android/apps/CVCamera/Makefile +++ b/android/apps/CVCamera/Makefile @@ -11,7 +11,9 @@ $(info ERROR local environement not setup! try:) $(info gedit $(LOCAL_ENV_MK)) $(error Please setup the $(LOCAL_ENV_MK) - the default was just created') endif - +ifndef ARM_TARGETS +ARM_TARGETS=armeabi armeabi-v7a +endif ANDROID_NDK_BASE = $(ANDROID_NDK_ROOT) $(info OPENCV_CONFIG = $(OPENCV_CONFIG)) @@ -46,7 +48,8 @@ SWIG_C_OUT = $(SWIG_C_DIR)/cvcamera_swig.cpp BUILD_DEFS=OPENCV_CONFIG=$(OPENCV_CONFIG) \ PROJECT_PATH=$(PROJECT_PATH) \ V=$(V) \ - $(NDK_FLAGS) + $(NDK_FLAGS) \ + ARM_TARGETS=$(ARM_TARGETS) # The real native library stripped of symbols LIB = libs/armeabi-v7a/$(LIBNAME) libs/armeabi/$(LIBNAME) diff --git a/android/apps/CVCamera/jni/Application.mk b/android/apps/CVCamera/jni/Application.mk index a2c96a8fe8..0bbce43113 100644 --- a/android/apps/CVCamera/jni/Application.mk +++ b/android/apps/CVCamera/jni/Application.mk @@ -1,2 +1,2 @@ # The ARMv7 is significanly faster due to the use of the hardware FPU -APP_ABI := armeabi armeabi-v7a \ No newline at end of file +APP_ABI := $(ARM_TARGETS) \ No newline at end of file diff --git a/android/apps/CVCamera/jni/Processor.cpp b/android/apps/CVCamera/jni/Processor.cpp index 3d5a6b15d8..eaf0e5b747 100644 --- a/android/apps/CVCamera/jni/Processor.cpp +++ b/android/apps/CVCamera/jni/Processor.cpp @@ -7,294 +7,280 @@ #include "Processor.h" - #include using namespace cv; Processor::Processor() : - stard(20/*max_size*/, 8/*response_threshold*/, - 15/*line_threshold_projected*/, - 8/*line_threshold_binarized*/, 5/*suppress_nonmax_size*/), - fastd(20/*threshold*/, true/*nonmax_suppression*/), - surfd(100./*hessian_threshold*/, 1/*octaves*/, 2/*octave_layers*/) + stard(20/*max_size*/, 8/*response_threshold*/, 15/*line_threshold_projected*/, 8/*line_threshold_binarized*/, 5/*suppress_nonmax_size*/), + fastd(20/*threshold*/, true/*nonmax_suppression*/), + surfd(100./*hessian_threshold*/, 1/*octaves*/, 2/*octave_layers*/) { } -Processor::~Processor() { - // TODO Auto-generated destructor stub +Processor::~Processor() +{ + // TODO Auto-generated destructor stub } -void Processor::detectAndDrawFeatures(int input_idx, image_pool* pool,int feature_type) { - FeatureDetector* fd = 0; +void Processor::detectAndDrawFeatures(int input_idx, image_pool* pool, int feature_type) +{ + FeatureDetector* fd = 0; - switch (feature_type) { - case DETECT_SURF: - fd = &surfd; - break; - case DETECT_FAST: - fd = &fastd; - break; - case DETECT_STAR: - fd = &stard; - break; - } + switch (feature_type) + { + case DETECT_SURF: + fd = &surfd; + break; + case DETECT_FAST: + fd = &fastd; + break; + case DETECT_STAR: + fd = &stard; + break; + } - Mat greyimage; - pool->getGrey(input_idx, greyimage); - //Mat* grayimage = pool->getYUV(input_idx); + Mat greyimage = pool->getGrey(input_idx); - Mat* img = pool->getImage(input_idx); + Mat img = pool->getImage(input_idx); - if (!img || greyimage.empty() || fd == 0) - return; //no image at input_idx! + if (img.empty() || greyimage.empty() || fd == 0) + return; //no image at input_idx! - keypoints.clear(); + keypoints.clear(); - //if(grayimage->step1() > sizeof(uchar)) return; - //cvtColor(*img,*grayimage,CV_RGB2GRAY); + //if(grayimage->step1() > sizeof(uchar)) return; + //cvtColor(*img,*grayimage,CV_RGB2GRAY); - fd->detect(greyimage, keypoints); + fd->detect(greyimage, keypoints); - for (vector::const_iterator it = keypoints.begin(); it - != keypoints.end(); ++it) { - circle(*img, it->pt, 3, cvScalar(255, 0, 255, 0)); - } + for (vector::const_iterator it = keypoints.begin(); it != keypoints.end(); ++it) + { + circle(img, it->pt, 3, cvScalar(255, 0, 255, 0)); + } - //pool->addImage(output_idx,outimage); + //pool->addImage(output_idx,outimage); } -static double computeReprojectionErrors( - const vector >& objectPoints, const vector >& imagePoints, const vector& rvecs, - const vector& tvecs, const Mat& cameraMatrix, - const Mat& distCoeffs, vector& perViewErrors) { - vector imagePoints2; - int i, totalPoints = 0; - double totalErr = 0, err; - perViewErrors.resize(objectPoints.size()); - - for (i = 0; i < (int) objectPoints.size(); i++) { - projectPoints(Mat(objectPoints[i]), rvecs[i], tvecs[i], cameraMatrix, - distCoeffs, imagePoints2); - err = norm(Mat(imagePoints[i]), Mat(imagePoints2), CV_L1 ); - int n = (int) objectPoints[i].size(); - perViewErrors[i] = err / n; - totalErr += err; - totalPoints += n; - } - - return totalErr / totalPoints; +static double computeReprojectionErrors(const vector >& objectPoints, + const vector >& imagePoints, const vector& rvecs, + const vector& tvecs, const Mat& cameraMatrix, const Mat& distCoeffs, + vector& perViewErrors) +{ + vector imagePoints2; + int i, totalPoints = 0; + double totalErr = 0, err; + perViewErrors.resize(objectPoints.size()); + + for (i = 0; i < (int)objectPoints.size(); i++) + { + projectPoints(Mat(objectPoints[i]), rvecs[i], tvecs[i], cameraMatrix, distCoeffs, imagePoints2); + err = norm(Mat(imagePoints[i]), Mat(imagePoints2), CV_L1); + int n = (int)objectPoints[i].size(); + perViewErrors[i] = err / n; + totalErr += err; + totalPoints += n; + } + + return totalErr / totalPoints; } -static void calcChessboardCorners(Size boardSize, float squareSize, vector< - Point3f>& corners) { - corners.resize(0); +static void calcChessboardCorners(Size boardSize, float squareSize, vector& corners) +{ + corners.resize(0); - for (int i = 0; i < boardSize.height; i++) - for (int j = 0; j < boardSize.width; j++) - corners.push_back(Point3f(float(j * squareSize), float(i - * squareSize), 0)); + for (int i = 0; i < boardSize.height; i++) + for (int j = 0; j < boardSize.width; j++) + corners.push_back(Point3f(float(j * squareSize), float(i * squareSize), 0)); } /**from opencv/samples/cpp/calibration.cpp * */ -static bool runCalibration(vector > imagePoints, - Size imageSize, Size boardSize, float squareSize, float aspectRatio, - int flags, Mat& cameraMatrix, Mat& distCoeffs, vector& rvecs, - vector& tvecs, vector& reprojErrs, double& totalAvgErr) { - cameraMatrix = Mat::eye(3, 3, CV_64F); - if (flags & CV_CALIB_FIX_ASPECT_RATIO) - cameraMatrix.at (0, 0) = aspectRatio; +static bool runCalibration(vector > imagePoints, Size imageSize, Size boardSize, float squareSize, + float aspectRatio, int flags, Mat& cameraMatrix, Mat& distCoeffs, vector& rvecs, + vector& tvecs, vector& reprojErrs, double& totalAvgErr) +{ + cameraMatrix = Mat::eye(3, 3, CV_64F); + if (flags & CV_CALIB_FIX_ASPECT_RATIO) + cameraMatrix.at (0, 0) = aspectRatio; - distCoeffs = Mat::zeros(5, 1, CV_64F); + distCoeffs = Mat::zeros(5, 1, CV_64F); - vector > objectPoints(1); - calcChessboardCorners(boardSize, squareSize, objectPoints[0]); - for (size_t i = 1; i < imagePoints.size(); i++) - objectPoints.push_back(objectPoints[0]); + vector > objectPoints(1); + calcChessboardCorners(boardSize, squareSize, objectPoints[0]); + for (size_t i = 1; i < imagePoints.size(); i++) + objectPoints.push_back(objectPoints[0]); - calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, - distCoeffs, rvecs, tvecs, flags); + calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs, rvecs, tvecs, flags); - bool ok = checkRange(cameraMatrix, CV_CHECK_QUIET ) && checkRange( - distCoeffs, CV_CHECK_QUIET ); + bool ok = checkRange(cameraMatrix, CV_CHECK_QUIET) && checkRange(distCoeffs, CV_CHECK_QUIET); - totalAvgErr = computeReprojectionErrors(objectPoints, imagePoints, rvecs, - tvecs, cameraMatrix, distCoeffs, reprojErrs); + totalAvgErr + = computeReprojectionErrors(objectPoints, imagePoints, rvecs, tvecs, cameraMatrix, distCoeffs, reprojErrs); - return ok; + return ok; } -bool Processor::detectAndDrawChessboard(int idx,image_pool* pool) { +bool Processor::detectAndDrawChessboard(int idx, image_pool* pool) +{ - Mat grey; - pool->getGrey(idx, grey); - if (grey.empty()) - return false; - vector corners; + Mat grey = pool->getGrey(idx); + if (grey.empty()) + return false; + vector corners; - IplImage iplgrey = grey; - if (!cvCheckChessboard(&iplgrey, Size(6, 8))) - return false; - bool patternfound = findChessboardCorners(grey, Size(6, 8), corners); + IplImage iplgrey = grey; + if (!cvCheckChessboard(&iplgrey, Size(6, 8))) + return false; + bool patternfound = findChessboardCorners(grey, Size(6, 8), corners); - Mat * img = pool->getImage(idx); + Mat img = pool->getImage(idx); - if (corners.size() < 1) - return false; + if (corners.size() < 1) + return false; - cornerSubPix(grey, corners, Size(11, 11), Size(-1, -1), TermCriteria( - CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1)); + cornerSubPix(grey, corners, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1)); - if(patternfound) - imagepoints.push_back(corners); + if (patternfound) + imagepoints.push_back(corners); - drawChessboardCorners(*img, Size(6, 8), Mat(corners), patternfound); + drawChessboardCorners(img, Size(6, 8), Mat(corners), patternfound); - imgsize = grey.size(); + imgsize = grey.size(); - return patternfound; + return patternfound; } -void Processor::drawText(int i, image_pool* pool, const char* ctext){ - // Use "y" to show that the baseLine is about - string text = ctext; - int fontFace = FONT_HERSHEY_COMPLEX_SMALL; - double fontScale = .8; - int thickness = .5; - - Mat img = *pool->getImage(i); - - int baseline=0; - Size textSize = getTextSize(text, fontFace, - fontScale, thickness, &baseline); - baseline += thickness; - - // center the text - Point textOrg((img.cols - textSize.width)/2, - (img.rows - textSize.height *2)); - - // draw the box - rectangle(img, textOrg + Point(0, baseline), - textOrg + Point(textSize.width, -textSize.height), - Scalar(0,0,255),CV_FILLED); - // ... and the baseline first - line(img, textOrg + Point(0, thickness), - textOrg + Point(textSize.width, thickness), - Scalar(0, 0, 255)); - - // then put the text itself - putText(img, text, textOrg, fontFace, fontScale, - Scalar::all(255), thickness, 8); +void Processor::drawText(int i, image_pool* pool, const char* ctext) +{ + // Use "y" to show that the baseLine is about + string text = ctext; + int fontFace = FONT_HERSHEY_COMPLEX_SMALL; + double fontScale = .8; + int thickness = .5; + + Mat img = pool->getImage(i); + + int baseline = 0; + Size textSize = getTextSize(text, fontFace, fontScale, thickness, &baseline); + baseline += thickness; + + // center the text + Point textOrg((img.cols - textSize.width) / 2, (img.rows - textSize.height * 2)); + + // draw the box + rectangle(img, textOrg + Point(0, baseline), textOrg + Point(textSize.width, -textSize.height), Scalar(0, 0, 255), + CV_FILLED); + // ... and the baseline first + line(img, textOrg + Point(0, thickness), textOrg + Point(textSize.width, thickness), Scalar(0, 0, 255)); + + // then put the text itself + putText(img, text, textOrg, fontFace, fontScale, Scalar::all(255), thickness, 8); } -void saveCameraParams(const string& filename, Size imageSize, Size boardSize, - float squareSize, float aspectRatio, int flags, - const Mat& cameraMatrix, const Mat& distCoeffs, - const vector& rvecs, const vector& tvecs, - const vector& reprojErrs, - const vector >& imagePoints, double totalAvgErr) { - FileStorage fs(filename, FileStorage::WRITE); - - time_t t; - time(&t); - struct tm *t2 = localtime(&t); - char buf[1024]; - strftime(buf, sizeof(buf) - 1, "%c", t2); - - fs << "calibration_time" << buf; - - if (!rvecs.empty() || !reprojErrs.empty()) - fs << "nframes" << (int) std::max(rvecs.size(), reprojErrs.size()); - fs << "image_width" << imageSize.width; - fs << "image_height" << imageSize.height; - fs << "board_width" << boardSize.width; - fs << "board_height" << boardSize.height; - fs << "squareSize" << squareSize; - - if (flags & CV_CALIB_FIX_ASPECT_RATIO) - fs << "aspectRatio" << aspectRatio; - - if (flags != 0) { - sprintf(buf, "flags: %s%s%s%s", - flags & CV_CALIB_USE_INTRINSIC_GUESS ? "+use_intrinsic_guess" - : "", - flags & CV_CALIB_FIX_ASPECT_RATIO ? "+fix_aspectRatio" : "", - flags & CV_CALIB_FIX_PRINCIPAL_POINT ? "+fix_principal_point" - : "", - flags & CV_CALIB_ZERO_TANGENT_DIST ? "+zero_tangent_dist" : ""); - cvWriteComment(*fs, buf, 0); - } - - fs << "flags" << flags; - - fs << "camera_matrix" << cameraMatrix; - fs << "distortion_coefficients" << distCoeffs; - - fs << "avg_reprojection_error" << totalAvgErr; - if (!reprojErrs.empty()) - fs << "per_view_reprojection_errors" << Mat(reprojErrs); - - if (!rvecs.empty() && !tvecs.empty()) { - Mat bigmat(rvecs.size(), 6, CV_32F); - for (size_t i = 0; i < rvecs.size(); i++) { - Mat r = bigmat(Range(i, i + 1), Range(0, 3)); - Mat t = bigmat(Range(i, i + 1), Range(3, 6)); - rvecs[i].copyTo(r); - tvecs[i].copyTo(t); - } - cvWriteComment( - *fs, - "a set of 6-tuples (rotation vector + translation vector) for each view", - 0); - fs << "extrinsic_parameters" << bigmat; - } - - if (!imagePoints.empty()) { - Mat imagePtMat(imagePoints.size(), imagePoints[0].size(), CV_32FC2); - for (size_t i = 0; i < imagePoints.size(); i++) { - Mat r = imagePtMat.row(i).reshape(2, imagePtMat.cols); - Mat(imagePoints[i]).copyTo(r); - } - fs << "image_points" << imagePtMat; - } +void saveCameraParams(const string& filename, Size imageSize, Size boardSize, float squareSize, float aspectRatio, + int flags, const Mat& cameraMatrix, const Mat& distCoeffs, const vector& rvecs, + const vector& tvecs, const vector& reprojErrs, + const vector >& imagePoints, double totalAvgErr) +{ + FileStorage fs(filename, FileStorage::WRITE); + + time_t t; + time(&t); + struct tm *t2 = localtime(&t); + char buf[1024]; + strftime(buf, sizeof(buf) - 1, "%c", t2); + + fs << "calibration_time" << buf; + + if (!rvecs.empty() || !reprojErrs.empty()) + fs << "nframes" << (int)std::max(rvecs.size(), reprojErrs.size()); + fs << "image_width" << imageSize.width; + fs << "image_height" << imageSize.height; + fs << "board_width" << boardSize.width; + fs << "board_height" << boardSize.height; + fs << "squareSize" << squareSize; + + if (flags & CV_CALIB_FIX_ASPECT_RATIO) + fs << "aspectRatio" << aspectRatio; + + if (flags != 0) + { + sprintf(buf, "flags: %s%s%s%s", flags & CV_CALIB_USE_INTRINSIC_GUESS ? "+use_intrinsic_guess" : "", flags + & CV_CALIB_FIX_ASPECT_RATIO ? "+fix_aspectRatio" : "", flags & CV_CALIB_FIX_PRINCIPAL_POINT + ? "+fix_principal_point" : "", flags & CV_CALIB_ZERO_TANGENT_DIST ? "+zero_tangent_dist" : ""); + cvWriteComment(*fs, buf, 0); + } + + fs << "flags" << flags; + + fs << "camera_matrix" << cameraMatrix; + fs << "distortion_coefficients" << distCoeffs; + + fs << "avg_reprojection_error" << totalAvgErr; + if (!reprojErrs.empty()) + fs << "per_view_reprojection_errors" << Mat(reprojErrs); + + if (!rvecs.empty() && !tvecs.empty()) + { + Mat bigmat(rvecs.size(), 6, CV_32F); + for (size_t i = 0; i < rvecs.size(); i++) + { + Mat r = bigmat(Range(i, i + 1), Range(0, 3)); + Mat t = bigmat(Range(i, i + 1), Range(3, 6)); + rvecs[i].copyTo(r); + tvecs[i].copyTo(t); + } + cvWriteComment(*fs, "a set of 6-tuples (rotation vector + translation vector) for each view", 0); + fs << "extrinsic_parameters" << bigmat; + } + + if (!imagePoints.empty()) + { + Mat imagePtMat(imagePoints.size(), imagePoints[0].size(), CV_32FC2); + for (size_t i = 0; i < imagePoints.size(); i++) + { + Mat r = imagePtMat.row(i).reshape(2, imagePtMat.cols); + Mat(imagePoints[i]).copyTo(r); + } + fs << "image_points" << imagePtMat; + } } -void Processor::resetChess() { +void Processor::resetChess() +{ - imagepoints.clear(); + imagepoints.clear(); } -void Processor::calibrate(const char* filename) { - - vector rvecs, tvecs; - vector reprojErrs; - double totalAvgErr = 0; - int flags = 0; - bool writeExtrinsics = true; - bool writePoints = true; +void Processor::calibrate(const char* filename) +{ - bool ok = runCalibration(imagepoints, imgsize, Size(6, 8), 1.f, 1.f, - flags, K, distortion, rvecs, tvecs, reprojErrs, totalAvgErr); + vector rvecs, tvecs; + vector reprojErrs; + double totalAvgErr = 0; + int flags = 0; + bool writeExtrinsics = true; + bool writePoints = true; + bool ok = runCalibration(imagepoints, imgsize, Size(6, 8), 1.f, 1.f, flags, K, distortion, rvecs, tvecs, reprojErrs, + totalAvgErr); - if (ok){ + if (ok) + { - saveCameraParams(filename, imgsize, Size(6, 8), 1.f, - 1.f, flags, K, distortion, writeExtrinsics ? rvecs - : vector (), writeExtrinsics ? tvecs - : vector (), writeExtrinsics ? reprojErrs - : vector (), writePoints ? imagepoints : vector< - vector > (), totalAvgErr); - } + saveCameraParams(filename, imgsize, Size(6, 8), 1.f, 1.f, flags, K, distortion, writeExtrinsics ? rvecs : vector< + Mat> (), writeExtrinsics ? tvecs : vector (), writeExtrinsics ? reprojErrs : vector (), writePoints + ? imagepoints : vector > (), totalAvgErr); + } } -int Processor::getNumberDetectedChessboards() { - return imagepoints.size(); +int Processor::getNumberDetectedChessboards() +{ + return imagepoints.size(); } diff --git a/android/apps/CVCamera/jni/Processor.h b/android/apps/CVCamera/jni/Processor.h index 49bee55a4c..cf61571ab5 100644 --- a/android/apps/CVCamera/jni/Processor.h +++ b/android/apps/CVCamera/jni/Processor.h @@ -14,8 +14,6 @@ #include #include - - #include #include "image_pool.h" @@ -24,36 +22,34 @@ #define DETECT_STAR 1 #define DETECT_SURF 2 -class Processor { - - cv::StarFeatureDetector stard; - cv::FastFeatureDetector fastd; - cv::SurfFeatureDetector surfd; - std::vector keypoints; - - vector > imagepoints; - - cv::Mat K; - cv::Mat distortion; - cv::Size imgsize; - //image_pool pool; +class Processor +{ public: - Processor(); - virtual ~Processor(); - - void detectAndDrawFeatures(int idx, image_pool* pool, int feature_type); + Processor(); + virtual ~Processor(); + + void detectAndDrawFeatures(int idx, image_pool* pool, int feature_type); - bool detectAndDrawChessboard(int idx,image_pool* pool); + bool detectAndDrawChessboard(int idx, image_pool* pool); - void resetChess(); + void resetChess(); - int getNumberDetectedChessboards(); + int getNumberDetectedChessboards(); - void calibrate(const char* filename); + void calibrate(const char* filename); - void drawText(int idx, image_pool* pool, const char* text); + void drawText(int idx, image_pool* pool, const char* text); +private: + cv::StarFeatureDetector stard; + cv::FastFeatureDetector fastd; + cv::SurfFeatureDetector surfd; + std::vector keypoints; + std::vector > imagepoints; + cv::Mat K; + cv::Mat distortion; + cv::Size imgsize; }; diff --git a/android/apps/CVCamera/sample.local.env.mk b/android/apps/CVCamera/sample.local.env.mk index 203c7301e8..d20c1b05b1 100644 --- a/android/apps/CVCamera/sample.local.env.mk +++ b/android/apps/CVCamera/sample.local.env.mk @@ -1,4 +1,4 @@ #location of android-opencv port of OpenCV to android OPENCV_CONFIG=../../build/android-opencv.mk ANDROID_NDK_ROOT=$(HOME)/android-ndk-r4-crystax - +ARM_TARGETS=armeabi armeabi-v7a diff --git a/android/apps/CVCamera/src/com/theveganrobot/cvcamera/CVCamera.java b/android/apps/CVCamera/src/com/theveganrobot/cvcamera/CVCamera.java index 2cbcbb31c6..b1fcbfabc8 100644 --- a/android/apps/CVCamera/src/com/theveganrobot/cvcamera/CVCamera.java +++ b/android/apps/CVCamera/src/com/theveganrobot/cvcamera/CVCamera.java @@ -10,6 +10,7 @@ import android.app.AlertDialog; import android.app.Dialog; import android.app.ProgressDialog; import android.content.DialogInterface; +import android.content.Intent; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.os.Environment; @@ -20,16 +21,16 @@ import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; +import android.view.ViewGroup.LayoutParams; import android.view.Window; import android.view.WindowManager; -import android.view.ViewGroup.LayoutParams; -import android.widget.AnalogClock; import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.Toast; +import com.opencv.camera.CameraConfig; import com.opencv.camera.NativePreviewer; import com.opencv.camera.NativeProcessor; import com.opencv.camera.NativeProcessor.PoolCallback; @@ -77,12 +78,11 @@ public class CVCamera extends Activity { Toast.LENGTH_LONG).show(); break; case DIALOG_TUTORIAL_CHESS: - Toast - .makeText( - this, - "Calibration Mode, Point at a chessboard pattern and press the camera button, space," - + "or the DPAD to capture.", - Toast.LENGTH_LONG).show(); + Toast.makeText( + this, + "Calibration Mode, Point at a chessboard pattern and press the camera button, space," + + "or the DPAD to capture.", Toast.LENGTH_LONG) + .show(); break; default: @@ -110,8 +110,9 @@ public class CVCamera extends Activity { private Dialog makeCalibFileAlert() { AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage(calib_text).setTitle( - "camera.yml at " + calib_file_loc).setCancelable(false) + builder.setMessage(calib_text) + .setTitle("camera.yml at " + calib_file_loc) + .setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { @@ -187,6 +188,7 @@ public class CVCamera extends Activity { menu.add("STAR"); menu.add("SURF"); menu.add("Chess"); + menu.add("Settings"); return true; } @@ -224,7 +226,14 @@ public class CVCamera extends Activity { } + else if (item.getTitle().equals("Settings")) { + + Intent intent = new Intent(this,CameraConfig.class); + startActivity(intent); + } + mPreview.addCallbackStack(defaultcallbackstack); + return true; } @@ -234,7 +243,6 @@ public class CVCamera extends Activity { super.onOptionsMenuClosed(menu); } - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -263,53 +271,54 @@ public class CVCamera extends Activity { glview = new GL2CameraViewer(getApplication(), false, 0, 0); glview.setZOrderMediaOverlay(true); - glview.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, - LayoutParams.FILL_PARENT)); - + + LinearLayout gllay = new LinearLayout(getApplication()); + + gllay.setGravity(Gravity.CENTER); + gllay.addView(glview, params); + frame.addView(gllay); + ImageButton capture_button = new ImageButton(getApplicationContext()); - capture_button.setImageDrawable(getResources().getDrawable(android.R.drawable.ic_menu_camera)); - capture_button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, - LayoutParams.WRAP_CONTENT)); + capture_button.setImageDrawable(getResources().getDrawable( + android.R.drawable.ic_menu_camera)); + capture_button.setLayoutParams(new LayoutParams( + LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); capture_button.setOnClickListener(new View.OnClickListener() { - - + @Override public void onClick(View v) { captureChess = true; - + } }); - + LinearLayout buttons = new LinearLayout(getApplicationContext()); buttons.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); - + buttons.addView(capture_button); - + Button focus_button = new Button(getApplicationContext()); - focus_button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, - LayoutParams.WRAP_CONTENT)); + focus_button.setLayoutParams(new LayoutParams( + LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); focus_button.setText("Focus"); focus_button.setOnClickListener(new View.OnClickListener() { - + @Override public void onClick(View v) { mPreview.postautofocus(100); } }); buttons.addView(focus_button); - - frame.addView(glview); frame.addView(buttons); setContentView(frame); toasts(DIALOG_OPENING_TUTORIAL); - } @Override public boolean onTrackballEvent(MotionEvent event) { - if(event.getAction() == MotionEvent.ACTION_UP){ + if (event.getAction() == MotionEvent.ACTION_UP) { captureChess = true; return true; } @@ -320,8 +329,7 @@ public class CVCamera extends Activity { protected void onPause() { super.onPause(); - - //clears the callback stack + // clears the callback stack mPreview.onPause(); glview.onPause(); @@ -332,9 +340,9 @@ public class CVCamera extends Activity { protected void onResume() { super.onResume(); glview.onResume(); - - //add an initiall callback stack to the preview on resume... - //this one will just draw the frames to opengl + mPreview.setParamsFromPrefs(getApplicationContext()); + // add an initiall callback stack to the preview on resume... + // this one will just draw the frames to opengl LinkedList cbstack = new LinkedList(); cbstack.add(glview.getDrawCallback()); mPreview.addCallbackStack(cbstack); @@ -362,7 +370,6 @@ public class CVCamera extends Activity { public void process(int idx, image_pool pool, long timestamp, NativeProcessor nativeProcessor) { processor.detectAndDrawFeatures(idx, pool, cvcamera.DETECT_STAR); - } @@ -396,8 +403,8 @@ public class CVCamera extends Activity { } if (processor.getNumberDetectedChessboards() == 10) { - File opencvdir = new File(Environment - .getExternalStorageDirectory(), "opencv"); + File opencvdir = new File( + Environment.getExternalStorageDirectory(), "opencv"); if (!opencvdir.exists()) { opencvdir.mkdir(); } @@ -486,9 +493,9 @@ public class CVCamera extends Activity { } if (processor.getNumberDetectedChessboards() < 10) { - processor.drawText(idx, pool, "found " - + processor.getNumberDetectedChessboards() - + "/10 chessboards"); + processor.drawText(idx, pool, + "found " + processor.getNumberDetectedChessboards() + + "/10 chessboards"); } }