pvl

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

README

Using the Intel Photography Vision Library

The Intel 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/pvl" package.

How to use

package main

import (
	"fmt"
	"image/color"

	"gocv.io/x/gocv"
	"gocv.io/x/gocv/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/pvl directory of this repo, in the form of some useful commands such as the smile detector.

How to install the Intel CV SDK

You will need to install various dependencies before you will be able to run the Intel CV SDK 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 CV SDK

The most recent version of the Intel CV SDK is currently Beta R3. You can obtain it from here:

https://software.intel.com/en-us/computer-vision-sdk

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 main Intel SDK env, by running the setupvars.sh program:

source /opt/intel/computer_vision_sdk_2017.1.163/bin/setupvars.sh

Then set the needed other exports for building/running GoCV code:

export CGO_CPPFLAGS="-I${INTEL_CVSDK_DIR}/opencv/include" 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"

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 the Intel CV SDK:

$ 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 CV SDK can be found in the cmd/pvl directory of this repository.

Documentation

Overview

Package pvl is the GoCV wrapper around the Intel Computer Vision (CV) SDK's Photography Vision Library (PVL).

For further details, please see: https://software.intel.com/en-us/cvsdk-devguide-advanced-face-capabilities-in-intels-opencv

Index

Constants

View Source
const UnknownFace = -10000

UnknownFace is when the FaceRecognizer cannot identify a Face.

Variables

This section is empty.

Functions

This section is empty.

Types

type Face

type Face struct {
	// contains filtered or unexported fields
}

Face is a wrapper around cv::pvl::Face.

func NewFace

func NewFace() Face

NewFace returns a new PVL Face.

func (*Face) Close

func (f *Face) Close() error

Close Face.

func (*Face) IsLeftEyeClosed

func (f *Face) IsLeftEyeClosed() bool

IsLeftEyeClosed checks if the right sys is closed or not.

func (*Face) IsRightEyeClosed

func (f *Face) IsRightEyeClosed() bool

IsRightEyeClosed checks if the right sys is closed or not.

func (*Face) IsSmiling

func (f *Face) IsSmiling() bool

IsSmiling Face? :) You must call FaceDetector's DetectEye() and DetectSmile() with this Face first, or this function will throw an exception.

func (*Face) LeftEyePosition

func (f *Face) LeftEyePosition() image.Point

LeftEyePosition of Face.

func (*Face) MouthPosition

func (f *Face) MouthPosition() image.Point

MouthPosition of Face.

func (*Face) Ptr

func (f *Face) Ptr() C.Face

Ptr returns the Face's underlying object pointer.

func (*Face) RIPAngle

func (f *Face) RIPAngle() int

RIPAngle of Face.

func (*Face) ROPAngle

func (f *Face) ROPAngle() int

ROPAngle of Face.

func (*Face) Rectangle

func (f *Face) Rectangle() image.Rectangle

Rectangle returns the image.Rectangle for this Face.

func (*Face) RightEyePosition

func (f *Face) RightEyePosition() image.Point

RightEyePosition of Face.

type FaceDetector

type FaceDetector struct {
	// contains filtered or unexported fields
}

FaceDetector is a wrapper around the cv::pvl::FaceDetector.

func NewFaceDetector

func NewFaceDetector() FaceDetector

NewFaceDetector returns a new PVL FaceDetector.

func (*FaceDetector) Close

func (f *FaceDetector) Close() error

Close FaceDetector.

func (f *FaceDetector) DetectBlink(img gocv.Mat, face Face)

DetectBlink uses PVL FaceDetector to detect blink on a Face.

func (*FaceDetector) DetectEye

func (f *FaceDetector) DetectEye(img gocv.Mat, face Face)

DetectEye uses PVL FaceDetector to detect eyes on a Face.

func (*FaceDetector) DetectFaceRect

func (f *FaceDetector) DetectFaceRect(img gocv.Mat) []Face

DetectFaceRect tries to detect Faces from the image Mat passed in as the param. The Mat must be a grayed image that has only one channel and 8-bit depth.

func (*FaceDetector) DetectMouth

func (f *FaceDetector) DetectMouth(img gocv.Mat, face Face)

DetectMouth uses PVL FaceDetector to detect mouth on a Face.

func (*FaceDetector) DetectSmile

func (f *FaceDetector) DetectSmile(img gocv.Mat, face Face)

DetectSmile uses PVL FaceDetector to detect smile on a Face.

func (*FaceDetector) GetBlinkThreshold added in v0.8.0

func (f *FaceDetector) GetBlinkThreshold() int

GetBlinkThreshold gets the threshold value used for evaluating blink.

func (*FaceDetector) GetMaxDetectableFaces added in v0.8.0

func (f *FaceDetector) GetMaxDetectableFaces() int

GetMaxDetectableFaces Returns the maximum number of detected faces.

func (*FaceDetector) GetMinFaceSize added in v0.8.0

func (f *FaceDetector) GetMinFaceSize() int

GetMinFaceSize gets the minimum face size in pixel.

func (*FaceDetector) GetRIPAngleRange added in v0.8.0

func (f *FaceDetector) GetRIPAngleRange() int

GetRIPAngleRange returns RIP(Rotation-In-Plane) angle range for face detection.

func (*FaceDetector) GetROPAngleRange added in v0.8.0

func (f *FaceDetector) GetROPAngleRange() int

GetROPAngleRange returns ROP(Rotation-Out-Of-Plane) angle range for face detection.

func (*FaceDetector) GetSmileThreshold added in v0.8.0

func (f *FaceDetector) GetSmileThreshold() int

GetSmileThreshold gets the threshold value used for evaluating smiles.

func (*FaceDetector) IsTrackingModeEnabled added in v0.8.0

func (f *FaceDetector) IsTrackingModeEnabled() bool

IsTrackingModeEnabled checks if the PVL FaceDetector tracking mode is enabled.

func (*FaceDetector) SetBlinkThreshold added in v0.8.0

func (f *FaceDetector) SetBlinkThreshold(thresh int)

SetBlinkThreshold sets the threshold value used for evaluating blink. When the blink score is equal or greater than this threshold, the eye is considered closing. Default value is 50.

func (*FaceDetector) SetMaxDetectableFaces added in v0.8.0

func (f *FaceDetector) SetMaxDetectableFaces(max int)

SetMaxDetectableFaces sets the maximum number of detected faces.

func (*FaceDetector) SetMinFaceSize added in v0.8.0

func (f *FaceDetector) SetMinFaceSize(min int)

SetMinFaceSize sets the minimum face size in pixel.

func (*FaceDetector) SetRIPAngleRange added in v0.8.0

func (f *FaceDetector) SetRIPAngleRange(rip int)

SetRIPAngleRange sets RIP(Rotation-In-Plane) angle range for face detection. Rotated faces within this angle range can be detected when detect method is invoked. If you specify small value for the range, Detection takes lesser time since it doesn't need to find much rotated faces. Default value is 135.

func (*FaceDetector) SetROPAngleRange added in v0.8.0

func (f *FaceDetector) SetROPAngleRange(rop int)

SetROPAngleRange sets ROP(Rotation-Out-Of-Plane) angle range for face detection. Rotated faces within this angle range can be detected when detect method is invoked. If you specify small value for the range, Detection takes lesser time since it doesn't need to find much rotated faces. Default value is 90.

func (*FaceDetector) SetSmileThreshold added in v0.8.0

func (f *FaceDetector) SetSmileThreshold(thresh int)

SetSmileThreshold sets the threshold value used for evaluating smiles. When the blink score is equal or greater than this threshold, the eye is considered smiling. Default value is 48.

func (*FaceDetector) SetTrackingModeEnabled

func (f *FaceDetector) SetTrackingModeEnabled(enabled bool)

SetTrackingModeEnabled sets if the PVL FaceDetector tracking mode is enabled.

type FaceRecognizer added in v0.8.0

type FaceRecognizer struct {
	// contains filtered or unexported fields
}

FaceRecognizer is a wrapper around the cv::pvl::FaceRecognizer.

func LoadFaceRecognizer added in v0.8.0

func LoadFaceRecognizer(name string) FaceRecognizer

LoadFaceRecognizer loads data from file and returns a FaceRecognizer.

func NewFaceRecognizer added in v0.8.0

func NewFaceRecognizer() FaceRecognizer

NewFaceRecognizer returns a new PVL FaceRecognizer.

func (*FaceRecognizer) Clear added in v0.8.0

func (f *FaceRecognizer) Clear()

Clear FaceRecognizer data.

func (*FaceRecognizer) Close added in v0.8.0

func (f *FaceRecognizer) Close() error

Close FaceRecognizer.

func (*FaceRecognizer) CreateNewPersonID added in v0.8.0

func (f *FaceRecognizer) CreateNewPersonID() int

CreateNewPersonID gets the next available ID from the PVL FaceRecognizer to be added to the database.

func (*FaceRecognizer) DeregisterFace added in v0.8.0

func (f *FaceRecognizer) DeregisterFace(faceID int64)

DeregisterFace deregisters the previously registered face from the internal database.

func (*FaceRecognizer) DeregisterPerson added in v0.8.0

func (f *FaceRecognizer) DeregisterPerson(personID int)

DeregisterPerson deregisters the previously registered person from the internal database.

func (*FaceRecognizer) Empty added in v0.8.0

func (f *FaceRecognizer) Empty() bool

Empty checks if FaceRecognizer has no data.

func (*FaceRecognizer) GetNumRegisteredPersons added in v0.8.0

func (f *FaceRecognizer) GetNumRegisteredPersons() int

GetNumRegisteredPersons gets the number of people in the current database.

func (*FaceRecognizer) Recognize added in v0.8.0

func (f *FaceRecognizer) Recognize(img gocv.Mat, faces []Face) (personIDs, confidences []int)

Recognize recognizes faces with the given image and face information.

func (*FaceRecognizer) RegisterFace added in v0.8.0

func (f *FaceRecognizer) RegisterFace(img gocv.Mat, face Face, personID int, saveToFile bool) int64

RegisterFace registers face information into the internal database.

func (*FaceRecognizer) Save added in v0.8.0

func (f *FaceRecognizer) Save(name string)

Save FaceRecognizer data to file.

func (*FaceRecognizer) SetTrackingModeEnabled added in v0.8.0

func (f *FaceRecognizer) SetTrackingModeEnabled(enabled bool)

SetTrackingModeEnabled sets if the PVL FaceRecognizer tracking mode is enabled.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL