Skip to content

Commit

Permalink
openvino: adds support for Intel OpenVINO toolkit PVL
Browse files Browse the repository at this point in the history
Signed-off-by: Ron Evans <[email protected]>
  • Loading branch information
deadprogram committed May 16, 2018
1 parent 85ebac6 commit a55b480
Show file tree
Hide file tree
Showing 21 changed files with 210 additions and 175 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The GoCV package provides Go language bindings for the [OpenCV 3](http://opencv.

The GoCV package supports the latest releases of Go and OpenCV (v3.4) on Linux, OS X, and Windows. We intend to make the Go language a "first-class" client compatible with the latest developments in the OpenCV ecosystem.

GoCV also supports the [Intel Computer Vision SDK](https://software.intel.com/en-us/cvsdk-devguide) using the Photography Vision Library (PVL). Check out the [PVL README](./pvl/README.md) for more info on how to use GoCV with the Intel CV SDK.
GoCV also supports [Intel OpenVINO](https://software.intel.com/en-us/openvino-toolkit) by using the Photography Vision Library (PVL). Check out the [OpenVINO README](./openvino/pvl/README.md) for more info on how to use GoCV with the Intel OpenVINO toolkit.

## How to use

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// What it does:
//
// This example uses the Intel CV SDK PVL FaceDetect to detect faces,
// This example uses the Intel OpenVINO PVL FaceDetect to detect faces,
// then blurs them using a Gaussian blur before displaying in a window.
//
// How to run:
//
// faceblur [camera ID]
//
// go run ./cmd/pvl/faceblur/main.go 0
// go run ./cmd/openvino/pvl/faceblur/main.go 0
//
// +build example

Expand All @@ -20,7 +20,7 @@ import (
"strconv"

"gocv.io/x/gocv"
"gocv.io/x/gocv/pvl"
"gocv.io/x/gocv/openvino/pvl"
)

func main() {
Expand All @@ -41,7 +41,7 @@ func main() {
defer webcam.Close()

// open display window
window := gocv.NewWindow("PVL Faceblur")
window := gocv.NewWindow("OpenVINO PVL Faceblur")
defer window.Close()

// prepare input image matrix
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// What it does:
//
// This example uses the Intel CV SDK PVL FaceRecognizer to recognize people by their face.
// This example uses the Intel OpenVINO PVL FaceRecognizer to recognize people by their face.
// It first detects faces using the FaceDetector, then uses that information to try to identify
// them in the database.
//
Expand All @@ -13,7 +13,7 @@
//
// facerecognizer [camera ID] [face data file]
//
// go run ./cmd/pvl/facerecognizer/main.go 0 ./myfacedata.xml
// go run ./cmd/openvino/pvl/facerecognizer/main.go 0 ./myfacedata.xml
//
// +build example

Expand All @@ -27,7 +27,7 @@ import (
"strconv"

"gocv.io/x/gocv"
"gocv.io/x/gocv/pvl"
"gocv.io/x/gocv/openvino/pvl"
)

const (
Expand All @@ -54,7 +54,7 @@ func main() {
defer webcam.Close()

// open display window
window := gocv.NewWindow("PVL Face Recognizer")
window := gocv.NewWindow("OpenVINO PVL Face Recognizer")
defer window.Close()

// prepare input image matrix
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// What it does:
//
// This example uses the Intel CV SDK PVL FaceDetect class to detect smiles!
// This example uses the Intel OpenVINO toolkit's PVL FaceDetect class to detect smiles!
// It first detects faces, then detects the smiles on each. Based on if the person is
// smiling, it draws a green or blue rectangle around each of them,
// before displaying them within a Window.
Expand All @@ -9,7 +9,7 @@
//
// smiledetect [camera ID]
//
// go run ./cmd/pvl/smiledetect/main.go 0
// go run ./cmd/openvino/pvl/smiledetect/main.go 0
//
// +build example

Expand All @@ -23,7 +23,7 @@ import (
"strconv"

"gocv.io/x/gocv"
"gocv.io/x/gocv/pvl"
"gocv.io/x/gocv/openvino/pvl"
)

func main() {
Expand Down
77 changes: 77 additions & 0 deletions openvino/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Using the Intel OpenVINO toolkit

The Intel OpenVINO toolkit is a set of tools and libraries for computer vision applications. It also includes a complete build of OpenCV installed with the Intel OpenVINO. It uses computer vision and imaging algorithms developed at Intel.

GoCV support for the Intel OpenVINO Photography Vision Library (PVL) can be found here in the "gocv.io/x/gocv/openvino/pvl" package. Check out the README.md in the `pvl` directory for more information.

## How to install the Intel OpenVINO toolkit

You will need to install various dependencies before you will be able to run the Intel OpenVINO installer:

```
sudo apt-get update
sudo apt-get install build-essential ffmpeg cmake checkinstall pkg-config yasm libjpeg-dev curl imagemagick gedit mplayer unzip libpng12-dev libcairo2-dev libpango1.0-dev libgtk2.0-dev libgstreamer0.10-dev libswscale.dev libavcodec-dev libavformat-dev
```

### Installing OpenCL Support

If you also want to use the OpenCL support for GPU-based hardware acceleration, you must install the OpenCL runtime. First, install the dependencies:

```
sudo apt-get update
sudo apt-get install build-essential ffmpeg cmake checkinstall pkg-config yasm libjpeg-dev curl imagemagick gedit mplayer unzip libpng12-dev libcairo2-dev libpango1.0-dev libgtk2.0-dev libgstreamer0.10-dev libswscale.dev libavcodec-dev libavformat-dev
```

Next, obtain the OpenCL runtime package:

```
wget http://registrationcenter-download.intel.com/akdlm/irc_nas/11396/SRB5.0_linux64.zip
unzip SRB5.0_linux64.zip -d SRB5.0_linux64
cd SRB5.0_linux64
```

Last, install the OpenCL runtime:

```
sudo apt-get install xz-utils
mkdir intel-opencl
tar -C intel-opencl -Jxf intel-opencl-r5.0-63503.x86_64.tar.xz
tar -C intel-opencl -Jxf intel-opencl-devel-r5.0-63503.x86_64.tar.xz
tar -C intel-opencl -Jxf intel-opencl-cpu-r5.0-63503.x86_64.tar.xz
sudo cp -R intel-opencl/* /
sudo ldconfig
```

### Installing Intel OpenVINO toolkit

The most recent version of the Intel OpenVINO toolkit is currently R1. You can obtain it from here:

https://software.intel.com/en-us/openvino-toolkit

One you have downloaded the compressed file, unzip the contents, and then run the `install.sh` program within the extracted directory.

## How to build/run code

Setup the environment for the Intel OpenVINO toolkit, by running the `setupvars.sh` program included with OpenVINO:

```
source /opt/intel/computer_vision_sdk/bin/setupvars.sh
```

Then set the needed other exports for building/running GoCV code by running the `env.sh` that is in the GoCV `openvino` directory:

```
source openvino/env.sh
```

You only need to do these two steps one time per session. Once you have run them, you do not need to run them again until you close your terminal window.

Now you can run the version command example to make sure you are compiling/linking against Intel OpenVINO:

```
$ go run ./cmd/version/main.go
gocv version: 0.11.0
opencv lib version: 3.4.1-cvsdk_2018_1.0.5
```

Examples that use the Intel OpenVINO toolkit can be found in the `cmd/openvino` directory of this repository.
2 changes: 2 additions & 0 deletions openvino/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export CGO_CPPFLAGS="-I${INTEL_CVSDK_DIR}/opencv/include"
export CGO_LDFLAGS="-L${INTEL_CVSDK_DIR}/opencv/lib -lopencv_core -lopencv_pvl -lopencv_face -lopencv_videoio -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -lopencv_objdetect -lopencv_features2d -lopencv_video -lopencv_dnn -lopencv_xfeatures2d"
6 changes: 6 additions & 0 deletions openvino/openvino.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Package openvino is the GoCV wrapper around the Intel OpenVINO toolkit.
//
// For further details, please see:
// https://software.intel.com/en-us/openvino-toolkit
//
package openvino // import "gocv.io/x/gocv/openvino"
103 changes: 103 additions & 0 deletions openvino/pvl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Using the Intel OpenVINO Photography Vision Library

The Intel OpenVINO Photography Vision Library (PVL) is a set of extensions to OpenCV that is installed with the Intel CV SDK. It uses computer vision and imaging algorithms developed at Intel.

GoCV support for the PVL can be found here in the "gocv.io/x/gocv/openvino/pvl" package.

## How to use

```go
package main

import (
"fmt"
"image/color"

"gocv.io/x/gocv"
"gocv.io/x/gocv/openvino/pvl"
)

func main() {
deviceID := 0

// open webcam
webcam, err := gocv.VideoCaptureDevice(int(deviceID))
if err != nil {
fmt.Printf("error opening video capture device: %v\n", deviceID)
return
}
defer webcam.Close()

// open display window
window := gocv.NewWindow("PVL")

// prepare input image matrix
img := gocv.NewMat()
defer img.Close()

// prepare grayscale image matrix
imgGray := gocv.NewMat()
defer imgGray.Close()

// color to draw the rect for detected faces
blue := color.RGBA(0, 0, 255, 0)

// load PVL FaceDetector to recognize faces
fd := pvl.NewFaceDetector()
defer fd.Close()

// enable tracking mode for more efficient tracking of video source
fd.SetTrackingModeEnabled(true)

fmt.Printf("start reading camera device: %v\n", deviceID)
for {
if ok := webcam.Read(&img); !ok {
fmt.Printf("cannot read device %d\n", deviceID)
return
}
if img.Empty() {
continue
}

// convert image to grayscale for detection
gocv.CvtColor(img, &imgGray, gocv.ColorBGR2GRAY);

// detect faces
faces := fd.DetectFaceRect(imgGray)
fmt.Printf("found %d faces\n", len(faces))

// draw a rectangle around each face on the original image
for _, face := range faces {
gocv.Rectangle(&img, face.Rectangle(), blue, 3)
}

// show the image in the window, and wait 1 millisecond
window.IMShow(img)
window.WaitKey(1)
}
}
```

Some PVL examples are in the [cmd/openvino/pvl directory](../cmd/openvino/pvl) of this repo, in the form of some useful commands such as the [smile detector](../cmd/openvino/pvl/smiledetector).

## How to build/run code

Setup the environment for the Intel OpenVINO toolkit, by running the `setupvars.sh` program included with OpenVINO:

```
source /opt/intel/computer_vision_sdk/bin/setupvars.sh
```

Then set the needed other exports for building/running GoCV code by running the `env.sh` that is in the GoCV `openvino` directory:

You only need to do these two steps one time per session. Once you have run them, you do not need to run them again until you close your terminal window.

Now you can run the version command example to make sure you are compiling/linking against Intel OpenVINO:

```
$ go run ./cmd/version/main.go
gocv version: 0.7.0
opencv lib version: 3.3.1-cvsdk_2017_R3.2
```

Examples that use the Intel OpenVINO toolkit can be found in the `cmd/openvino/pvl` directory of this repository.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pvl/face.h → openvino/pvl/face.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
extern "C" {
#endif

#include "../core.h"
#include "../../core.h"

#ifdef __cplusplus
typedef cv::pvl::Face* Face;
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pvl/face_detector.h → openvino/pvl/face_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
extern "C" {
#endif

#include "../core.h"
#include "../../core.h"
#include "face.h"

#ifdef __cplusplus
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pvl/face_recognizer.h → openvino/pvl/face_recognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
extern "C" {
#endif

#include "../core.h"
#include "../../core.h"
#include "face.h"

#ifdef __cplusplus
Expand Down
7 changes: 7 additions & 0 deletions openvino/pvl/pvl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Package pvl is the GoCV wrapper around the Intel OpenVINO toolkit's
// Photography vision Library (PVL).
//
// For further details, please see:
// https://software.intel.com/en-us/openvino-toolkit
//
package pvl // import "gocv.io/x/gocv/openvino/pvl"
File renamed without changes.
Loading

0 comments on commit a55b480

Please sign in to comment.