[−][src]Struct cv::Mat
This wraps OpenCV's Mat
class which is designed for n-dimensional dense
array. It's the most widely used data structure in image/video processing
since images are often stored as Mat
.
Fields
inner: *mut CMat
Pointer to the actual C/C++ data structure
cols: i32
Number of columns
rows: i32
Number of rows
depth: i32
Depth of this mat (it should be the type).
channels: i32
Channels of this mat
Methods
impl Mat
[src]
pub fn from_raw(raw: *mut CMat) -> Mat
[src]
Creates a Mat
object from raw CMat
pointer. This will read the rows
and cols of the image.
pub fn new() -> Mat
[src]
Creates an empty Mat
struct.
pub fn from_buffer(rows: i32, cols: i32, cv_type: i32, buf: &Vec<u8>) -> Mat
[src]
Creates a new Mat
from buffer. Note that internally opencv function
won't take ownership of the Mat, but when we call drop
, it will
deallocate the memory. To prevent double-freeing, you must mem::forget
it after use.
The following example shows how to get the data from an image and create a new image with the data (also forgets it).
let buffer = image.data(); let size = image.size(); let s = (size.width * size.height * 3) as usize; let mut vec = Vec::with_capacity(s); unsafe { vec.set_len(s); copy(buffer, vec.as_mut_ptr(), s); } let new_image = Mat::from_buffer( size.height, size.width, CvType::Cv8UC3 as i32, &vec); // . . . use new_image here, such as new_image.show(..) . . . ::std::mem::forget(new_image);
pub fn with_size(rows: i32, cols: i32, t: i32) -> Self
[src]
Create an empty Mat
with specific size (rows, cols and types).
pub fn zeros(rows: i32, cols: i32, t: i32) -> Self
[src]
Create an empty Mat
with specific size (rows, cols and types).
pub fn data(&self) -> *const u8
[src]
Returns the raw data (as a uchar pointer)
pub fn total(&self) -> usize
[src]
Returns the total number of array elements. The method returns the number of array elements (a number of pixels if the array represents an image). For example, images with 1920x1080 resolution will return 2073600.
pub fn elem_size(&self) -> usize
[src]
Returns the matrix element size in bytes.
The method returns the matrix element size in bytes. For example, if the matrix type is CV_16SC3 , the method returns 3*sizeof(short) or 6.
pub fn elem_size1(&self) -> usize
[src]
Returns the size of each matrix element channel in bytes.
The method returns the matrix element channel size in bytes, that is, it ignores the number of channels. For example, if the matrix type is CV_16SC3 , the method returns sizeof(short) or 2.
pub fn step1(&self, i: c_int) -> usize
[src]
Returns a normalized step.
The method returns a matrix step divided by Mat::elemSize1() . It can be useful to quickly access an arbitrary matrix element
pub fn size(&self) -> Size2i
[src]
Returns the size of this matrix.
pub fn is_valid(&self) -> bool
[src]
Check if the Mat
is valid or not.
pub fn roi(&self, rect: Rect) -> Mat
[src]
Return a region of interest from a Mat
specfied by a Rect
.
pub fn logic_and(&mut self, mask: Mat)
[src]
Apply a mask to myself.
pub fn flip(&mut self, code: FlipCode)
[src]
Flips an image around vertical, horizontal, or both axes.
pub fn show(&self, name: &str, delay: i32) -> Result<(), Error>
[src]
Calls out to highgui to show the image, the duration is specified by
delay
.
pub fn cv_type(&self) -> Result<CvType, Error>
[src]
Returns the images type. For supported types, please see CvType.
impl Mat
[src]
pub fn at<T: FromBytes>(&self, i0: i32) -> T
[src]
Returns individual pixel (element) information within the Mat. This
function may need type annotation to assist FromBytes
trait.
- If matrix is of type
CV_8U
then useMat.at<u8>(y,x)
. - If matrix is of type
CV_8S
then useMat.at<i8>(y,x)
. - If matrix is of type
CV_16U
then useMat.at<u16>(y,x)
. - If matrix is of type
CV_16S
then useMat.at<i16>(y,x)
. - If matrix is of type
CV_32S
then useMat.at<i32>(y,x)
. - If matrix is of type
CV_32F
then useMat.at<f32>(y,x)
. - If matrix is of type
CV_64F
then useMat.at<f64>(y,x)
.
pub fn at2<T: FromBytes>(&self, i0: i32, i1: i32) -> T
[src]
Returns individual pixel (element) information within the Mat. This
function may need type annotation to assist FromBytes
trait.
pub fn at3<T: FromBytes>(&self, i0: i32, i1: i32, i2: i32) -> T
[src]
impl Mat
[src]
pub fn in_range(&self, lowerb: Scalar, upperb: Scalar) -> Mat
[src]
Checks if Mat elements lie between the elements of two other arrays
(lowerb and upperb). The output Mat has the same size as self
and
CV_8U type.
pub fn min_max_loc(&self, mask: Mat) -> (f64, f64, Point2i, Point2i)
[src]
Finds the global minimum and maximum in an array.
This function finds the minimum and maximum element values and their positions. The extremums are searched across the whole array or, if mask is not an empty array, in the specified array region.
N.B. Only work with single-channel Mat. For multi-channel arrays. If you need to find minimum or maximum elements across all the channels, use Mat::reshape first to reinterpret the array as single-channel. Or you may extract the particular channel using either extractImageCOI , or mixChannels, or split.
pub fn mix_channels(
&self,
nsrcs: isize,
ndsts: isize,
from_to: *const i32,
npairs: isize
) -> Mat
[src]
&self,
nsrcs: isize,
ndsts: isize,
from_to: *const i32,
npairs: isize
) -> Mat
Copy specified channels from self
to the specified channels of output
Mat
.
pub fn normalize(&self, alpha: f64, beta: f64, t: NormTypes) -> Mat
[src]
Normalize the Mat according to the normalization type.
pub fn and(&self, another: &Mat) -> Mat
[src]
Computes bitwise conjunction between two Mat
pub fn or(&self, another: &Mat) -> Mat
[src]
Computes bitwise disjunction between two Mat
pub fn xor(&self, another: &Mat) -> Mat
[src]
Computes bitwise "exclusive or" between two Mat
pub fn not(&self) -> Mat
[src]
Computes bitwise "exclusive or" between two Mat
pub fn count_non_zero(&self) -> i32
[src]
Counts non-zero array elements.
impl Mat
[src]
pub fn line(&self, pt1: Point2i, pt2: Point2i)
[src]
Draws a simple line.
pub fn line_custom(
&self,
pt1: Point2i,
pt2: Point2i,
color: Scalar,
thickness: i32,
linetype: LineTypes,
shift: i32
)
[src]
&self,
pt1: Point2i,
pt2: Point2i,
color: Scalar,
thickness: i32,
linetype: LineTypes,
shift: i32
)
Draws a line with custom color, thickness and linetype.
pub fn rectangle(&self, rect: Rect)
[src]
Draws a simple, thick, or filled up-right rectangle.
pub fn rectangle_custom(
&self,
rect: Rect,
color: Scalar,
thickness: i32,
linetype: LineTypes
)
[src]
&self,
rect: Rect,
color: Scalar,
thickness: i32,
linetype: LineTypes
)
Draws a rectangle with custom color, thickness and linetype.
pub fn rectangle2f(&self, rect: Rect2f)
[src]
Draw a simple, thick, or filled up-right rectangle.
pub fn ellipse(
&self,
center: Point2i,
axes: Size2i,
angle: f64,
start_angle: f64,
end_angle: f64
)
[src]
&self,
center: Point2i,
axes: Size2i,
angle: f64,
start_angle: f64,
end_angle: f64
)
Draws a simple, thick ellipse
pub fn ellipse_custom(
&self,
center: Point2i,
axes: Size2i,
angle: f64,
start_angle: f64,
end_angle: f64,
color: Scalar,
thickness: i32,
linetype: LineTypes,
shift: i32
)
[src]
&self,
center: Point2i,
axes: Size2i,
angle: f64,
start_angle: f64,
end_angle: f64,
color: Scalar,
thickness: i32,
linetype: LineTypes,
shift: i32
)
Draws a custom ellipse
pub fn cvt_color(&self, code: ColorConversionCodes) -> Mat
[src]
Convert an image from one color space to another.
pub fn pyr_down(&self) -> Mat
[src]
Blurs an image and downsamples it. This function performs the downsampling step of the Gaussian pyramid construction.
pub fn resize_to(&self, dsize: Size2i, interpolation: InterpolationFlag) -> Mat
[src]
Resizes an image.
The function resize resizes the image down to or up to the specified size.
pub fn resize_by(
&self,
fx: f64,
fy: f64,
interpolation: InterpolationFlag
) -> Mat
[src]
&self,
fx: f64,
fy: f64,
interpolation: InterpolationFlag
) -> Mat
Resizes an image.
The function resize resizes the image down to or up to the specified size.
pub fn calc_hist(
&self,
channels: *const c_int,
mask: Mat,
dims: c_int,
hist_size: *const c_int,
ranges: *const *const f32
) -> Mat
[src]
&self,
channels: *const c_int,
mask: Mat,
dims: c_int,
hist_size: *const c_int,
ranges: *const *const f32
) -> Mat
Calculate a histogram of an image.
pub fn calc_back_project(
&self,
channels: *const i32,
hist: &Mat,
ranges: *const *const f32
) -> Mat
[src]
&self,
channels: *const i32,
hist: &Mat,
ranges: *const *const f32
) -> Mat
Calculate the back projection of a histogram. The function calculates the back project of the histogram.
impl Mat
[src]
pub fn from_path<P: AsRef<Path>>(path: P, flags: ImreadModes) -> Option<Mat>
[src]
Creates a Mat
from reading the image specified by the path.
pub fn imdecode(buf: &[u8], mode: ImreadModes) -> Mat
[src]
Decodes an image from buf
according to the specified mode.
pub fn imencode(&self, ext: &str, f: Vec<ImwriteFlags>) -> Option<Vec<u8>>
[src]
Encodes an image; the encoding scheme depends on the extension provided; additional write flags can be passed in using a vector. If successful, returns an owned vector of the encoded image.
impl Mat
[src]
pub fn camshift(&self, wndw: Rect, criteria: &TermCriteria) -> RotatedRect
[src]
Finds an object center, size, and orientation; returns as RotatedRect
.
wndw
- initial search window.criteria
- stop criteria for the underlying meanShift.
Trait Implementations
impl Send for Mat
[src]
impl From<GpuMat> for Mat
[src]
impl From<Mat> for GpuMat
[src]
impl Drop for Mat
[src]
impl Debug for Mat
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,