Created
February 26, 2017 19:05
-
-
Save samcorcos/735c72d93644f6d8855dcd84df7077d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you're
PlateRecognizer
doesnt need to define a constructor function: