KingsMentor / MobileVisionBarcodeScanner

Barcode Scanner powered by Mobile Vision Api
http://belvi.xyz/posts/Mobile-Vision-Barcode-Scanner
MIT License
540 stars 109 forks source link

How to set Set Rectangular overlay on Camera Preview #30

Closed kprathap23 closed 5 years ago

kprathap23 commented 6 years ago

32494173-a12cae9a-c3e6-11e7-9668-66e2977dae3f

KingsMentor commented 6 years ago

taking a look at this now. Would add this functionality to the next update.

KingsMentor commented 6 years ago

I just added setCustomDetector(Detector<Barcode> customDetector) to help achieve this.

Here is an example of how you can achieve this:


public class CustomBarCodeDetector extends Detector<Barcode> {

    public SparseArray<Barcode> detect(Frame frame) {
        // do something with frame
        return null;
    }

    public boolean isOperational() {
        return super.isOperational();
    }
}

see this on for further clarification on how you can use this.

don't forget to call barcodeCapture.refresh() after calling setCustomDetector()

KingsMentor commented 6 years ago

@kprathap23 available in the latest release.

jpabanil commented 6 years ago

Pls share how did you customized the detector like the way u did :)

jpabanil commented 6 years ago

Still getting this error

CODE

// init Barcode Detector BarcodeDetector mBarcodeDetector = new BarcodeDetector.Builder(getContext()).build(); CustomBarcodeDetector mCustomBarcodeDetector = new CustomBarcodeDetector(mBarcodeDetector);

        // init BarcodeCapture
        mBarcodeCapture = (BarcodeCapture) getChildFragmentManager().findFragmentById(R.id.barcode);
        mBarcodeCapture.setRetrieval(this);
        mBarcodeCapture.setBarcodeFormat(Barcode.CODE_128)
                .shouldAutoFocus(true)
                .setCameraFacing(CameraSource.CAMERA_FACING_BACK)
                .setShowDrawRect(false)
                .setSupportMultipleScan(false)
                .setTouchAsCallback(false)
                .setShowFlash(false)
                .setShouldShowText(false);
        mBarcodeCapture.setCustomDetector(mCustomBarcodeDetector);
        mBarcodeCapture.refresh(true);

ERROR

E/OpenCameraSource: Exception thrown from receiver. java.lang.IllegalStateException: Detector processor must first be set with setProcessor in order to receive detection results. at com.google.android.gms.vision.Detector.receiveFrame(Unknown Source) at com.google.android.gms.samples.vision.barcodereader.ui.camera.CameraSource$FrameProcessingRunnable.run(CameraSource.java:1222) at java.lang.Thread.run(Thread.java:818)

eternalBlast commented 6 years ago

Hi @jpabanil, do you achieve the success result now? Hi @KingsMentor, I try what you suggest at that link. However, i can't find the setCustomDetector method (using gradle dependency). Would you mind to provide more details in the readme section and the params (preferably in Kotlin version though)? Thanks.