Skip to content

Instantly share code, notes, and snippets.

@samcorcos
Created February 26, 2017 19:05
Show Gist options
  • Save samcorcos/735c72d93644f6d8855dcd84df7077d0 to your computer and use it in GitHub Desktop.
Save samcorcos/735c72d93644f6d8855dcd84df7077d0 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
} from 'react-native';
import Camera from 'react-native-openalpr';
const styles = StyleSheet.create({
container: {
flex: 1,
},
textContainer: {
position: 'absolute',
top: 100,
left: 50,
},
text: {
textAlign: 'center',
fontSize: 20,
},
});
export default class PlateRecognizer extends React.Component {
constructor(props) {
super(props);
this.camera = null;
this.state = {
camera: {
aspect: Camera.constants.Aspect.fill,
},
plate: 'Scan a plate',
};
}
onPlateRecognized = ({ plate, confidence }) => {
if (confidence > 0.9) {
this.setState({
plate,
})
}
}
render() {
return (
<View style={styles.container}>
<Camera
ref={(cam) => { this.camera = cam }}
style={styles.container}
aspect={this.state.camera.aspect}
captureQuality={Camera.constants.CaptureQuality.medium}
onPlateRecognized={this.onPlateRecognized}
showPlateOutline
torchMode={Camera.constants.TorchMode.off}
touchToFocus
/>
<View style={styles.textContainer}>
<Text style={styles.text}>{this.state.plate}</Text>
</View>
</View>
);
}
}
@ccorcos
Copy link

ccorcos commented Mar 2, 2017

you're PlateRecognizer doesnt need to define a constructor function:

export default class PlateRecognizer extends React.Component {
  camera = null
  state = {
    camera: {
      aspect: Camera.constants.Aspect.fill,
    }
    plate: 'Scan a plate',
  }
  // ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment