Exemple #1
0
  public void setCameraPreviewSize(Camera.Parameters cp) {
    List<CameraController.Size> cs = CameraController.getInstance().getSupportedPreviewSizes();

    CameraController.Size os =
        getOptimalPreviewSize(cs, MainScreen.getImageWidth(), MainScreen.getImageHeight());
    cp.setPreviewSize(os.getWidth(), os.getHeight());
    try {
      CameraController.getInstance().setCameraParameters(cp);
    } catch (RuntimeException e) {
      Log.e("CameraTest", "MainScreen.setupCamera unable setParameters " + e.getMessage());
    }
  }
Exemple #2
0
  // from google example
  protected CameraController.Size getOptimalPreviewSize(
      List<CameraController.Size> sizes, int w, int h) {
    final double ASPECT_TOLERANCE = 0.05;
    double targetRatio = (double) w / h;
    if (sizes == null) return null;

    CameraController.Size optimalSize = null;
    double minDiff = Double.MAX_VALUE;

    int targetHeight = h;

    // Try to find an size match aspect ratio and size
    for (CameraController.Size size : sizes) {
      double ratio = (double) size.getWidth() / size.getHeight();
      if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
      if (Math.abs(size.getHeight() - targetHeight) < minDiff) {
        optimalSize = size;
        minDiff = Math.abs(size.getHeight() - targetHeight);
      }
    }

    // Cannot find the one match the aspect ratio, ignore the requirement
    if (optimalSize == null) {
      minDiff = Double.MAX_VALUE;
      for (CameraController.Size size : sizes) {
        if (Math.abs(size.getHeight() - targetHeight) < minDiff) {
          optimalSize = size;
          minDiff = Math.abs(size.getHeight() - targetHeight);
        }
      }
    }
    return optimalSize;
  }
  public void onSequenceChanged(final int[] idx) {
    sequenceView.setEnabled(false);

    CameraController.Size imageSize = CameraController.getCameraImageSize();
    Size input = new Size(imageSize.getWidth(), imageSize.getHeight());
    int minSize = 1000;
    if (mMinSize == 0) {
      minSize = 0;
    } else {
      minSize = input.getWidth() * input.getHeight() / mMinSize;
    }

    Size preview = new Size(mDisplayWidth, mDisplayHeight);
    try {
      mAlmaCLRShot.initialize(
          preview,
          mAngle,
          /*
           * sensitivity for objection detection
           */
          mSensitivity - 15,
          /*
           * Minimum size of object to be able to detect -15 ~ 15 max -> easy
           * detection dull detection min ->
           */
          minSize,
          /*
           * ghosting parameter 0 : normal operation 1 : detect ghosted
           * objects but not remove them 2 : detect and remove all object
           */
          Integer.parseInt(mGhosting),
          idx);
    } catch (NumberFormatException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }

    mHandler.sendEmptyMessage(MSG_REDRAW);
  }
  public void onStartProcessing(long SessionID) {
    finishing = false;
    Message msg = new Message();
    msg.what = ApplicationInterface.MSG_PROCESSING_BLOCK_UI;
    ApplicationScreen.getMessageHandler().sendMessage(msg);

    PluginManager.getInstance()
        .sendMessage(ApplicationInterface.MSG_BROADCAST, ApplicationInterface.MSG_CONTROL_LOCKED);

    ApplicationScreen.getGUIManager().lockControls = true;

    sessionID = SessionID;

    PluginManager.getInstance()
        .addToSharedMem(
            "modeSaveName" + sessionID, PluginManager.getInstance().getActiveMode().modeSaveName);

    mDisplayOrientation =
        Integer.valueOf(
            PluginManager.getInstance().getFromSharedMem("frameorientation1" + sessionID));
    int orientation = ApplicationScreen.getGUIManager().getLayoutOrientation();
    mLayoutOrientationCurrent =
        (orientation == 0 || orientation == 180) ? orientation : (orientation + 180) % 360;

    mCameraMirrored =
        Boolean.valueOf(PluginManager.getInstance().getFromSharedMem("framemirrored1" + sessionID));

    CameraController.Size imageSize = CameraController.getCameraImageSize();
    if (mDisplayOrientation == 0 || mDisplayOrientation == 180) {
      imgWidthOR = imageSize.getHeight();
      imgHeightOR = imageSize.getWidth();
    } else {
      imgWidthOR = imageSize.getWidth();
      imgHeightOR = imageSize.getHeight();
    }

    mAlmaCLRShot = AlmaCLRShot.getInstance();

    getPrefs();

    try {
      Size input = new Size(imageSize.getWidth(), imageSize.getHeight());
      int imagesAmount =
          Integer.parseInt(
              PluginManager.getInstance().getFromSharedMem("amountofcapturedframes" + sessionID));
      int minSize = 1000;
      if (mMinSize == 0) {
        minSize = 0;
      } else {
        minSize = input.getWidth() * input.getHeight() / mMinSize;
      }

      if (imagesAmount == 0) imagesAmount = 1;

      int iImageWidth = imageSize.getWidth();
      int iImageHeight = imageSize.getHeight();

      thumbnails.clear();
      int heightPixels = ApplicationScreen.getAppResources().getDisplayMetrics().heightPixels;
      for (int i = 1; i <= imagesAmount; i++) {
        thumbnails.add(
            Bitmap.createScaledBitmap(
                ImageConversion.decodeYUVfromBuffer(
                    mYUVBufferList.get(i - 1), iImageWidth, iImageHeight),
                heightPixels / imagesAmount,
                (int) (iImageHeight * (((float) heightPixels / imagesAmount) / iImageWidth)),
                false));
      }

      Display display =
          ((WindowManager) ApplicationScreen.instance.getSystemService(Context.WINDOW_SERVICE))
              .getDefaultDisplay();
      Point dis = new Point();
      display.getSize(dis);

      float imageRatio = (float) iImageWidth / (float) iImageHeight;
      float displayRatio = (float) dis.y / (float) dis.x;

      if (imageRatio > displayRatio) {
        mDisplayWidth = dis.y;
        mDisplayHeight = (int) ((float) dis.y / (float) imageRatio);
      } else {
        mDisplayWidth = (int) ((float) dis.x * (float) imageRatio);
        mDisplayHeight = dis.x;
      }

      Size preview = new Size(mDisplayWidth, mDisplayHeight);

      PluginManager.getInstance()
          .addToSharedMem("amountofresultframes" + sessionID, String.valueOf(imagesAmount));

      PluginManager.getInstance()
          .addToSharedMem("saveImageWidth" + sessionID, String.valueOf(imgWidthOR));
      PluginManager.getInstance()
          .addToSharedMem("saveImageHeight" + sessionID, String.valueOf(imgHeightOR));

      this.indexes = new int[imagesAmount];
      for (int i = 0; i < imagesAmount; i++) {
        this.indexes[i] = i;
      }

      // frames!!! should be taken from heap
      mAlmaCLRShot.addYUVInputFrame(mYUVBufferList, input);

      mAlmaCLRShot.initialize(
          preview,
          mAngle,
          /*
           * sensitivity for objection detection
           */
          mSensitivity - 15,
          /*
           * Minimum size of object to be able to detect -15 ~ 15 max -> easy
           * detection dull detection min ->
           */
          minSize,
          /*
           * ghosting parameter 0 : normal operation 1 : detect ghosted
           * objects but not remove them 2 : detect and remove all object
           */
          Integer.parseInt(mGhosting),
          indexes);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemple #5
0
  public void selectImageDimension() {
    // ----- Figure how much memory do we have and possibly limit resolution
    long maxMem = Runtime.getRuntime().maxMemory();
    long maxMpix = (maxMem - 1000000) / 3; // 2 x Mpix - result, 1/4 x Mpix
    // x 4 - compressed input jpegs,
    // 1Mb - safe reserve

    // find index selected in preferences
    int prefIdx = -1;
    try {
      prefIdx = Integer.parseInt(MainScreen.getImageSizeIndex());
    } catch (IndexOutOfBoundsException e) {
      prefIdx = -1;
    }

    List<CameraController.Size> cs = CameraController.getResolutionsSizeList();
    // add 8 Mpix for rear camera for HTC One X
    if (Build.MODEL.contains("HTC One X")) {
      if (!CameraController.isFrontCamera()) {
        CameraController.Size additional = null;
        additional = CameraController.getInstance().new Size(3264, 2448);
        additional.setWidth(3264);
        additional.setHeight(2448);
        cs.add(additional);
      }
    }
    int defaultCaptureIdx = -1;
    long defaultCaptureMpix = 0;
    int defaultCaptureWidth = 0;
    int defaultCaptureHeight = 0;
    long CaptureMpix = 0;
    int CaptureWidth = 0;
    int CaptureHeight = 0;
    int CaptureIdx = -1;
    boolean prefFound = false;

    // figure default resolution
    int ii = 0;
    for (CameraController.Size s : cs) {
      long mpix = (long) s.getWidth() * s.getHeight();

      if ((mpix >= CameraController.MIN_MPIX_SUPPORTED) && (mpix < maxMpix)) {
        if (mpix > defaultCaptureMpix && mpix <= MPIX_8) {
          defaultCaptureIdx = ii;
          defaultCaptureMpix = mpix;
          defaultCaptureWidth = s.getWidth();
          defaultCaptureHeight = s.getHeight();
        }
      }

      ii++;
    }

    ii = 0;
    for (CameraController.Size s : cs) {
      long mpix = (long) s.getWidth() * s.getHeight();

      if ((Integer.parseInt(CameraController.getResolutionsIdxesList().get(ii)) == prefIdx)
          && (mpix >= CameraController.MIN_MPIX_SUPPORTED)) {
        prefFound = true;
        CaptureIdx = ii;
        CaptureMpix = mpix;
        CaptureWidth = s.getWidth();
        CaptureHeight = s.getHeight();
        break;
      }

      if (mpix > CaptureMpix) {
        CaptureIdx = ii;
        CaptureMpix = mpix;
        CaptureWidth = s.getWidth();
        CaptureHeight = s.getHeight();
      }

      ii++;
    }

    // default to about 8Mpix if nothing is set in preferences or maximum
    // resolution is above memory limits
    if (defaultCaptureMpix > 0) {
      if (!prefFound) {
        CaptureIdx = defaultCaptureIdx;
        CaptureMpix = defaultCaptureMpix;
        CaptureWidth = defaultCaptureWidth;
        CaptureHeight = defaultCaptureHeight;
      }
    }

    CameraController.setCameraImageSizeIndex(CaptureIdx);
    MainScreen.setImageWidth(CaptureWidth);
    MainScreen.setImageHeight(CaptureHeight);

    MainScreen.setSaveImageWidth(CaptureWidth);
    MainScreen.setSaveImageHeight(CaptureHeight);
  }