Something worng using LineIterator [closed]

asked 2013-05-21 11:34:31 -0600

wuling gravatar image

updated 2013-05-21 18:39:53 -0600

Hi all: I don't know happens using lielterator.The value of the variable buf[0]=47.Why???? Someone could tell me??? Thanks.

image description

image description

Original image: image description

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-21 12:50:05.671252



what exactly do you think is wrong here ?

it should be the pixel value for cp2.

berak gravatar imageberak ( 2013-05-21 12:50:01 -0600 )edit

Deae berak: cp2 is locations point(31,46),cp1 is locations pont(101,36), it's from pure black to pure white. so the data of the buf should be 0,0,....0,255,255,255,,,,,255.isn't.The code in the picture "LineIterator it(Img,cp2,cp1,4,false);" should be "LineIterator it(temp,cp2,cp1,4,false);"But I can't get correct the pixel of the line.

wuling gravatar imagewuling ( 2013-05-21 18:44:01 -0600 )edit

oh, right.

well, you're converting to grayscale(temp), but you're applying the LineIterator to the bgr-image (Img) is that intended ? should be iterating over Vec3b pixels then. (not that it would change the numbers, though)

berak gravatar imageberak ( 2013-05-22 01:03:13 -0600 )edit

Dear berak:i convert to gray. And i want to get the line in the gray piexl. so the code i change: if(Img.type()==CV_8UC1) { temp=Img; } else { cv::cvtColor(Img,temp,CV_BGR2GRAY); }

LineIterator it(temp,cp2,cp1,8,false);
for(int i = 0; i < it.count; i++, ++it)
    buf[i] =(const uchar) it.ptr[i];

But,unfortunatly,in some cases i get correct piexl, some cases are not. I try to convert BGR again.

wuling gravatar imagewuling ( 2013-05-22 01:33:29 -0600 )edit

I think it's Ok when gray image,using:
buf[i]=(const uchar) *it.ptr; & color image using: buf[i] =(const Vec3b) it.ptr[0]; thanks:)

wuling gravatar imagewuling ( 2013-05-22 03:00:05 -0600 )edit