In Android, Using ZXing we can scan a QR code through phone camera and decode it.
But, in my scenario, the QR code image is stored in the phone itself and I need to decode it.
Is there anyway to decode a QR image in this manner?
You can use ZXing code for this.
Check out DecodeHandler.java.
You can simply use the Mobile Vision API for decoding a QR Code from Image.It is very accurate and can detect more than one Qr code over image.
You have to include the following library inorder to use Mobile Vision API :
compile 'com.google.android.gms:play-services-vision:9.6.1'
BarcodeDetector detector =
new BarcodeDetector.Builder(context)
.setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE)
.build();
if(!detector.isOperational()){
Log.d("QR_READ","Could not set up the detector!");
}
Frame frame = new Frame.Builder().setBitmap(bitmap).build();
SparseArray<Barcode> barcodes = detector.detect(frame);
Log.d("QR_READ","-barcodeLength-"+barcodes.size());
Barcode thisCode=null;
if(barcodes.size()==0){
Log.d("QR_VALUE","--NODATA");
}
else if(barcodes.size()==1){
thisCode = barcodes.valueAt(0);
Log.d("QR_VALUE","--"+thisCode.rawValue);
}
else{
for(int iter=0;iter<barcodes.size();iter++) {
thisCode = barcodes.valueAt(iter);
Log.d("QR_VALUE","--"+thisCode.rawValue);
}
}
Related
I want to make an application where users can select 3 gallery images. After click next button a video will be created with these 3 photos and user can save this video to sd card.
Try using animation set in android that can help you achieve what you are after it is called FrameAnimation, here is an example on how to use it:
FrameAnimation Example
or checkout below code snippet if it helps :
` final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
int randomNum = random.nextInt(6);
dice.setImageResource(images[randomNum]);
handler.postDelayed(this, 500);
}
}, 500);`
You can use jcodec SequenceEncoder to convert sequence of images to MP4 file.
Sample code :
import org.jcodec.api.awt.SequenceEncoder;
...
SequenceEncoder enc = new SequenceEncoder(new File("filename"));
// GOP size will be supported in 0.2
// enc.getEncoder().setKeyInterval(25);
for(...) {
BufferedImage image = ... // Obtain an image to encode
enc.encodeImage(image);
}
enc.finish();
It's a java library so it's easy to import it into Android project, you don't have to use NDK unlike ffmpeg.
Refer http://jcodec.org/ for sample code & downloads.
According to Abhishek V
Look here to see more
I want to do that I have thousands of images on my phone and I want to fetch text from an image like below image: for example, i have above image on my phone and I want to fetch text "Sample Source Code" which is written in image. so how can we do that in android I have to try Google Vision API also gives sometimes correct text but sometimes not accurate. so is there any other option for this?
First you need to create a Demo for
Optical Character Recognition on Android – OCR
to fetch text from images.
Here posted some helpful links:-
1.Android OCR Library
2.https://github.com/abbyysdk/ocrsdk.com
3.http://www.truiton.com/2016/11/optical-character-recognition-android-ocr/
4.https://github.com/renard314/textfairy
5.https://github.com/rmtheis/android-ocr
6.https://github.com/priyankvex/Easy-Ocr-Scanner-Android
Many Examples you get from internet just Google it. hope this helps you.
try {
TextRecognizer txtRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();
if (!txtRecognizer.isOperational()) {
} else {
Frame frame = new Frame.Builder().setBitmap(bitmap).build();
SparseArray items = txtRecognizer.detect(frame);
StringBuilder strBuilder = new StringBuilder();
for (int i = 0; i < items.size(); i++) {
TextBlock item = (TextBlock) items.valueAt(i);
strBuilder.append(item.getValue());
}
Log.d("My Text : ", strBuilder.toString() + " okok");
}
} catch (Exception e) {
e.printStackTrace();
}
I am implementing an OCR scanning library for Android App which scans not just numbers but also scan those number with specific fonts which I have defined manually somewhere in library.
I am trying to implement "TESSERACT" library but didn't found font specific scanning implementation. I am using following code to scan OCR not a particular font. My implementation is given below:
private void processImage(Bitmap bMap, String imagePath) {
try {
datapath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tesseract/";
checkFile(new File(datapath + "tessdata/"));
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init(datapath, "eng");
baseApi.setImage(bMap);
String recognizedText = baseApi.getUTF8Text();
baseApi.end();
Log.e("log_tag", "onActivityResult recognizedText : " + recognizedText);
Fragment myFragment = getActiveFragment();
if (myFragment != null && myFragment.isVisible() && myFragment instanceof ScanPrescriptionFragment7c) {
((ScanPrescriptionFragment7c) myFragment).displaySelectedImage(recognizedText, imagePath);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Is there any way i can achieve font independent OCR implementation or atleast can provide a custom font to scan for during initialization of OCR?
Thanks!
I do not understand exactly why do you need to specify a font to recognize the characters, do you want to scan different languages or something like that?
I have been developing an Android app with OCR using Tesseract and I wrote down my conclusions and included an example in this post, have a look at it, might be useful to solve your case.
I want to print a code 128 barcode using the Zebra's EM 220 SDK for Android.
I tried to print it using the PrintBarcode() method like this :
BxlService bxl = new BxlService();
bxl.Connect(macAddress);
String data = "123589647525";
bxl.PrintBarcode(data.getBytes(), data.length(), BxlService.BXL_BCS_Code128, 100, 3, 0, BxlService.BXL_BC_TEXT_NONE);
bxl.Disconnect();
but the printed code can't be scanned by Android scan applications, like ZXing.
After searching on the web, I understood data had to be formatted (even if I am a little surprised Zebra SDK doesn't do that...) and found the barcode4j library that help to encode data. However, even with the library, the printed barcode can't be scanned.
BxlService bxl = new BxlService();
bxl.Connect(macAdress);
DefaultCode128Encoder dce = new DefaultCode128Encoder();
String data = "123456679857";
int[] i = dce.encode(data);
String barcode = "";
for (int j : i) {
barcode += j;
}
bxl.PrintBarcode(barcode.getBytes(), barcode.length(), BxlService.BXL_BCS_Code128, 100, 3, 0, BxlService.BXL_BC_TEXT_NONE);
bxl.Disconnect();
So, my question is simple : how to print code 128 barcode using the Zebra's EM 220 SDK for Android ?
Finally, I have found a workaround.
I use ZXing to encode my data, create a Bitmap with the barcode, save the Bitmap as a file before printing it with the printImage() method.
It works, but if someone knows how to use the printBarcode() method, I'd appreciate he tells me how to do.
I am implementing a QR code scanner for blackberry devices and I am using ZXing libraries to do so. This is for os 6+ by the way. The problem I am having is that sometimes, only sometimes, when the camera opens up to prepare scanning, the device will freeze and do a full reboot...
Otherwise it works most of the time, I am able to scan and decode the qr codes etc. However is just seems like it occasionally feels like crashing for no reason. I do not know if it is something with the camera or something in my code, but I will provide the code.
public void scanBarcode() {
// First we create a hashtable to hold all of the hints that we can
// give the API about how we want to scan a barcode to improve speed
// and accuracy.
Hashtable hints = new Hashtable();
// The first thing going in is a list of formats. We could look for
// more than one at a time, but it's much slower.
Vector formats = new Vector();
formats.addElement(BarcodeFormat.QR_CODE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
// We will also use the "TRY_HARDER" flag to make sure we get an
// accurate scan
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
// We create a new decoder using those hints
BarcodeDecoder decoder = new BarcodeDecoder(hints);
// Finally we can create the actual scanner with a decoder and a
// listener that will handle the data stored in the barcode. We put
// that in our view screen to handle the display.
try {
_scanner = new BarcodeScanner(decoder, new MyBarcodeDecoderListener());
_barcodeScreen = new MyBarcodeScannerViewScreen(_scanner);
} catch (Exception e) {
return;
}
// If we get here, all the barcode scanning infrastructure should be set
// up, so all we have to do is start the scan and display the viewfinder
try {
_scanner.stopScan();
_scanner.getPlayer().start();
_scanner.startScan();
UiApplication.getUiApplication().pushScreen(_barcodeScreen);
} catch (Exception e) {
}
}
/***
* MyBarcodeDecoderListener
* <p>
* This BarcodeDecoverListener implementation tries to open any data encoded
* in a barcode in the browser.
*
* #author PBernhardt
*
**/
private class MyBarcodeDecoderListener implements BarcodeDecoderListener {
public void barcodeDecoded(final String rawText) {
//UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
UtilityDecoder.saveToHistory(rawText);
try {
UtilityDecoder.distributeBarcode(rawText);
} catch (PIMException e) {
}
}
}
I basically call scanBarcode() when I click on a button on a toolbar.
Can anyone tell me if my code is the problem, or the device, or something else? Thanks in advance for any help provided!
Try this link:
Scan Any Type of Barcode Image which Supports Blackberry
See this forun link and see the discussions of that link. Surely, you will get overall concept of barcode scanning and you will also get the Implemention of QRCode in version 5.0
Any type of Barcode scaning in 5.0