opencv::imgproc

Struct LineIterator

source
pub struct LineIterator { /* private fields */ }
Expand description

Class for iterating over all pixels on a raster line segment.

The class LineIterator is used to get each pixel of a raster line connecting two specified points. It can be treated as a versatile implementation of the Bresenham algorithm where you can stop at each pixel and do some extra processing, for example, grab pixel values along the line or draw a line with an effect (for example, with XOR operation).

The number of pixels along the line is stored in LineIterator::count. The method LineIterator::pos returns the current position in the image:

// grabs pixels along the line (pt1, pt2)
// from 8-bit 3-channel image to the buffer
LineIterator it(img, pt1, pt2, 8);
LineIterator it2 = it;
vector<Vec3b> buf(it.count);

for(int i = 0; i < it.count; i++, ++it)
   buf[i] = *(const Vec3b*)*it;

// alternative way of iterating through the line
for(int i = 0; i < it2.count; i++, ++it2)
{
   Vec3b val = img.at<Vec3b>(it2.pos());
   CV_Assert(buf[i] == val);
}

Implementations§

source§

impl LineIterator

source

pub fn new( img: &impl MatTraitConst, pt1: Point, pt2: Point, connectivity: i32, left_to_right: bool, ) -> Result<LineIterator>

Initializes iterator object for the given line and image.

The returned iterator can be used to traverse all pixels on a line that connects the given two points. The line will be clipped on the image boundaries.

§Parameters
  • img: Underlying image.
  • pt1: First endpoint of the line.
  • pt2: The other endpoint of the line.
  • connectivity: Pixel connectivity of the iterator. Valid values are 4 (iterator can move up, down, left and right) and 8 (iterator can also move diagonally).
  • leftToRight: If true, the line is traversed from the leftmost endpoint to the rightmost endpoint. Otherwise, the line is traversed from \p pt1 to \p pt2.
§C++ default parameters
  • connectivity: 8
  • left_to_right: false
source

pub fn new_def( img: &impl MatTraitConst, pt1: Point, pt2: Point, ) -> Result<LineIterator>

Initializes iterator object for the given line and image.

The returned iterator can be used to traverse all pixels on a line that connects the given two points. The line will be clipped on the image boundaries.

§Parameters
  • img: Underlying image.
  • pt1: First endpoint of the line.
  • pt2: The other endpoint of the line.
  • connectivity: Pixel connectivity of the iterator. Valid values are 4 (iterator can move up, down, left and right) and 8 (iterator can also move diagonally).
  • leftToRight: If true, the line is traversed from the leftmost endpoint to the rightmost endpoint. Otherwise, the line is traversed from \p pt1 to \p pt2.
§Note

This alternative version of [new] function uses the following default values for its arguments:

  • connectivity: 8
  • left_to_right: false
source

pub fn new_1( pt1: Point, pt2: Point, connectivity: i32, left_to_right: bool, ) -> Result<LineIterator>

§C++ default parameters
  • connectivity: 8
  • left_to_right: false
source

pub fn new_def_1(pt1: Point, pt2: Point) -> Result<LineIterator>

§Note

This alternative version of [new] function uses the following default values for its arguments:

  • connectivity: 8
  • left_to_right: false
source

pub fn new_2( bounding_area_size: Size, pt1: Point, pt2: Point, connectivity: i32, left_to_right: bool, ) -> Result<LineIterator>

§C++ default parameters
  • connectivity: 8
  • left_to_right: false
source

pub fn new_def_2( bounding_area_size: Size, pt1: Point, pt2: Point, ) -> Result<LineIterator>

§Note

This alternative version of [new] function uses the following default values for its arguments:

  • connectivity: 8
  • left_to_right: false
source

pub fn new_3( bounding_area_rect: Rect, pt1: Point, pt2: Point, connectivity: i32, left_to_right: bool, ) -> Result<LineIterator>

§C++ default parameters
  • connectivity: 8
  • left_to_right: false
source

pub fn new_def_3( bounding_area_rect: Rect, pt1: Point, pt2: Point, ) -> Result<LineIterator>

§Note

This alternative version of [new] function uses the following default values for its arguments:

  • connectivity: 8
  • left_to_right: false

Trait Implementations§

source§

impl Boxed for LineIterator

source§

unsafe fn from_raw( ptr: <LineIterator as OpenCVFromExtern>::ExternReceive, ) -> Self

Wrap the specified raw pointer Read more
source§

fn into_raw(self) -> <LineIterator as OpenCVTypeExternContainer>::ExternSendMut

Return the underlying raw pointer while consuming this wrapper. Read more
source§

fn as_raw(&self) -> <LineIterator as OpenCVTypeExternContainer>::ExternSend

Return the underlying raw pointer. Read more
source§

fn as_raw_mut( &mut self, ) -> <LineIterator as OpenCVTypeExternContainer>::ExternSendMut

Return the underlying mutable raw pointer Read more
source§

impl Debug for LineIterator

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for LineIterator

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl LineIteratorTrait for LineIterator

source§

fn as_raw_mut_LineIterator(&mut self) -> *mut c_void

source§

fn ptr_mut(&mut self) -> *mut u8

source§

unsafe fn set_ptr(&mut self, val: *const u8)

source§

fn set_step(&mut self, val: i32)

source§

fn set_elem_size(&mut self, val: i32)

source§

fn set_err(&mut self, val: i32)

source§

fn set_count(&mut self, val: i32)

source§

fn set_minus_delta(&mut self, val: i32)

source§

fn set_plus_delta(&mut self, val: i32)

source§

fn set_minus_step(&mut self, val: i32)

source§

fn set_plus_step(&mut self, val: i32)

source§

fn set_minus_shift(&mut self, val: i32)

source§

fn set_plus_shift(&mut self, val: i32)

source§

fn set_p(&mut self, val: Point)

source§

fn set_ptmode(&mut self, val: bool)

source§

fn init( &mut self, img: &impl MatTraitConst, bounding_area_rect: Rect, pt1: Point, pt2: Point, connectivity: i32, left_to_right: bool, ) -> Result<()>

source§

fn try_deref_mut(&mut self) -> Result<*mut u8>

Returns pointer to the current pixel.
source§

fn incr(&mut self) -> Result<LineIterator>

Moves iterator to the next pixel on the line. Read more
source§

impl LineIteratorTraitConst for LineIterator

source§

fn as_raw_LineIterator(&self) -> *const c_void

source§

fn ptr(&self) -> *const u8

source§

fn ptr0(&self) -> *const u8

source§

fn step(&self) -> i32

source§

fn elem_size(&self) -> i32

source§

fn err(&self) -> i32

source§

fn count(&self) -> i32

source§

fn minus_delta(&self) -> i32

source§

fn plus_delta(&self) -> i32

source§

fn minus_step(&self) -> i32

source§

fn plus_step(&self) -> i32

source§

fn minus_shift(&self) -> i32

source§

fn plus_shift(&self) -> i32

source§

fn p(&self) -> Point

source§

fn ptmode(&self) -> bool

source§

fn pos(&self) -> Result<Point>

Returns coordinates of the current pixel.
source§

impl Send for LineIterator

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<Mat> ModifyInplace for Mat
where Mat: Boxed,

source§

unsafe fn modify_inplace<Res>( &mut self, f: impl FnOnce(&Mat, &mut Mat) -> Res, ) -> Res

Helper function to call OpenCV functions that allow in-place modification of a Mat or another similar object. By passing a mutable reference to the Mat to this function your closure will get called with the read reference and a write references to the same Mat. This is unsafe in a general case as it leads to having non-exclusive mutable access to the internal data, but it can be useful for some performance sensitive operations. One example of an OpenCV function that allows such in-place modification is imgproc::threshold. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.