API reference
OpenCV.OpenCV — Module
OpenCV.jl wraps the OpenCV computer-vision library for Julia.
Images and matrices are represented by Mat, a 3-dimensional AbstractArray that shares memory with OpenCV's cv::Mat. Mind the axis order: a cv::Mat is exposed with axes (channels, cols, rows) — see Mat for details and the consequences for descriptor/result matrices.
The bindings are generated from the OpenCV headers (see gen/); the full list of wrapped methods is in gen/funclist.csv.
This page documents the hand-written Julia surface of OpenCV.jl: the image/array types, the geometry primitives, and the FileIO integration.
The thousands of wrapped OpenCV functions (imread, cvtColor, GaussianBlur, ORB_create, …) keep their C++ names with the cv:: namespace stripped and are reached through the OpenCV. prefix — e.g. cv::cvtColor is OpenCV.cvtColor and the flag cv::IMREAD_GRAYSCALE is OpenCV.IMREAD_GRAYSCALE. See Core concepts for the naming and data conventions, and Wrapped functions for the complete generated list.
Image and array types
OpenCV.Mat — Type
Mat{T,M,D} <: AbstractArray{T,3}The image/array type of OpenCV.jl: a 3-dimensional AbstractArray view that shares memory with an OpenCV cv::Mat (no copy).
Memory layout
A cv::Mat is exposed to Julia with axes (channels, cols, rows) — that is, size(m) == (nchannels, width, height). This is OpenCV's row-major height × width × channels buffer reinterpreted in Julia's column-major order, so the bytes are shared with C++ directly.
Things to remember:
- A grayscale
H×Wimage hassize == (1, W, H). - A 3-channel
H×Wimage hassize == (3, W, H). - Result matrices follow the same rule. For example, an ORB descriptor matrix of
Nkeypoints ×descriptorSizebytes hassize == (1, descriptorSize, N)— the keypoint axis is dimension 3, not 1.
Construction
Mat(data) wraps an existing AbstractArray{T,3} without copying; most OpenCV functions return Mats converted from C++.
Examples
julia> using OpenCV
julia> data = reshape(collect(UInt8, 1:24), 1, 4, 6); # (channels, cols, rows)
julia> m = OpenCV.Mat(data);
julia> size(m)
(1, 4, 6)OpenCV.Vec — Type
Vec{T,N,C,D} <: AbstractArray{T,1}A fixed-length, 1-dimensional AbstractArray view backing OpenCV's small fixed vectors (cv::Vec{T,N}) — for example the per-pixel channel tuple of a multi-channel Mat. Vec{T,N}(data) wraps a length-N array (throwing DimensionMismatch otherwise); Vec{T,N}(cxxobj) wraps a C++ object's storage in place.
Geometry primitives
OpenCV.Point — Type
Point{T}(x, y)A 2-D point with coordinates x, y (OpenCV cv::Point_). Pass the element type explicitly to match the wrapped signature, e.g. Point{Int32}(10, 20) for pixel coordinates or Point{Float32} for sub-pixel ones.
OpenCV.Point3 — Type
Point3{T}(x, y, z)A 3-D point with coordinates x, y, z (OpenCV cv::Point3_).
OpenCV.Size — Type
Size{T}(width, height)A width × height size (OpenCV cv::Size_). Note this is width-then-height, unlike a Mat's (channels, cols, rows) axes. Many functions expect Size{Int32}, e.g. Size{Int32}(640, 480).
OpenCV.Rect — Type
Rect{T}(x, y, width, height)An axis-aligned rectangle with top-left corner (x, y) and the given width and height (OpenCV cv::Rect_).
OpenCV.RotatedRect — Type
RotatedRect(center::Point{Float32}, size::Size{Float32}, angle::Float32)A rectangle rotated by angle degrees about center (OpenCV cv::RotatedRect).
OpenCV.Range — Type
Range(start, end_)A half-open integer index range [start, end_) (OpenCV cv::Range). end_ is spelled with a trailing underscore because end is a Julia keyword.
OpenCV.TermCriteria — Type
TermCriteria(type, maxCount, epsilon)Iteration stopping criterion for iterative algorithms (OpenCV cv::TermCriteria): stop after maxCount iterations and/or once the change falls below epsilon, according to type (a combination of TermCriteria_COUNT / TermCriteria_EPS).
OpenCV.cvComplex — Type
cvComplex{T}(re, im)A complex number with real part re and imaginary part im (OpenCV cv::Complex).
File and stream I/O
OpenCV.load — Function
load(f::File, [flags])
load(s::Stream, [flags])FileIO integration: decode an image file or stream into an OpenCV Mat. Registered for BMP/JP2/JPEG/PNG/TIFF, so FileIO.load("img.png") returns a Mat with the usual (channels, cols, rows) layout. The optional flags argument is an imread-style colour flag (e.g. OpenCV.IMREAD_GRAYSCALE).
OpenCV.save — Function
save(f::File, image, [params])
save(s::Stream, image, [params])FileIO integration: encode an OpenCV image (a Mat or any InputArray) to a file or stream. The format is taken from the File/Stream type; the optional params::Vector{Int32} is forwarded to imwrite/imencode (e.g. JPEG quality).
OpenCV.imdecode — Function
imdecode(buf::AbstractVector{UInt8}, [flags])Decode an encoded image held in a flat byte buffer (e.g. from imencode, a file read, or a network response) into a Mat. This convenience method reshapes buf into the 3D InputArray the generated imdecode expects; without flags it uses the same default as imread (IMREAD_COLOR_BGR). See issue #58.