Skip to content

Commit 71d5723

Browse files
committed
Update readme
Add Travis badge, replace old links, fix example, remove linking section for iOS
1 parent 2d45e4e commit 71d5723

File tree

2 files changed

+83
-90
lines changed

2 files changed

+83
-90
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ script:
6565
- |
6666
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
6767
cd $TRAVIS_BUILD_DIR/example/android
68+
pwd
69+
ls -la
70+
chmod +x /.gradlew
6871
TERM=dumb ./gradlew assemble
6972
fi
7073
deploy:

README.md

Lines changed: 80 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
[![Build Status](https://travis-ci.com/RobertSasak/react-native-openalpr.svg?branch=master)](https://travis-ci.com/RobertSasak/react-native-openalpr)
2+
13
# react-native-openalpr
24

3-
[OpenALPR](https://github.com/openalpr/openalpr) integration for React Native. Provides a camera component that recognizes license plates in real-time. Supports both iOS and Android.
5+
[OpenALPR](https://github.com/openalpr/openalpr) integration for React Native. Provides a camera component that recognizes license plates in real-time. Supports both iOS and Android.
46

57
<img alt="OpenALPR iOS Demo Video" src="https://cdn-images-1.medium.com/max/800/1*u1nTJMFc34aDLTPCIr0-cQ.gif" width=200 height=350 /> <img alt="OpenALPR Android Demo Video" src="https://user-images.githubusercontent.com/10334791/27850595-62dc852e-615e-11e7-875c-57a017dbb28c.gif" width=200 height=350 />
68

79
## Requirements
10+
811
- iOS 9+
912
- Android 5.0+
10-
- RN 0.41+
13+
- RN 0.60+
1114

1215
## Installation
1316

@@ -17,20 +20,18 @@ Start by adding the package and linking it.
1720

1821
```sh
1922
$ yarn add react-native-openalpr
20-
$ react-native link react-native-openalpr
2123
```
2224

23-
or if you are using npm:
25+
### iOS Specific Setup
26+
27+
#### Install pods
2428

2529
```sh
26-
$ npm i -S react-native-openalpr
27-
$ react-native link react-native-openalpr
30+
$ cd ios && pod install && cd ...
2831
```
29-
Unfortunately, the `react-native link` command does not do everything it needs to do, so continue on to the project specific instructions below.
30-
31-
### iOS Specific Setup
3232

3333
#### Camera Permissions
34+
3435
- Add an entry for `NSCameraUsageDescription` in your `info.plist` explaining why your app will use the camera. If you forget to add this, your app will crash!
3536

3637
```xml
@@ -44,30 +45,18 @@ Unfortunately, the `react-native link` command does not do everything it needs t
4445
</dict>
4546
```
4647

47-
#### Linking
48-
The project needs to be linked against four libraries: leptonica, opencv, tesseract, and openalpr.
49-
- In Xcode, open your project (`.xcodeproj`).
50-
- Go to `File -> Add Files` (or `Option + Command + A`)
51-
- Click the `Options` button on the bottom and tick the `Copy items if needed` option.
52-
- Add all four frameworks (leptonica, opencv, tesseract, openalpr) from the `node_modules/react-native-openalpr/ios/Frameworks`. This should cause the project to add a framework search path to the project's build settings (e.g. `$(PROJECT_DIR)/../node_modules/react-native-openalpr/ios/Frameworks`).
53-
- Ensure that all four frameworks are included in the `Link Binary With Libraries` build phase by selecting your project in the tray on the left, selecting the `Build Phases` tab, then checking that each framework is included in the list of `Link Binary With Libraries`.
54-
55-
#### Resources
56-
The alpr library requires a config file (`openalpr.conf`) and a data folder (`runtime_data`), both of which are included in the openalpr framework, but must be copied to the application resources:
57-
- Select your project on the project navigator, then, on the main pane, go to `Targets``<Your Project>``Build Phases``Copy Bundle Resources`, and click on the `+`.
58-
- Select `Add Other...`
59-
- Browse *into* the `openalpr.framework` bundle, and command-select both `runtime_data` and `openalpr.conf`. Unselect `Copy items if needed` and select `Create folder references`.
60-
6148
#### Bitcode
62-
Because the OpenCV binary framework release is compiled without bitcode, the other frameworks built by this script are also built without it, which ultimately means your Xcode project also cannot be built with bitcode enabled. [Per this message](http://stackoverflow.com/a/32728516/868173), it sounds like we want this feature disabled for OpenCV anyway.
49+
50+
Because the OpenCV binary framework release is compiled without bitcode, the other frameworks built by this script are also built without it, which ultimately means your Xcode project also cannot be built with bitcode enabled. [Per this message](http://stackoverflow.com/a/32728516/868173), it sounds like we want this feature disabled for OpenCV anyway.
6351

6452
To disable bitcode in your project:
6553

66-
- In `Build Settings``Build Options`, search for `Enable Bitcode` and set it to `No`.
54+
- In `Build Settings``Build Options`, search for `Enable Bitcode` and set it to `No`.
6755

68-
## Android-specific Setup
56+
### Android-specific Setup
6957

7058
#### Camera Permissions
59+
7160
- Add permissions for `CAMERA` and `FLASHLIGHT` and the related features (below) to `AndroidManifest.xml`. If you forget to add these permissions, your app will crash!
7261

7362
```xml
@@ -86,7 +75,8 @@ To disable bitcode in your project:
8675
```
8776

8877
#### Add to Gradle
89-
###### Your `android/settings.gradle` file should have following lines:
78+
79+
###### Your `android/settings.gradle` file should have following lines:
9080

9181
```java
9282

@@ -99,35 +89,36 @@ project(':react-native-openalpr').projectDir = new File(rootProject.projectDir,
9989

10090
```
10191

102-
###### and `android/app/build.gradle` file should have the following under dependencies:
103-
`compile project(':react-native-openalpr')`
92+
###### and `android/app/build.gradle` file should have the following under dependencies:
93+
94+
`compile project(':react-native-openalpr')`
10495

10596
#### Linking
97+
10698
The library is linked automatically with leptonica, opencv, tesseract, and openalpr ([openalpr](https://github.com/SandroMachado/openalpr-android)).
10799
To make it work, copy and paste the directory with the runtime needed data to your project at path `android/app/src/main/assets/runtime_data`.
108100

109101
The `runtime_data` file can be found in `/Example/android/app/src/main/assets/` in this repo. Open `runtime_data/openalpr.conf` file and replace `com.awesomeproject` with your package name
110102

111103
#### Add to an Activity
112-
Open your activity, usually located in `android/app/src/main/java/[your package]/MainApplication.java`.
113-
Add `import com.cardash.openalpr.CameraReactPackage;` to the imports at the top of the file.
114-
Add `new CameraReactPackage()` to the list returned by the `getPackages()` method.
104+
105+
Open your activity, usually located in `android/app/src/main/java/[your package]/MainApplication.java`.
106+
Add `import com.cardash.openalpr.CameraReactPackage;` to the imports at the top of the file.
107+
Add `new CameraReactPackage()` to the list returned by the `getPackages()` method.
115108

116109
## Usage
117110

118111
OpenALPR exposes a camera component (based on [react-native-camera](https://github.com/lwansbrough/react-native-camera)) that is optimized to run OpenALPR image processing on a live camera stream. Among other parameters, the camera accepts a callback, `onPlateRecognized`, for when a plate is recognized.
119112

120113
```js
121-
import React, { Component } from 'react';
122-
import {
123-
AppRegistry,
124-
StyleSheet,
125-
Text,
126-
View,
127-
StatusBar,
128-
} from 'react-native';
114+
import React, { Component } from 'react'
115+
import { StyleSheet, Text, View } from 'react-native'
129116

130-
import Camera from 'react-native-openalpr';
117+
import Camera, {
118+
Aspect,
119+
CaptureQuality,
120+
TorchMode,
121+
} from 'react-native-openalpr'
131122

132123
const styles = StyleSheet.create({
133124
container: {
@@ -142,74 +133,63 @@ const styles = StyleSheet.create({
142133
textAlign: 'center',
143134
fontSize: 20,
144135
},
145-
});
136+
})
146137

147138
export default class PlateRecognizer extends React.Component {
148-
constructor(props) {
149-
super(props);
150-
151-
this.camera = null;
152-
this.state = {
153-
camera: {
154-
aspect: Camera.constants.Aspect.fill,
155-
},
156-
plate: 'Scan a plate',
157-
};
139+
state = {
140+
plate: 'Scan a plate',
158141
}
159142

160143
onPlateRecognized = ({ plate, confidence }) => {
161-
if (confidence > 90) {
162-
this.setState({
163-
plate,
164-
})
165-
}
144+
this.setState({
145+
plate,
146+
})
166147
}
167148

168149
render() {
169150
return (
170151
<View style={styles.container}>
171152
<Camera
172-
ref={(cam) => {
173-
this.camera = cam;
174-
}}
175153
style={styles.preview}
176-
aspect={this.state.camera.aspect}
177-
captureQuality={Camera.constants.CaptureQuality.medium}
154+
aspect={Aspect.fill}
155+
captureQuality={CaptureQuality.medium}
178156
country="us"
179157
onPlateRecognized={this.onPlateRecognized}
180158
plateOutlineColor="#ff0000"
181159
showPlateOutline
182-
torchMode={Camera.constants.TorchMode.off}
160+
torchMode={TorchMode.off}
183161
touchToFocus
184162
/>
185163
<View style={styles.textContainer}>
186164
<Text style={styles.text}>{this.state.plate}</Text>
187165
</View>
188166
</View>
189-
190-
);
167+
)
191168
}
192169
}
193-
194-
AppRegistry.registerComponent('PlateRecognizer', () => PlateRecognizer);
195-
196170
```
197171

198172
### Options
199173

200174
#### `aspect`
175+
201176
The aspect ratio of the camera. Can be one of:
202-
- `Camera.constants.Aspect.stretch`
203-
- `Camera.constants.Aspect.fit`
204-
- `Camera.constants.Aspect.fill`
177+
178+
- `Aspect.stretch`
179+
- `Aspect.fit`
180+
- `Aspect.fill`
205181

206182
#### `captureQuality`
183+
207184
The resolution at which video frames are captured and analyzed. For completeness, several options are provided. However, it is strongly recommended that you stick with one of the following for the best frame rates and accuracy:
208-
- `Camera.constants.CaptureQuality.medium` (480x360)
209-
- `Camera.constants.CaptureQuality.480p` (640x480)
185+
186+
- `CaptureQuality.medium` (480x360)
187+
- `CaptureQuality.480p` (640x480)
210188

211189
#### `country`
190+
212191
Specifies which OpenALPR config file to load, corresponding to the country whose plates you wish to recognize. Currently supported values are:
192+
213193
- `au`
214194
- `br`
215195
- `eu`
@@ -222,57 +202,67 @@ Specifies which OpenALPR config file to load, corresponding to the country whose
222202
- `vn2`
223203

224204
#### `onPlateRecognized`
205+
225206
This callback receives a hash with keys:
226-
- `plate`, representing the recognized license plate string; and
227-
- `confidence`, OpenALPR's confidence in the result
207+
208+
- `plate`, representing the recognized license plate string
209+
- `confidence`, OpenALPR's confidence(%) in the result
228210

229211
#### `plateOutlineColor`
212+
230213
Hex string specifying the color of the border to draw around the recognized plate. Example: `#ff0000` for red.
231214

232215
#### `showPlateOutline`
216+
233217
If true, this draws an outline over the recognized plate
234218

235219
#### `torchMode`
220+
236221
Turns the flashlight on or off. Can be one of:
237-
- `Camera.constants.TorchMode.on`
238-
- `Camera.constants.TorchMode.off`
239-
- `Camera.constants.TorchMode.auto`
222+
223+
- `TorchMode.on`
224+
- `TorchMode.off`
225+
- `TorchMode.auto`
240226

241227
#### `touchToFocus`
228+
242229
If true, this focuses the camera where the user taps
243230

244231
## Examples
245-
- [Example Project](https://github.com/cardash/react-native-openalpr/tree/master/Example)
232+
233+
- [Example Project](https://github.com/RobertSasak/react-native-openalpr/tree/master/example)
246234

247235
## Development
248-
- This project works with iOS and Android. It may have some bugs depending on how the underlying native components are updated
236+
237+
- This project works with iOS and Android. It may have some bugs depending on how the underlying native components are updated
249238

250239
### Running the Example project on Android While Developing
251240

252-
1) Clone the repo and enter the `Example` directory
241+
1. Clone the repo and enter the `example` directory
253242

254243
```ssh
255-
git clone https://github.com/cardash/react-native-openalpr.git
244+
git clone https://github.com/RobertSasak/react-native-openalpr.git
256245
cd react-native-openalpr
257-
cd Example
246+
cd example
258247
```
259248

260-
2) From the `Example` directory, run `npm install`
249+
2. From the `example` directory, run `yarn`
261250

262-
3) Copy the `android` folder from `/react-native-openalpr/android` to `/react-native-openalpr/Example/node_modules/react-native-openalpr/`
251+
3. Copy the `android` folder from `/react-native-openalpr/android` to `/react-native-openalpr/Example/node_modules/react-native-openalpr/`
263252

264-
4) Open Android Studio and import the project `react-native-openalpr/Example/android` and wait until Android Studio indexes and links.
253+
4. Open Android Studio and import the project `react-native-openalpr/Example/android` and wait until Android Studio indexes and links.
265254

266-
5) Run `npm start` from dir /react-native-openalpr/Example/
255+
5. Run `npm start` from dir /react-native-openalpr/Example/
267256

268-
6) Open the path in your browser `http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false`
257+
6. Open the path in your browser `http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false`
269258

270-
7) Create file the `/react-native-openalpr/Example/android/app/src/main/assets/index.android.bundle`. Copy and paste the data from browser window to the file you just created and save.
259+
7. Create file the `/react-native-openalpr/Example/android/app/src/main/assets/index.android.bundle`. Copy and paste the data from browser window to the file you just created and save.
271260

272-
8) Return to Android Studio and run project on your development device.
261+
8. Return to Android Studio and run project on your development device.
273262

274263
Note: If you are getting errors, double check that you have completed all of the steps above. If you are having issues running `npm start` on Mac OSX and are using homebrew, [this issue might help](https://github.com/facebook/react-native/issues/910).
275264

276265
## Credits
266+
277267
- OpenALPR built from [OpenALPR-iOS](https://github.com/twelve17/openalpr-ios)
278268
- Project scaffold based on [react-native-camera](https://github.com/lwansbrough/react-native-camera)

0 commit comments

Comments
 (0)