Concentramos todo nuestros esfuerzos y conocimientos para proyectar tus ideas en Diseño y Desarrollo Web y Móvil Responsive. Idea + Desarrollo + Diseño = Producto Genial ¿Hablamos?
https://bouncingshield.com
React Native OCR Scanner Card2Contact
This is a demo study app for making an ocr scanner for business cards and store the info in the contacts list of the phone. In this case I will only target iOS system but this can be done for Android also. I’m calling this app Card2Contact and this is part of Bouncing Shield Explorations
The main packages we will need are the one for reading images form the camera (react-native-camera)
Creating base React Native App
react-native init Card2Contact
Install dependencies
yarn add react-native-camera --save
Configure react-native-camera package
react-native link react-native-camera
For iOS we have to set the permissions.
In the Info.plist file add the description for NSCameraUsageDescription key. It is required by Apple and it says why you need to access the camera.
You also need NSPhotoLibraryUsageDescription key to store the picture in the phone library.
Basic Camera Component Screen
Add Navigation to show photo screen for processing
yarn add react-navigation --saveyarn add react-native-gesture-handler --savereact-native link react-native-gesture-handler
Re-organize code to add navigation
App.js
CameraScreen.js
ContactScreen.js
Using Google Cloud Vision API to extract data from photo
Google has a great API for detecting text and extracting (OCR) that we can use for this purpose. For using this API you need to create a Google Cloud Platform (GCP) project
Go to the web page and create a new project
After that, go to your project and create an credential API to use in your React Native Project
Copy your API key and store it in a safe place
Lets add the Vision API for this project
Look for the Vision API and click ENABLE
Remember to enable Billing for the projects as it is REQUIRED
Code for detecting text
Lets modify the code in the CameraScreen.js file and add a new method to connect with Google Vision API.
The API endpoint for Google Vision is https://vision.googleapis.com/v1/images:annotate And you need to pass the key for authenticate.
CameraScreen.js
ConatctScreen.js
Creating Contact View Form
Lets display the list of text returned by the Google API and along with it a form to choose the type of text to classify it for the contact.
npm install react-native-picker-select
And also add a button on the bottom to save the info.
Using Contact package to save contact info
npm install react-native-contacts --savereact-native link
Add kit specific “permission” keys to your Xcode Info.plist file, in order to make requestPermission work. Otherwise your app crashes when requesting the specific permission.
npm install react-native-contacts --savereact-native link
Add kit specific “permission” keys to your Xcode Info.plist file, in order to make requestPermission work. Otherwise your app crashes when requesting the specific permission.
Open Xcode > open ios/yourApp.xcodeproj > Info.plist > Add key Privacy - Contacts Usage Description with your kit specific permission. The value for the key is optional in development. If you submit to the App Store the value must explain why you need this permission.