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
impl LineIterator
sourcepub fn new(
img: &impl MatTraitConst,
pt1: Point,
pt2: Point,
connectivity: i32,
left_to_right: bool,
) -> Result<LineIterator>
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
sourcepub fn new_def(
img: &impl MatTraitConst,
pt1: Point,
pt2: Point,
) -> Result<LineIterator>
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
sourcepub fn new_1(
pt1: Point,
pt2: Point,
connectivity: i32,
left_to_right: bool,
) -> Result<LineIterator>
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
sourcepub fn new_def_1(pt1: Point, pt2: Point) -> Result<LineIterator>
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
sourcepub fn new_2(
bounding_area_size: Size,
pt1: Point,
pt2: Point,
connectivity: i32,
left_to_right: bool,
) -> Result<LineIterator>
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
sourcepub fn new_def_2(
bounding_area_size: Size,
pt1: Point,
pt2: Point,
) -> Result<LineIterator>
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
Trait Implementations§
source§impl Boxed for LineIterator
impl Boxed for LineIterator
source§unsafe fn from_raw(
ptr: <LineIterator as OpenCVFromExtern>::ExternReceive,
) -> Self
unsafe fn from_raw( ptr: <LineIterator as OpenCVFromExtern>::ExternReceive, ) -> Self
source§fn into_raw(self) -> <LineIterator as OpenCVTypeExternContainer>::ExternSendMut
fn into_raw(self) -> <LineIterator as OpenCVTypeExternContainer>::ExternSendMut
source§fn as_raw(&self) -> <LineIterator as OpenCVTypeExternContainer>::ExternSend
fn as_raw(&self) -> <LineIterator as OpenCVTypeExternContainer>::ExternSend
source§fn as_raw_mut(
&mut self,
) -> <LineIterator as OpenCVTypeExternContainer>::ExternSendMut
fn as_raw_mut( &mut self, ) -> <LineIterator as OpenCVTypeExternContainer>::ExternSendMut
source§impl Debug for LineIterator
impl Debug for LineIterator
source§impl Drop for LineIterator
impl Drop for LineIterator
source§impl LineIteratorTrait for LineIterator
impl LineIteratorTrait for LineIterator
fn as_raw_mut_LineIterator(&mut self) -> *mut c_void
fn ptr_mut(&mut self) -> *mut u8
unsafe fn set_ptr(&mut self, val: *const u8)
fn set_step(&mut self, val: i32)
fn set_elem_size(&mut self, val: i32)
fn set_err(&mut self, val: i32)
fn set_count(&mut self, val: i32)
fn set_minus_delta(&mut self, val: i32)
fn set_plus_delta(&mut self, val: i32)
fn set_minus_step(&mut self, val: i32)
fn set_plus_step(&mut self, val: i32)
fn set_minus_shift(&mut self, val: i32)
fn set_plus_shift(&mut self, val: i32)
fn set_p(&mut self, val: Point)
fn set_ptmode(&mut self, val: bool)
fn init( &mut self, img: &impl MatTraitConst, bounding_area_rect: Rect, pt1: Point, pt2: Point, connectivity: i32, left_to_right: bool, ) -> Result<()>
source§impl LineIteratorTraitConst for LineIterator
impl LineIteratorTraitConst for LineIterator
fn as_raw_LineIterator(&self) -> *const c_void
fn ptr(&self) -> *const u8
fn ptr0(&self) -> *const u8
fn step(&self) -> i32
fn elem_size(&self) -> i32
fn err(&self) -> i32
fn count(&self) -> i32
fn minus_delta(&self) -> i32
fn plus_delta(&self) -> i32
fn minus_step(&self) -> i32
fn plus_step(&self) -> i32
fn minus_shift(&self) -> i32
fn plus_shift(&self) -> i32
fn p(&self) -> Point
fn ptmode(&self) -> bool
impl Send for LineIterator
Auto Trait Implementations§
impl Freeze for LineIterator
impl RefUnwindSafe for LineIterator
impl !Sync for LineIterator
impl Unpin for LineIterator
impl UnwindSafe for LineIterator
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Mat> ModifyInplace for Matwhere
Mat: Boxed,
impl<Mat> ModifyInplace for Matwhere
Mat: Boxed,
source§unsafe fn modify_inplace<Res>(
&mut self,
f: impl FnOnce(&Mat, &mut Mat) -> Res,
) -> Res
unsafe fn modify_inplace<Res>( &mut self, f: impl FnOnce(&Mat, &mut Mat) -> Res, ) -> Res
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