> For the complete documentation index, see [llms.txt](https://easonwang.gitbook.io/web_advance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://easonwang.gitbook.io/web_advance/node.js-di-san-fang-mo-zu/opencv.md).

# OpenCV

<https://github.com/peterbraden/node-opencv>

安裝:

```
sudo yarn cache clean
brew cleanup
brew install pkg-config
brew install opencv@2
brew link --force opencv@2

echo 'export PATH="/usr/local/opt/opencv@2/bin:$PATH"' >> ~/.zshrc
yarn add opencv
```

範例：

```javascript
const cv = require('opencv');

cv.readImage("./test.jpg", function (err, im) {
  im.detectObject(cv.FACE_CASCADE, {}, function (err, faces) {
    for (var i = 0; i < faces.length; i++) {
      var x = faces[i]
      im.ellipse(x.x + x.width / 2, x.y + x.height / 2, x.width / 2, x.height / 2);
    }
    im.save('./out.jpg');
  });
})
```
