Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/giacomocerquone/opencv-react

Hooks-first minimal OpenCV wrapper for React
https://github.com/giacomocerquone/opencv-react

hacktoberfest opencv react react-hooks

Last synced: 7 days ago
JSON representation

Hooks-first minimal OpenCV wrapper for React

Awesome Lists containing this project

README

        

# opencv-react

> Hooks-first minimal OpenCV wrapper for React.

[![NPM](https://img.shields.io/npm/v/opencv-react.svg)](https://www.npmjs.com/package/opencv-react) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

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

## Install

```bash
npm i opencv-react
```

or

```bash
yarn add opencv-react
```

## API

## `OpenCvProvider`

### Props

- **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](#description))

**Usage**:

```js
const MyApp = () => {
return (



)
}
```

## `useOpenCv`

### Context object

```
{
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)
}
```

```js
function MyComponent() {
const { loaded, cv } = useOpenCv()

useEffect(() => {
if (cv) {
}
}, [cv])

return

OpenCv React test


}
```

## Quick Start

```javascript
function MyComponent() {
const data = useOpenCv()
console.log(data)
return

OpenCv React test


}

const App = () => {
const onLoaded = (cv) => {
console.log('opencv loaded', cv)
}

return (



)
}
```

_*Check also the example folder*_

## Todo

- tests
- prop types
- index.d.ts

## Projects that uses this lib

WIP

## License

MIT © [giacomocerquone](https://github.com/giacomocerquone)