Google Barcode API PDF417 not working - android

I've followed the directions in the Google codelab to get the Baracode API to detect and decode a standard QR code. I've done a simple integration to get the camera to provide the image and it works. Then I try a PDF417 bar code, and nothing.
Bitmap myBitmap = BitmapFactory.decodeResource(
getApplicationContext().getResources(),
R.drawable.barcode);
BarcodeDetector detector =
new BarcodeDetector.Builder(getApplicationContext())
.setBarcodeFormats(Barcode.PDF417)
.build();
Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
SparseArray<Barcode> barcodes = detector.detect(frame);
Barcode thisCode = barcodes.valueAt(0);
barcodes is a zero length object and thisCode fails trying to get the value at position 0. I've tried feeding a PDF417 barcode I took a picture of as well as a barcode from an online generator.
Can someone help me?
Thanks in advance!!

A quick answer to your question, you either need to change the barcode flag to ALL_FORMATS (Barcode.ALL_FORMATS) or you should only provide the barcode. In other words, there should be no other visual information alongside the barcode (crop it). Otherwise, the API can't find the PDF-417 barcode.

Related

QR code detection issue from photo using openCV

I am currently working on an android application, that should be able to detect a QR code from a picture taken. It is not necessary to decode the QR code because it's only needed to calibrate the camera.
I am using openCV and when I tried to detect the QR code from the original downloaded picture of the QR code it works fine. That's the code I used:
bitmap= BitmapFactory.decodeResource(getResources(),R.drawable.qrcodemitzeugs);
Mat img =new Mat();
Utils.bitmapToMat(bitmap,img)
Mat points= new Mat();
QRCodeDetector detector=new QRCodeDetector();
boolean data = detector.detect(img, points);
But when I try the same Code on a photo taken with my smartphone's camera, the QR code doesn't get detected. I searched for a solution and found that maybe the contrast wasn't high enough so converted the picture into binary using following code:
Imgproc.cvtColor(img,img2,Imgproc.COLOR_BGR2GRAY);
Imgproc.threshold(img2,img2,100,255,Imgproc.THRESH_BINARY);
It returned the whole image in black and white but still the QR code wasn't detected.
Did I do something wrong or is there a solution for this problem?
One of the images i used
I had to resize the picture before uploading it
So I solved my problem, by resizing the Mat to a max of 1200x1200. Apparently the OpenCV QRCodeDetector can only handle Mats between ca. 85x85 and ca. 1200x1200, in which the QR Code itself has to have at least a size of ca. 80x80. I tested this with the image of the original QR Code, which had a size of 600x600. I resized it until the QR Code wasn't detected anymore.

QR code not detecting in image BarcodeDetector

I have implemented QR codes detection from an image using BarcodeDetector
BarcodeDetector detector = new BarcodeDetector.Builder(getApplicationContext())
.setBarcodeFormats(/*Barcode.DATA_MATRIX | Barcode.QR_CODE|*/Barcode.QR_CODE)
.build();
if (detector.isOperational()) {
Log.e("QR_READ", "Could not set up the detector!");
Frame frame = new Frame.Builder().setBitmap(pageBitmap).build();
QRCodeList = detector.detect(frame);
}
Here QRCodeList is empty but that image has QR code in it.
but some images are working with code but some are not detecting but those images I checked in online, those were working in that.
why that code not detecting QR code?
Maybe it's only a problem with those QRCodes which you are scanning. Try to use an online QRCode generator and check if it works for each QRCode you'll generate.
In addition , you could print the raw value returned from scanning.
This is Kotlin but you can convert it to Java . Something like that:
val rawScanValue: String = QRCodeList.valueAt(0).rawValue
// or toast or whatever
Log.d('RAWVALUE',rawScanValue)

Revert Barcode object to image in Android

I am getting Barcode(com.google.android.gms.vision.barcode) object from a physical sales card via camera. Is there a way to convert it back to a image using gms:play-services-vision library?
I think you will get barcode value in a string. you may try to below code
TextView tv = (TextView)findViewById(R.id.textview);
tv.setText(bitmapstring);
tv.buildDrawingCache();
ImageView img = (ImageView)findViewById(R.id.imageview);
img.setImageBitmap(tv.getDrawingCache());
Seems like there's no way of doing that by using the play-services-vision library. My first thought would be to take a screen capture of the preview of the camera before actually reading the barcode, but let's suppose you cannot do that.
If you have the actual data and the format of the barcode you can use ZXing to generate back the barcode image.
Here's an example of how to do it: Generate barcode image in Android application

Android Face Detection API - Stored video file

I would like to perform face detection / tracking on a video file (e.g. an MP4 from the users gallery) using the Android Vision FaceDetector API. I can see many examples on using the CameraSource class to perform face tracking on the stream coming directly from the camera (e.g. on the android-vision github), but nothing on video files.
I tried looking at the source code for CameraSource through Android Studio, but it is obfuscated, and I couldn't see the original online. I image there are many commonalities between using the camera and using a file. Presumably I just play the video file on a Surface, and then pass that to a pipeline.
Alternatively I can see that Frame.Builder has functions setImageData and setTimestampMillis. If I was able to read in the video as ByteBuffer, how would I pass that to the FaceDetector API? I guess this question is similar, but no answers. Similarly, decode the video into Bitmap frames and pass that to setBitmap.
Ideally I don't want to render the video to the screen, and the processing should happen as fast as the FaceDetector API is capable of.
Alternatively I can see that Frame.Builder has functions setImageData and setTimestampMillis. If I was able to read in the video as ByteBuffer, how would I pass that to the FaceDetector API?
Simply call SparseArray<Face> faces = detector.detect(frame); where detector has to be created like this:
FaceDetector detector = new FaceDetector.Builder(context)
.setProminentFaceOnly(true)
.build();
If processing time is not an issue, using MediaMetadataRetriever.getFrameAtTime solves the question. As Anton suggested, you can also use FaceDetector.detect:
Bitmap bitmap;
Frame frame;
SparseArray<Face> faces;
MediaMetadataRetriever mMMR = new MediaMetadataRetriever();
mMMR.setDataSource(videoPath);
String timeMs = mMMR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); // video time in ms
int totalVideoTime= 1000*Integer.valueOf(timeMs); // total video time, in uS
for (int time_us=1;time_us<totalVideoTime;time_us+=deltaT){
bitmap = mMMR.getFrameAtTime(time_us, MediaMetadataRetriever.OPTION_CLOSEST_SYNC); // extract a bitmap element from the closest key frame from the specified time_us
if (bitmap==null) break;
frame = new Frame.Builder().setBitmap(bitmap).build(); // generates a "Frame" object, which can be fed to a face detector
faces = detector.detect(frame); // detect the faces (detector is a FaceDetector)
// TODO ... do something with "faces"
}
where deltaT=1000000/fps, and fps is the desired number of frames per second. For example, if you want to extract 4 frames every second, deltaT=250000
(Note that faces will be overwritten on every iteration, so you should do something (store/report results) inside the loop

zxing not found exception in android

Hello everyone,
If any one of you can help me this. I am using zxing to decode barCode image, but it returns com.google.zxing.NotFoundException, don't know why. The same image gets decoded via Intent provided to zxing, but not when I use it to decode from image file.
The code that I am using is below :
mMultiFormatReader = new MultiFormatReader();
mMultiFormatReader.setHints(null);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(new RGBLuminanceSource(path)));
Result result = mMultiFormatReader.decodeWithState(bitmap);
I don't think it's exactly the same image, since you can't have it scan a file by Intent. I assume you mean that you can scan the image off your screen fine, but the image itself does not decode.
That's just life, really. Some images won't happen to decode. But you may try TRY_HARDER mode or use a different binarizer to see if that works.

Categories

Resources