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§

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
C++ default parameters
  • connectivity: 8
  • left_to_right: false
C++ default parameters
  • connectivity: 8
  • left_to_right: false
C++ default parameters
  • connectivity: 8
  • left_to_right: false

Trait Implementations§

Wrap the specified raw pointer Read more
Return an the underlying raw pointer while consuming this wrapper. Read more
Return the underlying raw pointer. Read more
Return the underlying mutable raw pointer Read more
Executes the destructor for this type. Read more
Returns pointer to the current pixel.
Moves iterator to the next pixel on the line. Read more
Returns coordinates of the current pixel.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.