Hooks-first minimal OpenCV wrapper for React.
It simplifies the import of this library and integrates it well with the React ecosystem.
Bear in mind that the loading of the library, being huge, is done asynchronously. Of course you can listen with this lib when the loading has finished in order to execute some setup code.
You have also access to a loaded
state which is provided by the OpenCvProvider
component
npm i opencv-react
or
yarn add opencv-react
- openCvPath: string used to indicate where to load the OpenCv lib from (default to official cdn)
- onLoad: function that gets called whenever the library has finished loading (see the package description)
Usage:
const MyApp = () => {
return (
<OpenCvProvider>
<MyComponent />
</OpenCvProvider>
)
}
{
loaded: boolean, indicates if the opencv library is loaded (useful to show a spinner)
cv: undefined or the OpenCV global instance (can also be found in window.cv)
}
function MyComponent() {
const { loaded, cv } = useOpenCv()
useEffect(() => {
if (cv) {
}
}, [cv])
return <p>OpenCv React test</p>
}
function MyComponent() {
const data = useOpenCv()
console.log(data)
return <p>OpenCv React test</p>
}
const App = () => {
const onLoaded = (cv) => {
console.log('opencv loaded', cv)
}
return (
<OpenCvProvider onLoad={onLoaded} openCvPath='/opencv/opencv.js'>
<MyComponent />
</OpenCvProvider>
)
}
Check also the example folder
- tests
- prop types
- index.d.ts
WIP
MIT © giacomocerquone