コード例 #1
0
  public void setupCamera(int width, int height) {
    Log.i(TAG, "setupCamera(" + width + ", " + height + ")");
    synchronized (this) {
      if (mCamera != null && mCamera.isOpened()) {
        List<Size> sizes = 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);
            }
          }
        }

        mCamera.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, mFrameWidth);
        mCamera.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, mFrameHeight);
      }
    }
  }
コード例 #2
0
  public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) {
    Log.i(TAG, "surfaceCreated");
    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);
            }
          }
        }

        mCamera.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, mFrameWidth);
        mCamera.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, mFrameHeight);
      }
    }
  }
コード例 #3
0
  public void setupCamera(int width, int height) {
    Log.i(TAG, "setupCamera out(" + width + ", " + height + ")");
    synchronized (this) {
      if (mCamera != null && mCamera.isOpened()) {
        List<Size> sizes = 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) + Math.abs(size.width - width)) < minDiff) {
              mFrameWidth = (int) size.width;
              mFrameHeight = (int) size.height;
              minDiff = Math.abs(size.height - height);
            }
          }
        }

        mCamera.set(
            Highgui.CV_CAP_PROP_ANDROID_ANTIBANDING, Highgui.CV_CAP_ANDROID_ANTIBANDING_OFF);
        mCamera.set(Highgui.CV_CAP_PROP_ANDROID_FLASH_MODE, Highgui.CV_CAP_ANDROID_FLASH_MODE_OFF);
        mCamera.set(
            Highgui.CV_CAP_PROP_ANDROID_FOCUS_MODE,
            Highgui.CV_CAP_ANDROID_FOCUS_MODE_CONTINUOUS_VIDEO);
        mCamera.set(
            Highgui.CV_CAP_PROP_ANDROID_WHITE_BALANCE,
            Highgui.CV_CAP_ANDROID_WHITE_BALANCE_FLUORESCENT);
        //                mCamera.set(Highgui.CV_CAP_PROP_IOS_DEVICE_EXPOSURE,
        //                Log.i(TAG, "setupCamera 6: " +
        // mCamera.get(Highgui.CV_CAP_PROP_IOS_DEVICE_EXPOSURE));

        mCamera.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, mFrameWidth);
        mCamera.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, mFrameHeight);
      }
    }
  }