Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Machine Learning Projects for Mobile Applications

You're reading from  Machine Learning Projects for Mobile Applications

Product type Book
Published in Oct 2018
Publisher Packt
ISBN-13 9781788994590
Pages 246 pages
Edition 1st Edition
Languages
Author (1):
Karthikeyan NG Karthikeyan NG
Profile icon Karthikeyan NG
Toc

Barcode scanner


Let's now jump into implementing a mobile-based barcode scanner using ML Kit. There are many formats for barcodes. ML Kit supports all the following listed formats:

Once the barcode is identified on the camera view, the draw method puts the bounding box on top of it, along with the detected barcode's raw value. The following code draws the barcode block annotations for position, size, and raw value on the supplied canvas:

/**
 * Draws the barcode block annotations
*/
@Override
public void draw(Canvas canvas) {
if (barcode == null) {
throw new IllegalStateException("Attempting to draw a null 
                                     barcode.");
}

// Draws the bounding box around the BarcodeBlock.
RectF rect = new RectF(barcode.getBoundingBox());
rect.left = translateX(rect.left);
rect.top = translateY(rect.top);
rect.right = translateX(rect.right);
rect.bottom = translateY(rect.bottom);
canvas.drawRect(rect, rectPaint);

// Renders the barcode at the bottom of the box.
canvas.drawText...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime