tfimage

package module
v0.0.0-...-b7b8866 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 13 Imported by: 0

README

tfImage

Work in progress

  • Face detection (MTCNN)
  • Image aesthetics (NIMA)

Example Code

See cmd/main.go

Install Tensorflow v1.14

Warning: This tensorflow binary is CPU only and doesnt support AVX2 and FMA

sudo curl -L https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.14.0.tar.gz | sudo tar xz --directory /usr/local sudo ldconfig

go get github.com/tensorflow/tensorflow/tensorflow/go@v1.14.0

Documentation

Index

Constants

View Source
const (
	ErrLoadFile string = "Unable to Load MTCNN model file: %v\n"
)

Errors

Variables

This section is empty.

Functions

func SaveJPG

func SaveJPG(path string, im image.Image, quality int) error

SaveJPG - Save image to JPG

func TensorFromJpeg

func TensorFromJpeg(bytes []byte) (*tf.Tensor, error)

TensorFromJpeg - Decode a JPEG image into RGB channels in a tensor

Types

type AestheticsEvaluator

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

Evaluator - Evaluator for aesthetic image quality. Uses a MobileNet modified CNN trained from: https://github.com/idealo/image-quality-assessment/ Apache 2.0 License

func NewAestheticsEvaluator

func NewAestheticsEvaluator(modelFile string) (*AestheticsEvaluator, error)

NewAestheticsEvaluator - Creates a new Aesthetics Evaluator

func (*AestheticsEvaluator) Close

func (eval *AestheticsEvaluator) Close()

Close closes the Aesthetics Evaluator's Session

func (*AestheticsEvaluator) Run

func (eval *AestheticsEvaluator) Run(tensor *tf.Tensor) (score float32, err error)

type Face

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

Face

func (*Face) AffineMatrix

func (f *Face) AffineMatrix(width, height uint16) Matrix

AffineMatrix builds a Face Warp Affine Matrix

func (Face) Angle

func (f Face) Angle() float64

Angle caculates the angle of the face using the LeftEye and RightEye returns radians

func (Face) EyesCenter

func (f Face) EyesCenter() (x float64, y float64)

EyesCenter returns the (x,y) center between the eyes

func (Face) LeftEye

func (f Face) LeftEye() (x float64, y float64)

LeftEye returns the (x,y) of the left eye

func (Face) LeftMouth

func (f Face) LeftMouth() (x float64, y float64)

LeftMouth returns the (x,y) of the left corner of the mouth

func (Face) Nose

func (f Face) Nose() (x float64, y float64)

Nose returns the (x,y) center of the nose

func (Face) RightEye

func (f Face) RightEye() (x float64, y float64)

RightEye returns the (x,y) of the right eye

func (Face) RightMouth

func (f Face) RightMouth() (x float64, y float64)

RightMouth returns the (x,y) of the right corner of the mouth

func (Face) Size

func (f Face) Size() (width int, height int)

Size returns the width and height of the face in the source image

func (Face) String

func (f Face) String() string

func (Face) ToImage

func (f Face) ToImage(srcImage image.Image, kernel draw.Interpolator, width uint16, height uint16) image.Image

ToImage transforms an image by the matrix and returns the face image

type FaceDetector

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

FaceDetector - Detector for faces in an image based on an MTCNN model. Uses a Multi-task Cascaded Convolutional Network Detector trained from: https://kpzhang93.github.io/MTCNN_face_detection_alignment/

func NewFaceDetector

func NewFaceDetector(modelFile string, options FaceDetectorOptions) (*FaceDetector, error)

NewFaceDetector - Create a New FaceDetector from a model file

func (*FaceDetector) Close

func (det *FaceDetector) Close()

Close - Close a FaceDetector Session

func (*FaceDetector) DetectFaces

func (det *FaceDetector) DetectFaces(tensor *tf.Tensor) (*FaceResults, error)

DetectFaces runs the tensorflow detection session and outputs a FacesResults

type FaceDetectorOptions

type FaceDetectorOptions struct {
	MinimumSize int
	FaceWidth   int
	FaceHeight  int
}

FaceDetectorOptions -

type FaceResults

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

func (*FaceResults) DrawDebugJPEG

func (fr *FaceResults) DrawDebugJPEG(path string, src image.Image) error

func (FaceResults) Len

func (fr FaceResults) Len() int

func (FaceResults) String

func (fr FaceResults) String() string

func (FaceResults) ToJPEG

func (fr FaceResults) ToJPEG(src image.Image, kernel draw.Interpolator, width uint16, height uint16, fn func(image.Image) error) (err error)

type Matrix

type Matrix struct {
	XX, YX, XY, YY, X0, Y0 float64
}

Matrix -

func NewMatrix

func NewMatrix() Matrix

NewMatrix - Create a new Matrix

func Rotate

func Rotate(angle float64) Matrix

Rotate New Matrix by x and y

func RotationMatrix2D

func RotationMatrix2D(centerX, centerY float64, angle, scale float64) Matrix

RotationMatrix2D creates a Rotation and Transformation Matrix. This is similiar to OpenCV's function. Angle in Radians

func Scale

func Scale(x, y float64) Matrix

Scale New Matrix by x and y

func Shear

func Shear(x, y float64) Matrix

Shear New Matrix by x and y

func Translate

func Translate(x, y float64) Matrix

Translate New Matrix by x and y

func (*Matrix) AdjustPosition

func (m *Matrix) AdjustPosition(x, y float64)

AdjustPosition adjust position of the matrix by x and y

func (Matrix) AdjustScale

func (m Matrix) AdjustScale(scale float64) Matrix

AdjustScale -

func (Matrix) Multiply

func (m Matrix) Multiply(b Matrix) Matrix

Multiply Matrix and another Matrix

func (Matrix) Rotate

func (m Matrix) Rotate(angle float64) Matrix

Rotate a Matrix using x and y

func (Matrix) Scale

func (m Matrix) Scale(x, y float64) Matrix

Scale a Matrix using x and y

func (Matrix) Shear

func (m Matrix) Shear(x, y float64) Matrix

Shear a Matrix using x and y

func (Matrix) ToAffineMatrix

func (m Matrix) ToAffineMatrix() f64.Aff3

func (Matrix) TransformPoint

func (m Matrix) TransformPoint(x, y float64) (tx, ty float64)

TransformPoint using a Matrix and x and y

func (Matrix) TransformVector

func (m Matrix) TransformVector(x, y float64) (tx, ty float64)

TransformVector using a Matrix and x and y

func (Matrix) Translate

func (m Matrix) Translate(x, y float64) Matrix

Translate a Matrix using x and y

Directories

Path Synopsis
Based on https://github.com/jdeng/goface/blob/master/mtcnn.go
Based on https://github.com/jdeng/goface/blob/master/mtcnn.go

Jump to

Keyboard shortcuts

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