$ npm install react-native-opencv3 --save
$ react-native link react-native-opencv3
Add to Podfile ->
pod 'RNOpencv3', :podspec => '../node_modules/react-native-opencv3/ios/RNOpencv3.podspec'
$ pod install
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-opencv3
and addRNOpencv3.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNOpencv3.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import org.opencvport.RNOpencv3Package;
to the imports at the top of the file - Add
new RNOpencv3Package()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-opencv3' project(':react-native-opencv3').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-opencv3/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-opencv3')
import {RNCv} from 'react-native-opencv3';
// Basic convert input jpg or png to grayscale
RNCv.cvtColorGray(inFile, outFile)
.then((image) => {
const { width, height, uri } = image
console.log('width is: ' + width + 'height is: ' + height + ' uri is: ' + uri)
})
.error((err) => {
console.error(err)
})
import React, {Component} from 'react';
import {StyleSheet, View} from 'react-native';
import {CvCamera} from 'react-native-opencv3';
type Props = {};
export default class App extends Component<Props> {
render() {
const { type } = 'back';
return (
<View
style={styles.preview}
>
<CvCamera
style={styles.preview}
type={type}
/>
</View>
);
}
}
const styles = StyleSheet.create({
preview: {
flex: 1
},
});