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)
Related
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.
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.
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
I currently implemented ZBar QR Code Scanner Library into my own app. But, so far, I am just able to read a QR Code that leads to a website. What should I do if I want to scan a QR Code that leads you to dial a phone number or text messages? How do I make my app read any QR Code?
The content of the QR code should be irrelevant -- it's just text. It might happen to contain a URL, but that doesn't change the format of the QR code.
int result = imageScanner.scanImage(image);
// Nonzero means a result was found
if (result != 0) {
// Typical only one symbol unless multiple codes were found
// in the scanned image
for (Symbol symbol : imageScanner.getResults()) {
// .getData() gives the string content of the QR code
String qrCodeContent = symbol.getData();
}
}
I am using Zxing core.jar to scan bar codes and qr codes and it's working perfectly, but I want to make tests using Robolectric, to run automated tests without an emulator or device, that will take N number of images through zxing, so my problem is that zxing for some reason is not detecting any type of code format from the .jpg files, I'm not sure if there is a limit size on the image, or something else that I'm missing. The piece of code that does the detection is this, which works fine with frame previews converted to jpgs
BinaryBitmap bitmap = getBitmapFromImageData(input);
Collection<BarcodeFormat> decodeFormats = getDecodeFormats();
Map<DecodeHintType, Object> hints = getHints(decodeFormats);
MultiFormatReader multiFormatReader = getMultiFormatReader(hints);
Result rawResult;
try {
rawResult = multiFormatReader.decodeWithState(bitmap);
} catch (NotFoundException e) {
// not really an error, just QR code not found
Log.e(LOG_TAG, "Code Detection not found exception.");
return null;
}
Where the input contains the byte array in jpg format and is being converted by getBitmapFromImageData to Zxings internal formats. And like I said the library is working fine in the device, but I can't find any logical reason on why running this code from my pc won't work.
You're not showing any key code, like how you are reading your image. You should check whether it is being read correctly, being binarized correctly by your code, etc. Look at the unit tests in the project to see how to correctly read and process and image on the desktop. I don't know what your code may be doing in the "get" methods that is different.