Commit f7c17493 authored by Ethan Rublee's avatar Ethan Rublee

Bringing the CVCamera up to speed with new changes to android-jni - added…

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