gocv

package module
v0.0.0-...-63d793e Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2017 License: Apache-2.0 Imports: 1 Imported by: 0

README

go-cv

go-cv is a computer vision and image processing library for Go using Golang assembly. It is a works-in-progress wrapper around the Simd library. For now most work has been done on the SSE2 version.

SIMD

The Simd Library is a highly optimized image processing library. It provides many useful high performance algorithms for image processing such as:

  • pixel format conversion
  • image scaling and filtration
  • extraction of statistic information from images
  • motion detection
  • object detection (HAAR and LBP classifier cascades)
  • classification
  • neural network

The algorithms are optimized using different SIMD CPU extensions. In particular the library supports following CPU extensions:

  • x86/x64: SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX and AVX2
  • ARM: NEON

Installation

$ go get -u "github.com/fwessels/go-cv"

Samples

See the samples directory for various sample algorithms. For example:

$ cd samples
$ go run filtering.go

Performance compared to OpenCV 2.x

A comparison against go-opencv shows the following results:

                               OpenCV          SSE2
benchmark                   old ns/op     new ns/op      delta
BenchmarkGaussian-8             74338         18481    -75.14%
BenchmarkGaussianRGB-8         186024         57169    -69.27%
BenchmarkBlur-8                110155         16623    -84.91%
BenchmarkBlurRGB-8             293017         53716    -81.67%
BenchmarkMedian3x3-8           129268         23270    -82.00%
BenchmarkMedian3x3RGB-8        169857         65896    -61.21%
BenchmarkMedian5x5-8           883311        131812    -85.08%
BenchmarkMedian5x5RGB-8       1246845        388415    -68.85%

go-cv

See the underlying package go-cv for more information.

License

go-cv is released under the Apache License v2.0. You can find the complete text in the file LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsDifferenceSum

func AbsDifferenceSum(a, b gocvsimd.View) uint64

AbsDifferenceSum gets sum of absolute difference of two gray 8-bit images. Both images must have the same width and height.

func AbsDifferenceSumMasked

func AbsDifferenceSumMasked(a, b, mask gocvsimd.View, index uint8) uint64

AbsDifferenceSumMasked gets sum of absolute difference of two gray 8-bit images based on gray 8-bit mask. Gets the absolute difference sum for all points when mask[i] == index. Both images and mask must have the same width and height.

func AbsDifferenceSums3x3

func AbsDifferenceSums3x3(current, background gocvsimd.View) [9]uint64

AbsDifferenceSums3x3 gets 9 sums of absolute difference of two gray 8-bit images with various relative shifts in neighborhood 3x3. Both images must have the same width and height. The image height and width must be equal or greater 3. The sums are calculated with central part (indent width = 1) of the current image and with part of the background image with corresponding shift. The shifts are lain in the range [-1, 1] for axis x and y.

func AbsDifferenceSums3x3Masked

func AbsDifferenceSums3x3Masked(current, background, mask gocvsimd.View, index uint8) [9]uint64

AbsDifferenceSums3x3Masked gets 9 sums of absolute difference of two gray 8-bit images with various relative shifts in neighborhood 3x3 based on gray 8-bit mask. Gets the absolute difference sums for all points when mask[i] == index. Both images and mask must have the same width and height. The image height and width must be equal or greater 3. The sums are calculated with central part (indent width = 1) of the current image and with part of the background image with the corresponding shift. The shifts are lain in the range [-1, 1] for axis x and y.

func AbsGradientSaturatedSum

func AbsGradientSaturatedSum(src, dst gocvsimd.View)

AbsGradientSaturatedSum puts to destination 8-bit gray image saturated sum of absolute gradient for every point of source 8-bit gray image. Both images must have the same width and height.

For border pixels:
	dst[x, y] = 0;
For other pixels:
	dx = abs(src[x + 1, y] - src[x - 1, y]);
	dy = abs(src[x, y + 1] - src[x, y - 1]);
	dst[x, y] = min(dx + dy, 255);

func AddFeatureDifference

func AddFeatureDifference(value, lo, hi gocvsimd.View, weight uint16, difference gocvsimd.View)

AddFeatureDifference adds feature difference to common difference in sum. All images must have the same width, height and format (8-bit gray).

For every point:
	excess = max(lo[i] - value[i], 0) + max(value[i] - hi[i], 0);
	difference[i] += (weight * excess*excess) >> 16;

This function is used for difference estimation in algorithm of motion detection.

func AlphaBlending

func AlphaBlending(src, alpha, dst gocvsimd.View)

AlphaBlending performs alpha blending operation. All images must have the same width and height. Source and destination images must have the same format (8 bit per channel, for example GRAY8, BGR24 or BGRA32). Alpha must be 8-bit gray image.

For every point:
	dst[i] = (src[i]*alpha[i] + dst[i]*(255 - alpha[i]))/255;

This function is used for image drawing.

func AveragingBinarization

func AveragingBinarization(src gocvsimd.View, value uint8, neighborhood uint64, threshold, positive, negative uint8, dst gocvsimd.View, compareType uint8)

AveragingBinarization performs averaging binarization of 8-bit gray image. All images must have 8-bit gray format and must have the same width and height.

For every point:
	sum = 0; area = 0;
	for(dy = -neighborhood; dy <= neighborhood; ++dy)
	{
		for(dx = -neighborhood; dx <= neighborhood; ++dx)
		{
			if(x + dx >= 0 && x + dx < width && y + dy >= 0 && y + dy < height)
			{
				area++;
				if(compare(src[x + dx, x + dy], value))
					sum++;
			}
		}
	}
	dst[x, y] = sum*255 > area*threshold ? positive : negative;

where compare(a, b) depends from compareType (see ::SimdCompareType).

func BackgroundAdjustRange

func BackgroundAdjustRange(loCount, loValue, hiCount, hiValue gocvsimd.View, threshold uint8)

BackgroundAdjustRange performs adjustment of background range. All images must have the same width, height and format (8-bit gray).

Adjusts background range for every point:
    loValue[i] -= (loCount[i] > threshold && loValue[i] > 0) ? 1 : 0;
    loValue[i] += (loCount[i] < threshold && loValue[i] < 255) ? 1 : 0;
    loCount[i] = 0;
    hiValue[i] += (hiCount[i] > threshold && hiValue[i] < 255) ? 1 : 0;
    hiValue[i] -= (hiCount[i] < threshold && hiValue[i] > 0) ? 1 : 0;
    hiCount[i] = 0;

This function is used for background updating in motion detection algorithm.

func BackgroundAdjustRangeMasked

func BackgroundAdjustRangeMasked(loCount, loValue, hiCount, hiValue gocvsimd.View, threshold uint8, mask gocvsimd.View)

BackgroundAdjustRangeMasked performs adjustment of background range with using adjust range mask. All images must have the same width, height and format (8-bit gray).

Adjusts background range for every point:
    if(mask[i])
    {
        loValue[i] -= (loCount[i] > threshold && loValue[i] > 0) ? 1 : 0;
        loValue[i] += (loCount[i] < threshold && loValue[i] < 255) ? 1 : 0;
        loCount[i] = 0;
        hiValue[i] += (hiCount[i] > threshold && hiValue[i] < 255) ? 1 : 0;
        hiValue[i] -= (hiCount[i] < threshold && hiValue[i] > 0) ? 1 : 0;
        hiCount[i] = 0;
    }

This function is used for background updating in motion detection algorithm.

func BackgroundGrowRangeFast

func BackgroundGrowRangeFast(value, lo, hi gocvsimd.View)

BackgroundGrowRangeFast performs background update (initial grow, fast mode). All images must have the same width, height and format (8-bit gray).

For every point:
    lo[i] = value[i] < lo[i] ? value[i] : lo[i];
    hi[i] = value[i] > hi[i] ? value[i] : hi[i];

This function is used for background updating in motion detection algorithm.

func BackgroundGrowRangeSlow

func BackgroundGrowRangeSlow(value, lo, hi gocvsimd.View)

BackgroundGrowRangeSlow performs background update (initial grow, slow mode). All images must have the same width, height and format (8-bit gray).

For every point:
	lo[i] -= value[i] < lo[i] ? 1 : 0;
	hi[i] += value[i] > hi[i] ? 1 : 0;

This function is used for background updating in motion detection algorithm.

func BackgroundIncrementCount

func BackgroundIncrementCount(value, lo, hi, loCount, hiCount gocvsimd.View)

BackgroundIncrementCount performs collection of background statistic. All images must have the same width, height and format (8-bit gray).

Updates background statistic counters for every point:
    loCount[i] += (value[i] < loValue[i] && loCount[i] < 255) ? 1 : 0;
    hiCount[i] += (value[i] > hiValue[i] && hiCount[i] < 255) ? 1 : 0;

This function is used for background updating in motion detection algorithm.

func BackgroundShiftRange

func BackgroundShiftRange(value, lo, hi gocvsimd.View)

BackgroundShiftRange shifts background range. All images must have the same width, height and format (8-bit gray).

For every point:
	if (value[i] > hi[i])
	{
		lo[i] = min(lo[i] + value[i] - hi[i], 255);
		hi[i] = value[i];
	}
	if (lo[i] > value[i])
	{
		lo[i] = value[i];
		hi[i] = max(hi[i] - lo[i] + value[i], 0);
	}

This function is used for fast background updating in motion detection algorithm.

func BackgroundShiftRangeMasked

func BackgroundShiftRangeMasked(value, lo, hi, mask gocvsimd.View)

BackgroundShiftRangeMasked shifts background range with using shift range mask. All images must have the same width, height and format (8-bit gray).

For every point:
	if(mask[i])
	{
		if (value[i] > hi[i])
		{
			lo[i] = min(lo[i] + value[i] - hi[i], 255);
			hi[i] = value[i];
		}
		if (lo[i] > value[i])
		{
			lo[i] = value[i];
			hi[i] = max(hi[i] - lo[i] + value[i], 0);
		}
	}

This function is used for fast background updating in motion detection algorithm.

func BgraToGray

func BgraToGray(bgra gocvsimd.View) (gray gocvsimd.View)

BgraToGray converts 32-bit BGRA image to 8-bit gray image. All images must have the same width and height.

func BgraToYuv420p

func BgraToYuv420p(bgra gocvsimd.View) (y, u, v gocvsimd.View)

BgraToYuv420p converts 32-bit BGRA image to YUV420P.

The input BGRA and output Y images must have the same width and height.

The input U and V images must have the same width and height (half size relative to Y component).

func BgraToYuv422p

func BgraToYuv422p(bgra gocvsimd.View) (y, u, v gocvsimd.View)

BgraToYuv422p converts 32-bit BGRA image to YUV422P.

The input BGRA and output Y images must have the same width and height.

The input U and V images must have the same width and height (their width is equal to half width of Y component).

func BgraToYuv444p

func BgraToYuv444p(bgra gocvsimd.View) (y, u, v gocvsimd.View)

BgraToYuv444p converts 32-bit BGRA image to YUV444P. The input BGRA and output Y, U and V images must have the same width and height.

func Binarization

func Binarization(src gocvsimd.View, value, positive, negative uint8, dst gocvsimd.View, compareType uint8)

Binarization performs binarization of 8-bit gray image. All images must have 8-bit gray format and must have the same width and height.

For every point:
	dst[i] = compare(src[i], value) ? positive : negative;

where compare(a, b) depends from compareType (see ::SimdCompareType).

func ConditionalCount16i

func ConditionalCount16i(src gocvsimd.View, value int16, compareType uint8) uint32

ConditionalCount16i calculates the number of points satisfying certain condition for 16-bit signed integer image.

For every point:
	if(compare(src[i], value))
	count++;

where compare(a, b) depends from compareType (see ::SimdCompareType).

func ConditionalCount8u

func ConditionalCount8u(src gocvsimd.View, value uint8, compareType uint8) uint32

ConditionalCount8u calculates number of points satisfying certain condition for 8-bit gray image.

For every point:
	if(compare(src[i], value))
	count++;

where compare(a, b) depends from compareType (see ::SimdCompareType).

func ConditionalFill

func ConditionalFill(src gocvsimd.View, threshold, compareType, value uint8, dst gocvsimd.View)

ConditionalFill fills pixels of 8-bit gray image by given value if corresponding pixels of input 8-bit gray image satisfy certain condition. All images must have the same width and height.

For every point:
	if(compare(src[i], threshold))
	dst[i] = value;

where compare(a, b) depends from compareType (see ::SimdCompareType).

func ConditionalSquareGradientSum

func ConditionalSquareGradientSum(src, mask gocvsimd.View, value, compareType uint8) uint64

ConditionalSquareGradientSum calculates sum of squared gradient of image points when mask points satisfying certain condition. All images must have 8-bit gray format and must have the same width and height. The image height and width must be equal or greater 3.

For every point except border:
	if(compare(mask[x, y], value))
	{
		dx = src[x + 1, y] - src[x - 1, y];
		dy = src[x, y + 1] - src[x, y - 1];
		sum += dx*dx + dy*dy;
	}

where compare(a, b) depends from compareType (see ::SimdCompareType).

func ConditionalSquareSum

func ConditionalSquareSum(src, mask gocvsimd.View, value, compareType uint8) uint64

ConditionalSquareSum calculates sum of squared image points when mask points satisfying certain condition. All images must have 8-bit gray format and must have the same width and height.

For every point:
	if(compare(mask[i], value))
	sum += src[i]*src[i];

where compare(a, b) depends from compareType (see ::SimdCompareType).

func ConditionalSum

func ConditionalSum(src, mask gocvsimd.View, value, compareType uint8) uint64

ConditionalSum calculates sum of image points when mask points satisfying certain condition. All images must have 8-bit gray format and must have the same width and height.

For every point:
	if(compare(mask[i], value))
	sum += src[i];

where compare(a, b) depends from compareType (see ::SimdCompareType).

func ContourAnchors

func ContourAnchors(src gocvsimd.View, step uint64, threshold int16, dst gocvsimd.View)

func DeinterleaveUv

func DeinterleaveUv(uv gocvsimd.View) (u, v gocvsimd.View)

DeinterleaveUv deinterleaves 16-bit UV interleaved image into separated 8-bit U and V planar images. All images must have the same width and height. This function used for NV12 to YUV420P conversion.

func FillBgr

func FillBgr(dst gocvsimd.View, blue, green, red int)

FillBgr fills pixels data of 24-bit BGR image by given color(blue, green, red).

func FillBgra

func FillBgra(dst gocvsimd.View, blue, green, red, alpha int)

FillBgra fills pixels data of 32-bit BGRA image by given color(blue, green, red, alpha).

func GaussianBlur3x3

func GaussianBlur3x3(src gocvsimd.View) (dst gocvsimd.View)

GaussianBlur3x3 performs Gaussian blur filtration with window 3x3.

For every point:
	dst[x, y] = (src[x-1, y-1] + 2*src[x, y-1] + src[x+1, y-1] +
	2*(src[x-1, y] + 2*src[x, y] + src[x+1, y]) +
	src[x-1, y+1] + 2*src[x, y+1] + src[x+1, y+1] + 8) / 16;

All images must have the same width, height and format (8-bit gray, 16-bit UV, 24-bit BGR or 32-bit BGRA).

func GrayToBgra

func GrayToBgra(gray gocvsimd.View) (bgra gocvsimd.View)

GrayToBgra converts 8-bit gray image to 32-bit BGRA image. All images must have the same width and height.

func Int16ToGray

func Int16ToGray(src gocvsimd.View) (dst gocvsimd.View)

Int16ToGray converts 16-bit signed integer image to 8-bit gray image with saturation. All images must have the same width and height.

func Laplace

func Laplace(src gocvsimd.View) (dst gocvsimd.View)

Laplace calculates Laplace's filter. All images must have the same width and height. Input image must has 8-bit gray format, output image must has 16-bit integer format.

func MeanFilter3x3

func MeanFilter3x3(src gocvsimd.View) (dst gocvsimd.View)

MeanFilter3x3 performs an averaging with window 3x3.

For every point:
	dst[x, y] = (src[x-1, y-1] + src[x, y-1] + src[x+1, y-1] +
		src[x-1, y] + src[x, y] + src[x+1, y] +
		src[x-1, y+1] + src[x, y+1] + src[x+1, y+1] + 4) / 9;

All images must have the same width, height and format (8-bit gray, 16-bit UV, 24-bit BGR or 32-bit BGRA).

func MedianFilterRhomb3x3

func MedianFilterRhomb3x3(src gocvsimd.View) (dst gocvsimd.View)

MedianFilterRhomb3x3 performs median filtration of input image (filter window is a rhomb 3x3). All images must have the same width, height and format (8-bit gray, 16-bit UV, 24-bit BGR or 32-bit BGRA).

func MedianFilterRhomb5x5

func MedianFilterRhomb5x5(src gocvsimd.View) (dst gocvsimd.View)

MedianFilterRhomb5x5 performs median filtration of input image (filter window is a rhomb 5x5). All images must have the same width, height and format (8-bit gray, 16-bit UV, 24-bit BGR or 32-bit BGRA).

func MedianFilterSquare3x3

func MedianFilterSquare3x3(src gocvsimd.View) (dst gocvsimd.View)

MedianFilterSquare3x3 performs median filtration of input image (filter window is a square 3x3). All images must have the same width, height and format (8-bit gray, 16-bit UV, 24-bit BGR or 32-bit BGRA).

func MedianFilterSquare5x5

func MedianFilterSquare5x5(src gocvsimd.View) (dst gocvsimd.View)

MedianFilterSquare5x5 performs median filtration of input image (filter window is a square 5x5). All images must have the same width, height and format (8-bit gray, 16-bit UV, 24-bit BGR or 32-bit BGRA).

func OperationBinary16i

func OperationBinary16i(a, b, dst gocvsimd.View, _type uint8)

OperationBinary16i performs given operation between two images. All images must have the same width, height and ::SimdPixelFormatInt16 pixel format.

func OperationBinary8u

func OperationBinary8u(a, b, dst gocvsimd.View, _type uint8)

OperationBinary8u performs given operation between two images. All images must have the same width, height and format (8-bit gray, 16-bit UV (UV plane of NV12 pixel format), 24-bit BGR or 32-bit BGRA).

func SegmentationChangeIndex

func SegmentationChangeIndex(mask gocvsimd.View, oldIndex, newIndex uint8)

SegmentationChangeIndex changes certain index in mask. Mask must has 8-bit gray pixel format.

For every point:
	if(mask[i] == oldIndex)
	mask[i] = newIndex;

func SegmentationFillSingleHoles

func SegmentationFillSingleHoles(mask gocvsimd.View, index uint8)

SegmentationFillSingleHoles fills single holes in mask. Mask must has 8-bit gray pixel format.

func SegmentationPropagate2x2

func SegmentationPropagate2x2(parent, child, difference gocvsimd.View, currentIndex, invalidIndex, emptyIndex, differenceThreshold uint8)

SegmentationPropagate2x2 propagates mask index from parent (upper) to child (lower) level of mask pyramid with using 2x2 scan window. For parent and child image the following must be true: parentWidth = (childWidth + 1)/2, parentHeight = (childHeight + 1)/2. All images must have 8-bit gray pixel format. Size of different image is equal to the child image.

func SobelDx

func SobelDx(src gocvsimd.View) (dst gocvsimd.View)

SobelDx calculates Sobel's filter along x axis. All images must have the same width and height. Input image must has 8-bit gray format, output image must has 16-bit integer format.

For every point:
	n dst[x, y] = (src[x+1,y-1] + 2*src[x+1, y] + src[x+1, y+1]) - (src[x-1,y-1] + 2*src[x-1, y] + src[x-1, y+1]).

func SobelDy

func SobelDy(src gocvsimd.View) (dst gocvsimd.View)

SobelDy calculates Sobel's filter along y axis. All images must have the same width and height. Input image must has 8-bit gray format, output image must have a 16-bit integer format.

For every point:
	dst[x, y] = (src[x-1,y+1] + 2*src[x, y+1] + src[x+1, y+1]) - (src[x-1,y-1] + 2*src[x, y-1] + src[x+1, y-1]);

func SquaredDifferenceSum

func SquaredDifferenceSum(a, b gocvsimd.View) uint64

SquaredDifferenceSum calculates sum of squared differences for two 8-bit gray images. All images must have the same width and height.

For every point:
	sum += (a[i] - b[i])*(a[i] - b[i]);

func SquaredDifferenceSumMasked

func SquaredDifferenceSumMasked(a, b, mask gocvsimd.View, index uint8) uint64

SquaredDifferenceSumMasked calculates sum of squared differences for two images with using mask. All images must have the same width, height and format (8-bit gray).

For every point:
	if(mask[i] == index)
		sum += (a[i] - b[i])*(a[i] - b[i]);

func StretchGray2x2

func StretchGray2x2(src, dst gocvsimd.View)

StretchGray2x2 stretches input 8-bit gray image in two times.

func TextureBoostedSaturatedGradient

func TextureBoostedSaturatedGradient(src gocvsimd.View, saturation, boost uint8, dx, dy gocvsimd.View)

TextureBoostedSaturatedGradient calculates boosted saturated gradients for given input image. All images must have the same width, height and format (8-bit gray).

For border pixels:
	dx[x, y] = 0;
	dy[x, y] = 0;
For other pixels:
	dx[x, y] = (saturation + max(-saturation, min(saturation, (src[x + 1, y] - src[x - 1, y]))))*boost;
	dy[x, y] = (saturation + max(-saturation, min(saturation, (src[x, y + 1] - src[x, y - 1]))))*boost;

func TextureBoostedUv

func TextureBoostedUv(src gocvsimd.View, boost uint8, dst gocvsimd.View)

TextureBoostedUv calculates boosted colorized texture feature of input image (actual for U and V components of YUV format). All images must have the same width, height and format (8-bit gray).

For every pixel:
	lo = 128 - (128/boost);
	hi = 255 - lo;
	dst[x, y] = max(lo, min(hi, src[i]))*boost;

func TextureGetDifferenceSum

func TextureGetDifferenceSum(src, lo, hi gocvsimd.View) int64

TextureGetDifferenceSum calculates difference between current image and background. All images must have the same width, height and format (8-bit gray).

For every pixel:
	sum += current - average(lo[i], hi[i]);

func TexturePerformCompensation

func TexturePerformCompensation(src gocvsimd.View, shift int, dst gocvsimd.View)

TexturePerformCompensation performs brightness compensation of input image. All images must have the same width, height and format (8-bit gray).

For every pixel:
	dst[i] = max(0, min(255, src[i] + shift));

func VectorProduct

func VectorProduct(vertical, horizontal, dst gocvsimd.View)

VectorProduct calculates result 8-bit gray image as product of two vectors.

For all points:
	dst[x, y] = horizontal[x]*vertical[y]/255;

func Yuv420pToBgra

func Yuv420pToBgra(y, u, v gocvsimd.View, alpha uint8) (bgra gocvsimd.View)

Yuv420pToBgra converts YUV420P image to 32-bit BGRA image.

The input Y and output BGRA images must have the same width and height.
The input U and V images must have the same width and height (half size relative to Y component).

func Yuv422pToBgra

func Yuv422pToBgra(y, u, v gocvsimd.View, alpha uint8) (bgra gocvsimd.View)

Yuv422pToBgra converts YUV422P image to 32-bit BGRA image.

The input Y and output BGRA images must have the same width and height.
The input U and V images must have the same width and height (their width is equal to half width of Y component).

func Yuv444pToBgra

func Yuv444pToBgra(y, u, v gocvsimd.View, alpha uint8) (bgra gocvsimd.View)

Yuv444pToBgra converts YUV444P image to 32-bit BGRA image.

The input Y, U, V and output BGRA images must have the same width and height.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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