Ask Your Question
0

LineIterator for non-8U images

asked 2017-01-16 11:09:32 -0600

Hi there!

I have a CV_32FC2 image, and need to iterate over a line on that image (C++). The LineIterator constructor does not report any issue, but from the pointer I can get only Vec2b -not Vec2f, as I need.

  • Is it possible to use the class for non-8U images?
  • Does the class do more than iterating over _coordinates_? -Is it somehow optimized for pixel value access?
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2017-01-16 11:34:44 -0600

updated 2017-01-16 11:36:06 -0600

  • Yes it is possible. I've used it on a CV_32F to iterate through pixel values along a line.

  • You don't access pixels with lineIterator. LineIterator will let you know the current position within the line. Then you use that position to access the Mat in order to retrieve the data. If it is not a intensive process, you can use the Mat::at<cv::Vec2f>(lineIterator.pos()) to make it simple. If you are accessing tens of thousands of pixels in a cycle I suggest you find other way to access the Mat pixels, since the Mat::at method is not the fastest way, but those are separate issues.

Cheers.

edit flag offensive delete link more

Comments

Okay -that means this class does not provide any pixel access optimization. I just wanted to make sure, as there is the third argument of the constructor (connectivity), and the ptr member, and this suggest me that the class has its own pixel access methods. Thanks!

mstankie gravatar imagemstankie ( 2017-01-17 04:57:31 -0600 )edit
2

answered 2017-01-16 11:30:23 -0600

LBerger gravatar image

updated 2017-01-16 11:33:44 -0600

I think you can try like this

Mat im(50,50,CV_32FC2);
Point pt1(10,10),pt2(20,30);
for (int i = 0; i<im.rows; i++)
    for (int j = 0; j<im.cols; j++)
        im.at<Vec2f>(i,j) = Vec2f(i,j);
cv::LineIterator it(im, pt1, pt2, 8);
for (int i = 0; i < it.count; i++, ++it)
{
        cv::Point p = it.pos();
        Vec2f pixelValue = im.at<Vec2f>(p);
       cout<<"pixel "<<p<<" = "<<pixelValue<<endl;
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-01-16 11:09:32 -0600

Seen: 468 times

Last updated: Jan 16 '17