Standard library · Machine learning

opencv

Computer vision with OpenCV: image processing, features, face detection, neural networks and video.

import opencv

This package binds the OpenCV library and gives most of the everyday computer vision work: color conversion, resizing, filters, edge detection and thresholds, contours, ORB and SIFT features, face detection with a cascade classifier, running DNN networks, and reading and writing video and camera frames.

It needs OpenCV and the Salam shim at run time; check with Available that the library was loaded. For simpler work with no dependency, see the image package. The examples on the site are only type-checked.

Types

VideoCapture

struct VideoCapture
Reads video or a camera.
NameTypeDescription
handlevoid*The internal handle.
opencv-Detect.salam
import opencv
import image

func main:
    mut cascade := opencv.LoadCascade("haarcascade_frontalface_default.xml")
    mut photo := opencv.Read("people_en.jpg")
    if cascade.ok():
        each face in cascade.detect(photo.to_gray(), 1.1, 5, 100):
            photo.rectangle(face.x, face.y, face.width, face.height, opencv.Green(), 2)
        end
    end
    cascade.free()

    mut net := opencv.LoadNet("MobileNetSSD_en.caffemodel", "MobileNetSSD_en.prototxt")
    mut single := opencv.LoadNetSingleFile("model_en.onnx")
    if net.ok():
        _ := net.set_input(photo, 0.007843, opencv.RGB(127, 127, 127), false, opencv.Size { width = 300, height = 300 })
        output := net.forward()
        _ := net.forward_layer("detection_out")
        each obj in opencv.ParseSSDDetections(output, photo.width(), photo.height(), 0.5):
            println obj.class_id, obj.confidence, obj.x, obj.y, obj.width, obj.height
        end
    end
    net.free()
    single.free()

    mut video := opencv.OpenVideo("clip_en.mp4")
    mut camera := opencv.OpenCamera(0)
    mut writer := opencv.NewVideoWriter("out_en.mp4", "mp4v", video.fps(), 640, 480)
    println video.ok(), video.frame_count(), camera.ok(), writer.ok()
    opencv.CreateTrackbar("threshold", "preview", 100, 255)
    until video.ok():
        frame := video.read()
        if frame.empty():
            break
        end
        level := opencv.GetTrackbarPos("threshold", "preview")
        edges := frame.to_gray().canny(level as f64, 200.0)
        _ := writer.write(frame)
        opencv.Imshow("preview", edges)
        if opencv.WaitKey(1) == 27:
            break
        end
    end
    opencv.SetTrackbarPos("threshold", "preview", 50)
    opencv.DestroyWindow("preview")
    opencv.DestroyAllWindows()
    video.close()
    camera.close()
    writer.close()

    picture := opencv.ToImage(photo)
    println picture.width
    _ := opencv.FromImage(image.New(8, 8))
end

ok

func ok(): bool
Whether it is open.

The example for this item is shown with the ones above: opencv-Detect.salam

read

func read(): Mat
The next frame; empty at the end.

The example for this item is shown with the ones above: opencv-Detect.salam

fps

func fps(): f64
Frames per second.

The example for this item is shown with the ones above: opencv-Detect.salam

frame_count

func frame_count(): int
The number of frames.

The example for this item is shown with the ones above: opencv-Detect.salam

close

func close()
Closes it.

The example for this item is shown with the ones above: opencv-Detect.salam

VideoWriter

struct VideoWriter
Writes video.
NameTypeDescription
handlevoid*The internal handle.

The example for this item is shown with the ones above: opencv-Detect.salam

ok

func ok(): bool
Whether it is open.

The example for this item is shown with the ones above: opencv-Detect.salam

write

func write(frame: Mat): bool
Writes a frame.

The example for this item is shown with the ones above: opencv-Detect.salam

close

func close()
Closes it.

The example for this item is shown with the ones above: opencv-Detect.salam

DetectedObject

struct DetectedObject
A detected object.
NameTypeDescription
xint = 0x.
yint = 0y.
widthint = 0The width.
heightint = 0The height.

The example for this item is shown with the ones above: opencv-Detect.salam

CascadeClassifier

struct CascadeClassifier
A Haar cascade classifier; for face detection.
NameTypeDescription
handlevoid*The internal handle.

The example for this item is shown with the ones above: opencv-Detect.salam

ok

func ok(): bool
Whether it loaded.

The example for this item is shown with the ones above: opencv-Detect.salam

detect

func detect(m: Mat, scale_factor: f64, min_neighbors: int, max_results: int): Vector<DetectedObject>
Finds objects with a scale factor and a minimum neighbor count.

The example for this item is shown with the ones above: opencv-Detect.salam

free

func free()
Frees it.

The example for this item is shown with the ones above: opencv-Detect.salam

Contours

struct Contours
Contours.
NameTypeDescription
handlevoid*The internal handle.
opencv-Features.salam
import opencv

func main:
    mut scene := opencv.Read("scene_en.jpg")
    mut target := opencv.Read("object_en.jpg")
    mut contours := scene.to_gray().threshold_otsu(255.0).find_contours()
    println contours.ok(), contours.count()
    repeat contours.count() in i:
        box := contours.bounding_rect(i)
        println contours.area(i), contours.point_count(i), contours.point(i, 0).x, box.x, box.y, box.width, box.height
        scene.draw_contour(contours, i, opencv.Green(), 2)
    end
    contours.free()

    corners := scene.to_gray().good_features(50, 0.01, 10.0)
    println corners.len()
    mut keys1 := scene.detect_orb(500)
    mut keys2 := target.detect_orb(500)
    mut sift := scene.detect_sift(500)
    println keys1.ok(), keys1.count(), sift.count()
    if keys1.count() > 0:
        first := keys1.get(0)
        println first.x, first.y, first.size, first.angle, first.response
    end
    matches := opencv.MatchDescriptors(keys1.descriptors(), keys2.descriptors(), 50, opencv.NORM_HAMMING)
    each m in matches:
        println m.query_idx, m.train_idx, m.distance
    end
    println opencv.NORM_L2
    keys1.free()
    keys2.free()
    sift.free()

    found := scene.find_template(target)
    println found.found, found.x, found.y, found.score
    mut quad := Vector {} as Vector<opencv.Point>
    quad.push(opencv.Point { x = 0, y = 0 })
    quad.push(opencv.Point { x = 400, y = 10 })
    quad.push(opencv.Point { x = 410, y = 580 })
    quad.push(opencv.Point { x = 5, y = 590 })
    flat := scene.warp_perspective(quad, 420, 594)
    _ := opencv.Write("document_en.png", flat)
end

ok

func ok(): bool
Whether it is valid.

The example for this item is shown with the ones above: opencv-Features.salam

count

func count(): int
The number of contours.

The example for this item is shown with the ones above: opencv-Features.salam

point_count

func point_count(idx: int): int
The number of points in a contour.

The example for this item is shown with the ones above: opencv-Features.salam

point

func point(idx: int, pt_idx: int): Point
One point.

The example for this item is shown with the ones above: opencv-Features.salam

area

func area(idx: int): f64
The area.

The example for this item is shown with the ones above: opencv-Features.salam

bounding_rect

func bounding_rect(idx: int): Rect
The bounding rectangle.

The example for this item is shown with the ones above: opencv-Features.salam

free

func free()
Frees it.

The example for this item is shown with the ones above: opencv-Features.salam

Keypoint

struct Keypoint
One keypoint.
NameTypeDescription
xf64 = 0x.
yf64 = 0y.
sizef64 = 0The size.
anglef64 = 0The angle.
responsef64 = 0The strength.

The example for this item is shown with the ones above: opencv-Features.salam

Keypoints

struct Keypoints
Keypoints and descriptors.
NameTypeDescription
handlevoid*The internal handle.

The example for this item is shown with the ones above: opencv-Features.salam

ok

func ok(): bool
Whether it is valid.

The example for this item is shown with the ones above: opencv-Features.salam

count

func count(): int
The count.

The example for this item is shown with the ones above: opencv-Features.salam

get

func get(i: int): Keypoint
Keypoint i.

The example for this item is shown with the ones above: opencv-Features.salam

descriptors

func descriptors(): Mat
The descriptors.

The example for this item is shown with the ones above: opencv-Features.salam

free

func free()
Frees it.

The example for this item is shown with the ones above: opencv-Features.salam

Match

struct Match
One match.
NameTypeDescription
query_idxint = 0The index in the first set.
train_idxint = 0The index in the second set.
distancef64 = 0The distance; lower means more alike.

The example for this item is shown with the ones above: opencv-Features.salam

Net

struct Net
A DNN neural network.
NameTypeDescription
handlevoid*The internal handle.

The example for this item is shown with the ones above: opencv-Detect.salam

ok

func ok(): bool
Whether it loaded.

The example for this item is shown with the ones above: opencv-Detect.salam

set_input

func set_input(image: Mat, scale: f64, mean: Color, swap_rb: bool, size: Size): bool
Prepares the input with a scale, a mean, a channel swap and a size.

The example for this item is shown with the ones above: opencv-Detect.salam

forward

func forward(): Mat
Runs the network.

The example for this item is shown with the ones above: opencv-Detect.salam

forward_layer

func forward_layer(layer_name: str): Mat
The output of one layer.

The example for this item is shown with the ones above: opencv-Detect.salam

free

func free()
Frees it.

The example for this item is shown with the ones above: opencv-Detect.salam

Detection

struct Detection
One object found with DNN.
NameTypeDescription
class_idint = 0The class number.
confidencef64 = 0The confidence.
xint = 0x.
yint = 0y.
widthint = 0The width.
heightint = 0The height.

The example for this item is shown with the ones above: opencv-Features.salam

Mat

struct Mat
An OpenCV image or matrix with BGR channels.
NameTypeDescription
handlevoid*The internal handle.
opencv-Basics.salam
import opencv

func main:
    if not opencv.Available():
        println "OpenCV is not available:", opencv.LastError()
        ret
    end
    println opencv.Version()
    mut photo := opencv.Read("photo_en.jpg")
    if not photo.ok() or photo.empty():
        photo = opencv.NewBlank(320, 240, 3, opencv.White())
    end
    dims := photo.size()
    println photo.width(), photo.height(), photo.channels(), dims.width, dims.height, photo.step(), photo.total(), photo.data() != null
    color := photo.at(10, 10)
    println color.r, color.g, color.b
    photo.set_pixel(0, 0, opencv.RGB(255, 128, 0))
    black := opencv.Zeros(10, 10, 1)
    println black.channels(), opencv.Black().r, opencv.Red().r, opencv.Green().g, opencv.Blue().b

    gray := photo.to_gray()
    _ := photo.to_rgb()
    hsv := photo.to_hsv()
    _ := hsv.hsv_to_rgb()
    _ := photo.convert_color(opencv.COLOR_BGR2GRAY)
    _ := gray.convert_color(opencv.COLOR_GRAY2BGR)
    println opencv.COLOR_RGB2GRAY, opencv.COLOR_GRAY2RGB, opencv.COLOR_BGR2RGB, opencv.COLOR_RGB2BGR, opencv.COLOR_BGR2HSV, opencv.COLOR_HSV2BGR, opencv.COLOR_RGB2HSV, opencv.COLOR_HSV2RGB

    small := photo.resize(160, 120, opencv.INTERP_AREA)
    _ := photo.resize_scale(2.0, 2.0)
    _ := photo.crop(10, 10, 100, 80)
    _ := photo.rotate90(opencv.ROTATE_90_CW)
    _ := photo.rotate(45.0, 1.0)
    _ := photo.flip(opencv.FLIP_BOTH)
    _ := photo.flip_horizontal()
    _ := photo.flip_vertical()
    println opencv.INTERP_NEAREST, opencv.INTERP_LINEAR, opencv.INTERP_CUBIC, opencv.INTERP_LANCZOS4, opencv.ROTATE_180, opencv.ROTATE_90_CCW, opencv.FLIP_VERTICAL, opencv.FLIP_HORIZONTAL
    copied := small.clone()
    println copied.save("small_en.png"), opencv.Write("gray_en.png", gray)
    copied.free()
    photo.free()
end

ok

func ok(): bool
Whether it is valid.

The example for this item is shown with the ones above: opencv-Basics.salam

empty

func empty(): bool
Whether it is empty.

The example for this item is shown with the ones above: opencv-Basics.salam

width

func width(): int
The width.

The example for this item is shown with the ones above: opencv-Basics.salam

height

func height(): int
The height.

The example for this item is shown with the ones above: opencv-Basics.salam

channels

func channels(): int
The number of channels.

The example for this item is shown with the ones above: opencv-Basics.salam

size

func size(): Size
The size.

The example for this item is shown with the ones above: opencv-Features.salam

clone

func clone(): Mat
A copy.

The example for this item is shown with the ones above: opencv-Basics.salam

free

func free()
Frees it.

The example for this item is shown with the ones above: opencv-Basics.salam

save

func save(path: str): bool
Saves it to a file.

The example for this item is shown with the ones above: opencv-Basics.salam

data

func data(): void*
A pointer to the pixels.

The example for this item is shown with the ones above: opencv-Basics.salam

step

func step(): int
The bytes in each row.

The example for this item is shown with the ones above: opencv-Basics.salam

total

func total(): int
The number of pixels.

The example for this item is shown with the ones above: opencv-Basics.salam

at

func at(x: int, y: int): Color
The color of a pixel.

The example for this item is shown with the ones above: opencv-Basics.salam

set_pixel

func set_pixel(x: int, y: int, c: Color)
Sets the color of a pixel.

The example for this item is shown with the ones above: opencv-Basics.salam

convert_color

func convert_color(code: int): Mat
Converts the colors with one of the conversion constants.

The example for this item is shown with the ones above: opencv-Basics.salam

to_gray

func to_gray(): Mat
Gray.

The example for this item is shown with the ones above: opencv-Basics.salam

to_rgb

func to_rgb(): Mat
RGB.

The example for this item is shown with the ones above: opencv-Basics.salam

to_hsv

func to_hsv(): Mat
HSV; for picking out a color.

The example for this item is shown with the ones above: opencv-Basics.salam

hsv_to_rgb

func hsv_to_rgb(): Mat
HSV to RGB.

The example for this item is shown with the ones above: opencv-Basics.salam

resize

func resize(width: int, height: int, interpolation: int): Mat
Resizes with an interpolation method.

The example for this item is shown with the ones above: opencv-Basics.salam

resize_scale

func resize_scale(fx: f64, fy: f64): Mat
Resizes by a factor.

The example for this item is shown with the ones above: opencv-Basics.salam

crop

func crop(x: int, y: int, w: int, h: int): Mat
Cuts out a rectangle.

The example for this item is shown with the ones above: opencv-Basics.salam

rotate90

func rotate90(code: int): Mat
Rotates by a multiple of ninety degrees.

The example for this item is shown with the ones above: opencv-Basics.salam

rotate

func rotate(angle_degrees: f64, scale: f64): Mat
Rotates by an angle and a scale.

The example for this item is shown with the ones above: opencv-Basics.salam

flip

func flip(mode: int): Mat
Flips.

The example for this item is shown with the ones above: opencv-Basics.salam

flip_horizontal

func flip_horizontal(): Mat
Flips horizontally.

The example for this item is shown with the ones above: opencv-Basics.salam

flip_vertical

func flip_vertical(): Mat
Flips vertically.

The example for this item is shown with the ones above: opencv-Basics.salam

blur

func blur(ksize: int): Mat
Mean blur.

The example for this item is shown with the ones above: opencv-Basics.salam

gaussian_blur

func gaussian_blur(ksize: int, sigma: f64): Mat
Gaussian blur.

The example for this item is shown with the ones above: opencv-Basics.salam

median_blur

func median_blur(ksize: int): Mat
Median blur; for salt and pepper noise.

The example for this item is shown with the ones above: opencv-Basics.salam

canny

func canny(t1: f64, t2: f64): Mat
Canny edge detection with two thresholds.

The example for this item is shown with the ones above: opencv-Basics.salam

threshold

func threshold(thresh: f64, maxval: f64, kind: int): Mat
Applies a threshold.

The example for this item is shown with the ones above: opencv-Basics.salam

threshold_otsu

func threshold_otsu(maxval: f64): Mat
Otsu's automatic threshold.

The example for this item is shown with the ones above: opencv-Basics.salam

adaptive_threshold

func adaptive_threshold(maxval: f64, method: int, kind: int, block_size: int, c: f64): Mat
Adaptive threshold; for uneven light.

The example for this item is shown with the ones above: opencv-Basics.salam

histogram_gray

func histogram_gray(): Vector<int>
The 256 bin histogram of a gray image.

The example for this item is shown with the ones above: opencv-Basics.salam

line

func line(x1: int, y1: int, x2: int, y2: int, color: Color, thickness: int)
A line.

The example for this item is shown with the ones above: opencv-Basics.salam

rectangle

func rectangle(x: int, y: int, w: int, h: int, color: Color, thickness: int)
A rectangle; a negative thickness fills it.

The example for this item is shown with the ones above: opencv-Basics.salam

circle

func circle(cx: int, cy: int, radius: int, color: Color, thickness: int)
A circle.

The example for this item is shown with the ones above: opencv-Basics.salam

put_text

func put_text(text: str, x: int, y: int, font_scale: f64, color: Color, thickness: int)
Latin text.

The example for this item is shown with the ones above: opencv-Basics.salam

good_features

func good_features(max_corners: int, quality: f64, min_dist: f64): Vector<Point>
Good corners to track.

The example for this item is shown with the ones above: opencv-Basics.salam

detect_orb

func detect_orb(max_features: int): Keypoints
ORB keypoints and descriptors.

The example for this item is shown with the ones above: opencv-Basics.salam

detect_sift

func detect_sift(max_features: int): Keypoints
SIFT keypoints.

The example for this item is shown with the ones above: opencv-Basics.salam

erode

func erode(ksize: int, iterations: int): Mat
Erosion.

The example for this item is shown with the ones above: opencv-Basics.salam

dilate

func dilate(ksize: int, iterations: int): Mat
Dilation.

The example for this item is shown with the ones above: opencv-Basics.salam

morphology

func morphology(op: int, ksize: int): Mat
A morphological operation.

The example for this item is shown with the ones above: opencv-Basics.salam

blend

func blend(other: Mat, alpha: f64, beta: f64, gamma: f64): Mat
A weighted blend of two images.

The example for this item is shown with the ones above: opencv-Basics.salam

bitwise

func bitwise(other: Mat, op: int): Mat
A bitwise operation with another image.

The example for this item is shown with the ones above: opencv-Basics.salam

bitwise_not

func bitwise_not(): Mat
Bitwise NOT.

The example for this item is shown with the ones above: opencv-Basics.salam

abs_diff

func abs_diff(other: Mat): Mat
The absolute difference; for motion detection.

The example for this item is shown with the ones above: opencv-Basics.salam

warp_perspective

func warp_perspective(src: Vector<Point>, out_width: int, out_height: int): Mat
Turns four corners into a flat rectangle; for scanning documents.

The example for this item is shown with the ones above: opencv-Basics.salam

find_template

func find_template(template: Mat): TemplateMatch
Where a template sits in the image.

The example for this item is shown with the ones above: opencv-Basics.salam

ellipse

func ellipse(cx: int, cy: int, axis_width: int, axis_height: int, angle_degrees: f64, color: Color, thickness: int)
An ellipse.

The example for this item is shown with the ones above: opencv-Basics.salam

polylines

func polylines(pts: Vector<Point>, closed: bool, color: Color, thickness: int)
A polyline.

The example for this item is shown with the ones above: opencv-Basics.salam

fill_poly

func fill_poly(pts: Vector<Point>, color: Color)
A filled polygon.

The example for this item is shown with the ones above: opencv-Basics.salam

find_contours

func find_contours(): Contours
The contours of the shapes in a binary image.

The example for this item is shown with the ones above: opencv-Basics.salam

draw_contour

func draw_contour(cs: Contours, idx: int, color: Color, thickness: int)
Draws one contour.

The example for this item is shown with the ones above: opencv-Basics.salam

TemplateMatch

struct TemplateMatch
The result of a template search.
NameTypeDescription
foundbool = falseWhether it was found.
xint = 0x.
yint = 0y.
scoref64 = 0The match score.

The example for this item is shown with the ones above: opencv-Features.salam

Size

struct Size
A size.
NameTypeDescription
widthint = 0The width.
heightint = 0The height.

The example for this item is shown with the ones above: opencv-Basics.salam

Point

struct Point
A point.
NameTypeDescription
xint = 0x.
yint = 0y.
opencv-Filters.salam
import opencv

func main:
    mut photo := opencv.Read("photo_en.jpg")
    gray := photo.to_gray()
    _ := photo.blur(5)
    _ := photo.gaussian_blur(5, 1.5)
    _ := photo.median_blur(5)
    edges := gray.canny(50.0, 150.0)
    _ := gray.threshold(128.0, 255.0, opencv.THRESH_BINARY)
    _ := gray.threshold_otsu(255.0)
    _ := gray.adaptive_threshold(255.0, opencv.ADAPTIVE_GAUSSIAN, opencv.THRESH_BINARY, 11, 2.0)
    println opencv.THRESH_BINARY_INV, opencv.THRESH_TRUNC, opencv.THRESH_TOZERO, opencv.THRESH_TOZERO_INV, opencv.THRESH_OTSU, opencv.ADAPTIVE_MEAN
    println gray.histogram_gray().len()
    _ := edges.erode(3, 1)
    _ := edges.dilate(3, 2)
    _ := edges.morphology(opencv.MORPH_CLOSE, 5)
    println opencv.MORPH_OPEN, opencv.MORPH_GRADIENT, opencv.MORPH_TOPHAT, opencv.MORPH_BLACKHAT
    white := opencv.NewBlank(photo.width(), photo.height(), 3, opencv.White())
    _ := photo.blend(white, 0.7, 0.3, 0.0)
    _ := photo.bitwise(white, opencv.BITWISE_AND)
    _ := photo.bitwise(white, opencv.BITWISE_OR)
    _ := photo.bitwise(white, opencv.BITWISE_XOR)
    _ := photo.bitwise_not()
    _ := photo.abs_diff(white)
    photo.line(0, 0, 100, 100, opencv.Red(), 2)
    photo.rectangle(10, 10, 50, 30, opencv.Green(), 1)
    photo.circle(80, 80, 20, opencv.Blue(), -1)
    photo.ellipse(100, 50, 40, 20, 30.0, opencv.Black(), 2)
    photo.put_text("Salam", 10, 200, 1.0, opencv.White(), 2)
    mut points := Vector {} as Vector<opencv.Point>
    points.push(opencv.Point { x = 0, y = 0 })
    points.push(opencv.Point { x = 50, y = 0 })
    points.push(opencv.Point { x = 25, y = 40 })
    photo.polylines(points, true, opencv.Red(), 2)
    photo.fill_poly(points, opencv.Green())
    _ := opencv.Write("filtered_en.png", photo)
end

Rect

struct Rect
A rectangle.
NameTypeDescription
xint = 0x.
yint = 0y.
widthint = 0The width.
heightint = 0The height.

The example for this item is shown with the ones above: opencv-Filters.salam

Color

struct Color
A color.
NameTypeDescription
rint = 0Red.
gint = 0Green.
bint = 0Blue.

The example for this item is shown with the ones above: opencv-Basics.salam

Constants and variables

COLOR_BGR2GRAY

const COLOR_BGR2GRAY: i32 = 0
Color conversion: BGR to gray.

The example for this item is shown with the ones above: opencv-Basics.salam

COLOR_GRAY2BGR

const COLOR_GRAY2BGR: i32 = 1
Color conversion: gray to BGR.

The example for this item is shown with the ones above: opencv-Basics.salam

COLOR_RGB2GRAY

const COLOR_RGB2GRAY: i32 = 2
Color conversion: RGB to gray.

The example for this item is shown with the ones above: opencv-Basics.salam

COLOR_GRAY2RGB

const COLOR_GRAY2RGB: i32 = 3
Color conversion: gray to RGB.

The example for this item is shown with the ones above: opencv-Basics.salam

COLOR_BGR2RGB

const COLOR_BGR2RGB: i32 = 4
Color conversion: BGR to RGB.

The example for this item is shown with the ones above: opencv-Basics.salam

COLOR_RGB2BGR

const COLOR_RGB2BGR: i32 = 5
Color conversion: RGB to BGR.

The example for this item is shown with the ones above: opencv-Basics.salam

COLOR_BGR2HSV

const COLOR_BGR2HSV: i32 = 6
Color conversion: BGR to HSV.

The example for this item is shown with the ones above: opencv-Basics.salam

COLOR_HSV2BGR

const COLOR_HSV2BGR: i32 = 7
Color conversion: HSV to BGR.

The example for this item is shown with the ones above: opencv-Basics.salam

COLOR_RGB2HSV

const COLOR_RGB2HSV: i32 = 8
Color conversion: RGB to HSV.

The example for this item is shown with the ones above: opencv-Basics.salam

COLOR_HSV2RGB

const COLOR_HSV2RGB: i32 = 9
Color conversion: HSV to RGB.

The example for this item is shown with the ones above: opencv-Basics.salam

THRESH_BINARY

const THRESH_BINARY: i32 = 0
Threshold: the maximum above the threshold, zero elsewhere.

The example for this item is shown with the ones above: opencv-Filters.salam

THRESH_BINARY_INV

const THRESH_BINARY_INV: i32 = 1
Threshold: inverted binary.

The example for this item is shown with the ones above: opencv-Filters.salam

THRESH_TRUNC

const THRESH_TRUNC: i32 = 2
Threshold: values above the threshold become the threshold.

The example for this item is shown with the ones above: opencv-Filters.salam

THRESH_TOZERO

const THRESH_TOZERO: i32 = 3
Threshold: values below the threshold become zero.

The example for this item is shown with the ones above: opencv-Filters.salam

THRESH_TOZERO_INV

const THRESH_TOZERO_INV: i32 = 4
Threshold: values above the threshold become zero.

The example for this item is shown with the ones above: opencv-Filters.salam

THRESH_OTSU

const THRESH_OTSU: i32 = 5
Threshold: Otsu's automatic threshold.

The example for this item is shown with the ones above: opencv-Filters.salam

ADAPTIVE_MEAN

const ADAPTIVE_MEAN: i32 = 0
Adaptive threshold with the neighborhood mean.

The example for this item is shown with the ones above: opencv-Filters.salam

ADAPTIVE_GAUSSIAN

const ADAPTIVE_GAUSSIAN: i32 = 1
Adaptive threshold with a Gaussian weighted mean.

The example for this item is shown with the ones above: opencv-Filters.salam

INTERP_NEAREST

const INTERP_NEAREST: i32 = 0
Interpolation: nearest neighbor.

The example for this item is shown with the ones above: opencv-Basics.salam

INTERP_LINEAR

const INTERP_LINEAR: i32 = 1
Interpolation: bilinear.

The example for this item is shown with the ones above: opencv-Basics.salam

INTERP_CUBIC

const INTERP_CUBIC: i32 = 2
Interpolation: bicubic.

The example for this item is shown with the ones above: opencv-Basics.salam

INTERP_AREA

const INTERP_AREA: i32 = 3
Interpolation: area based, the best for shrinking.

The example for this item is shown with the ones above: opencv-Basics.salam

INTERP_LANCZOS4

const INTERP_LANCZOS4: i32 = 4
Interpolation: Lanczos.

The example for this item is shown with the ones above: opencv-Basics.salam

ROTATE_90_CW

const ROTATE_90_CW: i32 = 0
Rotate ninety degrees clockwise.

The example for this item is shown with the ones above: opencv-Basics.salam

ROTATE_180

const ROTATE_180: i32 = 1
Rotate one hundred and eighty degrees.

The example for this item is shown with the ones above: opencv-Basics.salam

ROTATE_90_CCW

const ROTATE_90_CCW: i32 = 2
Rotate ninety degrees counterclockwise.

The example for this item is shown with the ones above: opencv-Basics.salam

FLIP_VERTICAL

const FLIP_VERTICAL: i32 = 0
Vertical flip.

The example for this item is shown with the ones above: opencv-Basics.salam

FLIP_HORIZONTAL

const FLIP_HORIZONTAL: i32 = 1
Horizontal flip.

The example for this item is shown with the ones above: opencv-Basics.salam

FLIP_BOTH

const FLIP_BOTH: i32 = 2
Flip in both directions.

The example for this item is shown with the ones above: opencv-Basics.salam

MORPH_OPEN

const MORPH_OPEN: i32 = 0
Opening: erosion then dilation; removes small specks.

The example for this item is shown with the ones above: opencv-Filters.salam

MORPH_CLOSE

const MORPH_CLOSE: i32 = 1
Closing: dilation then erosion; fills small holes.

The example for this item is shown with the ones above: opencv-Filters.salam

MORPH_GRADIENT

const MORPH_GRADIENT: i32 = 2
Gradient: the outline of the shapes.

The example for this item is shown with the ones above: opencv-Filters.salam

MORPH_TOPHAT

const MORPH_TOPHAT: i32 = 3
Top hat.

The example for this item is shown with the ones above: opencv-Filters.salam

MORPH_BLACKHAT

const MORPH_BLACKHAT: i32 = 4
Black hat.

The example for this item is shown with the ones above: opencv-Filters.salam

BITWISE_AND

const BITWISE_AND: i32 = 0
Bitwise AND.

The example for this item is shown with the ones above: opencv-Filters.salam

BITWISE_OR

const BITWISE_OR: i32 = 1
Bitwise OR.

The example for this item is shown with the ones above: opencv-Filters.salam

BITWISE_XOR

const BITWISE_XOR: i32 = 2
Bitwise exclusive or.

The example for this item is shown with the ones above: opencv-Filters.salam

NORM_HAMMING

const NORM_HAMMING: i32 = 0
Hamming distance; for ORB descriptors.

The example for this item is shown with the ones above: opencv-Features.salam

NORM_L2

const NORM_L2: i32 = 1
Euclidean distance; for SIFT.

The example for this item is shown with the ones above: opencv-Features.salam

Functions

OpenVideo

func OpenVideo(path: str): VideoCapture
Opens a video file.

The example for this item is shown with the ones above: opencv-Detect.salam

OpenCamera

func OpenCamera(index: int): VideoCapture
A camera by number.

The example for this item is shown with the ones above: opencv-Detect.salam

NewVideoWriter

func NewVideoWriter(path: str, fourcc: str, fps: f64, width: int, height: int): VideoWriter
A writer with a four letter codec, frames per second and a size.

The example for this item is shown with the ones above: opencv-Detect.salam

LoadCascade

func LoadCascade(path: str): CascadeClassifier
Loads a classifier from an XML file.

The example for this item is shown with the ones above: opencv-Detect.salam

MatchDescriptors

func MatchDescriptors(desc1: Mat, desc2: Mat, max_matches: int, norm: int): Vector<Match>
The best matches between two sets of descriptors.

The example for this item is shown with the ones above: opencv-Features.salam

LoadNet

func LoadNet(model_path: str, config_path: str): Net
A model and its configuration, such as Caffe.

The example for this item is shown with the ones above: opencv-Detect.salam

LoadNetSingleFile

func LoadNetSingleFile(path: str): Net
A single file model, such as ONNX.

The example for this item is shown with the ones above: opencv-Detect.salam

ParseSSDDetections

func ParseSSDDetections(output: Mat, img_width: int, img_height: int, confidence_threshold: f64): Vector<Detection>
Turns SSD output into the objects whose confidence is above the threshold.

The example for this item is shown with the ones above: opencv-Detect.salam

Imshow

func Imshow(window: str, m: Mat)
Shows an image in a window.

The example for this item is shown with the ones above: opencv-Detect.salam

WaitKey

func WaitKey(delay_ms: int): int
Waits up to delay milliseconds for a key; the key code or -1.

The example for this item is shown with the ones above: opencv-Detect.salam

DestroyWindow

func DestroyWindow(window: str)
Closes a window.

The example for this item is shown with the ones above: opencv-Detect.salam

DestroyAllWindows

func DestroyAllWindows()
Closes all windows.

The example for this item is shown with the ones above: opencv-Detect.salam

CreateTrackbar

func CreateTrackbar(name: str, window: str, initial: int, max: int): bool
A slider in a window.

The example for this item is shown with the ones above: opencv-Detect.salam

GetTrackbarPos

func GetTrackbarPos(name: str, window: str): int
The position of a slider.

The example for this item is shown with the ones above: opencv-Detect.salam

SetTrackbarPos

func SetTrackbarPos(name: str, window: str, pos: int)
Sets the position.

The example for this item is shown with the ones above: opencv-Detect.salam

LastError

func LastError(): str
The message of the last error.

The example for this item is shown with the ones above: opencv-Basics.salam

Available

func Available(): bool
Whether the OpenCV library is loaded.

The example for this item is shown with the ones above: opencv-Basics.salam

Version

func Version(): str
The OpenCV version.

The example for this item is shown with the ones above: opencv-Basics.salam

RGB

func RGB(r: int, g: int, b: int): Color
A color from red, green and blue.

The example for this item is shown with the ones above: opencv-Basics.salam

Black

func Black(): Color
Black.

The example for this item is shown with the ones above: opencv-Basics.salam

White

func White(): Color
White.

The example for this item is shown with the ones above: opencv-Basics.salam

Red

func Red(): Color
Red.

The example for this item is shown with the ones above: opencv-Basics.salam

Green

func Green(): Color
Green.

The example for this item is shown with the ones above: opencv-Basics.salam

Blue

func Blue(): Color
Blue.

The example for this item is shown with the ones above: opencv-Basics.salam

Read

func Read(path: str): Mat
Reads an image from a file.

The example for this item is shown with the ones above: opencv-Basics.salam

Write

func Write(path: str, m: Mat): bool
Writes an image to a file.

The example for this item is shown with the ones above: opencv-Basics.salam

NewBlank

func NewBlank(width: int, height: int, channels: int, fill: Color): Mat
A canvas filled with a color.

The example for this item is shown with the ones above: opencv-Basics.salam

Zeros

func Zeros(width: int, height: int, channels: int): Mat
A black canvas.

The example for this item is shown with the ones above: opencv-Basics.salam

FromImage

func FromImage(img: image.Image): Mat
From an image of the image package.

The example for this item is shown with the ones above: opencv-Detect.salam

ToImage

func ToImage(m: Mat): image.Image
To an image of the image package.

The example for this item is shown with the ones above: opencv-Detect.salam