1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00
* Added manual port for getTextSize;
* Fixed bugs in "native camera" sample;
* Added 15-puzzle sample.
This commit is contained in:
Andrey Kamaev
2011-07-16 22:31:47 +00:00
parent ae5dd1d748
commit be2c4ddbdd
13 changed files with 559 additions and 30 deletions
@@ -16,7 +16,6 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
private SurfaceHolder mHolder;
private VideoCapture mCamera;
private boolean mThreadRun;
public SampleViewBase(Context context) {
super(context);
@@ -27,27 +26,29 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) {
Log.i(TAG, "surfaceCreated");
if (mCamera != null && mCamera.isOpened()) {
Log.i(TAG, "before mCamera.getSupportedPreviewSizes()");
List<Size> sizes = mCamera.getSupportedPreviewSizes();
Log.i(TAG, "after mCamera.getSupportedPreviewSizes()");
int mFrameWidth = width;
int mFrameHeight = height;
synchronized (this) {
if (mCamera != null && mCamera.isOpened()) {
Log.i(TAG, "before mCamera.getSupportedPreviewSizes()");
List<Size> sizes = mCamera.getSupportedPreviewSizes();
Log.i(TAG, "after mCamera.getSupportedPreviewSizes()");
int mFrameWidth = width;
int mFrameHeight = height;
// selecting optimal camera preview size
{
double minDiff = Double.MAX_VALUE;
for (Size size : sizes) {
if (Math.abs(size.height - height) < minDiff) {
mFrameWidth = (int) size.width;
mFrameHeight = (int) size.height;
minDiff = Math.abs(size.height - height);
// selecting optimal camera preview size
{
double minDiff = Double.MAX_VALUE;
for (Size size : sizes) {
if (Math.abs(size.height - height) < minDiff) {
mFrameWidth = (int) size.width;
mFrameHeight = (int) size.height;
minDiff = Math.abs(size.height - height);
}
}
}
}
mCamera.set(highgui.CV_CAP_PROP_FRAME_WIDTH, mFrameWidth);
mCamera.set(highgui.CV_CAP_PROP_FRAME_HEIGHT, mFrameHeight);
mCamera.set(highgui.CV_CAP_PROP_FRAME_WIDTH, mFrameWidth);
mCamera.set(highgui.CV_CAP_PROP_FRAME_HEIGHT, mFrameHeight);
}
}
}
@@ -65,7 +66,6 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
public void surfaceDestroyed(SurfaceHolder holder) {
Log.i(TAG, "surfaceDestroyed");
mThreadRun = false;
if (mCamera != null) {
synchronized (this) {
mCamera.release();
@@ -77,17 +77,19 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
protected abstract Bitmap processFrame(VideoCapture capture);
public void run() {
mThreadRun = true;
Log.i(TAG, "Starting processing thread");
while (mThreadRun) {
while (true) {
Bitmap bmp = null;
if (!mCamera.grab()) {
Log.e(TAG, "mCamera.grab() failed");
break;
}
synchronized (this) {
if (mCamera == null)
break;
if (!mCamera.grab()) {
Log.e(TAG, "mCamera.grab() failed");
break;
}
bmp = processFrame(mCamera);
}
@@ -100,5 +102,7 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
bmp.recycle();
}
}
Log.i(TAG, "Finishing processing thread");
}
}