OpenCV  4.5.1
Open Source Computer Vision
Public Member Functions | Public Attributes | List of all members
cv::LineIterator Class Reference

Line iterator. More...

#include <opencv2/imgproc.hpp>

Public Member Functions

 LineIterator (const Mat &img, Point pt1, Point pt2, int connectivity=8, bool leftToRight=false)
 initializes the iterator More...
 
 LineIterator (Point pt1, Point pt2, int connectivity=8, bool leftToRight=false)
 
 LineIterator (Size boundingAreaSize, Point pt1, Point pt2, int connectivity=8, bool leftToRight=false)
 
 LineIterator (Rect boundingAreaRect, Point pt1, Point pt2, int connectivity=8, bool leftToRight=false)
 
void init (const Mat *img, Rect boundingAreaRect, Point pt1, Point pt2, int connectivity, bool leftToRight)
 
ucharoperator* ()
 returns pointer to the current pixel More...
 
LineIteratoroperator++ ()
 prefix increment operator (++it). shifts iterator to the next pixel More...
 
LineIterator operator++ (int)
 postfix increment operator (it++). shifts iterator to the next pixel More...
 
Point pos () const
 returns coordinates of the current pixel More...
 

Public Attributes

int count
 
int elemSize
 
int err
 
int minusDelta
 
int minusShift
 
int minusStep
 
Point p
 
int plusDelta
 
int plusShift
 
int plusStep
 
bool ptmode
 
ucharptr
 
const ucharptr0
 
int step
 

Detailed Description

Line iterator.

The class is used to iterate over all the pixels on the raster line segment connecting two specified points.

The class LineIterator is used to get each pixel of a raster line. It can be treated as 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);
}

Constructor & Destructor Documentation

◆ LineIterator() [1/4]

cv::LineIterator::LineIterator ( const Mat img,
Point  pt1,
Point  pt2,
int  connectivity = 8,
bool  leftToRight = false 
)
inline

initializes the iterator

creates iterators for the line connecting pt1 and pt2 the line will be clipped on the image boundaries the line is 8-connected or 4-connected If leftToRight=true, then the iteration is always done from the left-most point to the right most, not to depend on the ordering of pt1 and pt2 parameters;

◆ LineIterator() [2/4]

cv::LineIterator::LineIterator ( Point  pt1,
Point  pt2,
int  connectivity = 8,
bool  leftToRight = false 
)
inline

◆ LineIterator() [3/4]

cv::LineIterator::LineIterator ( Size  boundingAreaSize,
Point  pt1,
Point  pt2,
int  connectivity = 8,
bool  leftToRight = false 
)
inline

◆ LineIterator() [4/4]

cv::LineIterator::LineIterator ( Rect  boundingAreaRect,
Point  pt1,
Point  pt2,
int  connectivity = 8,
bool  leftToRight = false 
)
inline

Member Function Documentation

◆ init()

void cv::LineIterator::init ( const Mat img,
Rect  boundingAreaRect,
Point  pt1,
Point  pt2,
int  connectivity,
bool  leftToRight 
)

◆ operator*()

uchar* cv::LineIterator::operator* ( )

returns pointer to the current pixel

◆ operator++() [1/2]

LineIterator& cv::LineIterator::operator++ ( )

prefix increment operator (++it). shifts iterator to the next pixel

◆ operator++() [2/2]

LineIterator cv::LineIterator::operator++ ( int  )

postfix increment operator (it++). shifts iterator to the next pixel

◆ pos()

Point cv::LineIterator::pos ( ) const

returns coordinates of the current pixel

Member Data Documentation

◆ count

int cv::LineIterator::count

◆ elemSize

int cv::LineIterator::elemSize

◆ err

int cv::LineIterator::err

◆ minusDelta

int cv::LineIterator::minusDelta

◆ minusShift

int cv::LineIterator::minusShift

◆ minusStep

int cv::LineIterator::minusStep

◆ p

Point cv::LineIterator::p

◆ plusDelta

int cv::LineIterator::plusDelta

◆ plusShift

int cv::LineIterator::plusShift

◆ plusStep

int cv::LineIterator::plusStep

◆ ptmode

bool cv::LineIterator::ptmode

◆ ptr

uchar* cv::LineIterator::ptr

◆ ptr0

const uchar* cv::LineIterator::ptr0

◆ step

int cv::LineIterator::step

The documentation for this class was generated from the following file: