How to run Flash while opining camera?

asked 2019-08-26 07:56:23 -0600

Mralaa gravatar image

updated 2019-08-26 09:44:04 -0600

i am using opencv 3.4.1 project to capture image i have used this link https://github.com/bluebead38/OpenCVT... and i have capure the image perfectly now i need to run flash with on and off button while capture the image i use extend classes for camera view

Blockquote package com.bluebead38.opencvtesseractocr;

import java.util.ArrayList; import java.util.List;

import org.opencv.android.JavaCameraView;

import android.R.integer; import android.content.Context; import android.graphics.Rect; import android.graphics.RectF; import android.hardware.Camera; import android.hardware.Camera.AutoFocusCallback; import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.Toast;

public class MTCameraView extends JavaCameraView implements AutoFocusCallback {

public MTCameraView(Context context, int attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
}

public List<Camera.Size> getResolutionList() {
    return  mCamera.getParameters().getSupportedPreviewSizes();
}

public Camera.Size getResolution() {
    Camera.Parameters params = mCamera.getParameters();
    Camera.Size s = params.getPreviewSize();
    return s;
}

public void setResolution(Camera.Size resolution) {
    disconnectCamera();
    connectCamera((int)resolution.width, (int)resolution.height);
}

public void focusOnTouch(MotionEvent event) {
    Rect focusRect = calculateTapArea(event.getRawX(), event.getRawY(), 1f);
    Rect meteringRect = calculateTapArea(event.getRawX(), event.getRawY(), 1.5f);

    Camera.Parameters parameters = mCamera.getParameters();
    parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);

    if (parameters.getMaxNumFocusAreas() > 0) {
        List<Camera.Area> focusAreas = new ArrayList<Camera.Area>();
        focusAreas.add(new Camera.Area(focusRect, 1000));

        parameters.setFocusAreas(focusAreas);
    }

    if (parameters.getMaxNumMeteringAreas() > 0) {
        List<Camera.Area> meteringAreas = new ArrayList<Camera.Area>();
        meteringAreas.add(new Camera.Area(meteringRect, 1000));

        parameters.setMeteringAreas(meteringAreas);
    }

    mCamera.setParameters(parameters);
    mCamera.autoFocus(this);
}

/**
 * Convert touch position x:y to {@link Camera.Area} position -1000:-1000 to 1000:1000.
 */
private Rect calculateTapArea(float x, float y, float coefficient) {
    float focusAreaSize = 300;
    int areaSize = Float.valueOf(focusAreaSize * coefficient).intValue();

    int centerX = (int) (x / getResolution().width * 2000 - 1000);
    int centerY = (int) (y / getResolution().height * 2000 - 1000);

    int left = clamp(centerX - areaSize / 2, -1000, 1000);
    int right = clamp(left + areaSize, -1000, 1000);
    int top = clamp(centerY - areaSize / 2, -1000, 1000);
    int bottom = clamp(top + areaSize, -1000, 1000);

    return new Rect(left, top, right, bottom);
}

private int clamp(int x, int min, int max) {
    if (x > max) {
        return max;
    }
    if (x < min) {
        return min;
    }
    return x;
}

public void setFocusMode (Context item, int type){
    Camera.Parameters params = mCamera.getParameters();
    List<String> FocusModes = params.getSupportedFocusModes();

    switch (type){
        case 0:
            if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO))
                params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
            else
                Toast.makeText(item, "Auto Mode not supported", Toast.LENGTH_SHORT).show();
            break;
        case 1:
            if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO))
                params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
            else
                Toast.makeText(item, "Continuous Mode not supported", Toast.LENGTH_SHORT).show();
            break;
        case 2:
            if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_EDOF))
                params.setFocusMode(Camera.Parameters.FOCUS_MODE_EDOF);
            else
                Toast.makeText(item, "EDOF Mode not supported", Toast.LENGTH_SHORT).show();
            break;
        case 3:
            if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_FIXED))
                params.setFocusMode(Camera.Parameters.FOCUS_MODE_FIXED);
            else
                Toast.makeText(item, "Fixed Mode not supported", Toast.LENGTH_SHORT).show();
            break;
        case 4:
            if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_INFINITY))
                params.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);
            else
                Toast.makeText(item, "Infinity Mode not supported", Toast.LENGTH_SHORT).show();
            break;
        case 5:
            if (FocusModes ...
(more)
edit retag flag offensive close merge delete