1313import android .util .Log ;
1414
1515import com .documentscanner .views .OpenNoteCameraView ;
16- import com .google .zxing .BinaryBitmap ;
17- import com .google .zxing .LuminanceSource ;
18- import com .google .zxing .NotFoundException ;
19- import com .google .zxing .RGBLuminanceSource ;
20- import com .google .zxing .Result ;
21- import com .google .zxing .ResultPoint ;
22- import com .google .zxing .common .HybridBinarizer ;
23- import com .google .zxing .multi .qrcode .QRCodeMultiReader ;
2416import com .documentscanner .helpers .OpenNoteMessage ;
2517import com .documentscanner .helpers .PreviewFrame ;
2618import com .documentscanner .helpers .Quadrilateral ;
@@ -56,6 +48,8 @@ public class ImageProcessor extends Handler {
5648 private Point [] mPreviewPoints ;
5749 private int numOfSquares = 0 ;
5850 private int numOfRectangles = 10 ;
51+ private double lastCaptureTime = 0 ;
52+ private double durationBetweenCaptures = 0 ;
5953
6054 public ImageProcessor (Looper looper , OpenNoteCameraView mainActivity , Context context ) {
6155 super (looper );
@@ -68,6 +62,10 @@ public void setNumOfRectangles(int numOfRectangles) {
6862 this .numOfRectangles = numOfRectangles ;
6963 }
7064
65+ public void setDurationBetweenCaptures (double durationBetweenCaptures ) {
66+ this .durationBetweenCaptures = durationBetweenCaptures ;
67+ }
68+
7169 public void setBrightness (double brightness ) {
7270 this .colorBias = brightness ;
7371 }
@@ -99,27 +97,16 @@ private void processPreviewFrame(PreviewFrame previewFrame) {
9997
10098 Mat frame = previewFrame .getFrame ();
10199
102- Result [] results = zxing (frame );
103-
104- for (Result result : results ) {
105- String qrText = result .getText ();
106- if (Utils .isMatch (qrText , "^P.. V.. S[0-9]+" ) && checkQR (qrText )) {
107- Log .d (TAG , "QR Code valid: " + result .getText ());
108- ResultPoint [] qrResultPoints = result .getResultPoints ();
109- break ;
110- } else {
111- Log .d (TAG , "QR Code ignored: " + result .getText ());
112- }
113- }
114-
115100 boolean focused = mMainActivity .isFocused ();
116101
117102 if (detectPreviewDocument (frame ) && focused ) {
118103 numOfSquares ++;
119- if (numOfSquares == numOfRectangles ) {
104+ double now = (double )(new Date ()).getTime () / 1000.0 ;
105+ if (numOfSquares == numOfRectangles && now < lastCaptureTime + durationBetweenCaptures ) {
106+ lastCaptureTime = now ;
107+ numOfSquares = 0 ;
120108 mMainActivity .requestPicture ();
121109 mMainActivity .waitSpinnerVisible ();
122- numOfSquares = 0 ;
123110 }
124111 } else {
125112 numOfSquares = 0 ;
@@ -447,44 +434,8 @@ public int compare(MatOfPoint lhs, MatOfPoint rhs) {
447434 return contours ;
448435 }
449436
450- private final QRCodeMultiReader qrCodeMultiReader = new QRCodeMultiReader ();
451-
452- private Result [] zxing (Mat inputImage ) {
453-
454- int w = inputImage .width ();
455- int h = inputImage .height ();
456-
457- Mat southEast ;
458-
459- if (mBugRotate ) {
460- southEast = inputImage .submat (h - h / 4 , h , 0 , w / 2 - h / 4 );
461- } else {
462- southEast = inputImage .submat (0 , h / 4 , w / 2 + h / 4 , w );
463- }
464-
465- Bitmap bMap = Bitmap .createBitmap (southEast .width (), southEast .height (), Bitmap .Config .ARGB_8888 );
466- org .opencv .android .Utils .matToBitmap (southEast , bMap );
467- southEast .release ();
468- int [] intArray = new int [bMap .getWidth () * bMap .getHeight ()];
469- // copy pixel data from the Bitmap into the 'intArray' array
470- bMap .getPixels (intArray , 0 , bMap .getWidth (), 0 , 0 , bMap .getWidth (), bMap .getHeight ());
471-
472- LuminanceSource source = new RGBLuminanceSource (bMap .getWidth (), bMap .getHeight (), intArray );
473-
474- BinaryBitmap bitmap = new BinaryBitmap (new HybridBinarizer (source ));
475-
476- Result [] results = {};
477- try {
478- results = qrCodeMultiReader .decodeMultiple (bitmap );
479- } catch (NotFoundException ignored ) {
480- }
481-
482- return results ;
483-
484- }
485-
486437 public void setBugRotate (boolean bugRotate ) {
487438 mBugRotate = bugRotate ;
488439 }
489440
490- }
441+ }
0 commit comments