[Bug Report ?] cvInitLineIterator and cvLine do not give the same results!!

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Bug Report ?] cvInitLineIterator and cvLine do not give the same results!!

adishavit
Hi,

   It seems that cvInitLineIterator and cvLine do not iterate in the same
pixels.
From my tests it seems that cvLine actually does the right thing and
cvInitLineIterator misses.
This is very strange since cvLine uses cvInitLineIterator!

Here's a small program to show the problem:

#include <iostream>

#include <cv.h>
#include <highgui.h>


using namespace std;


// from the OpenCV docs (slightly simplified)
int sum_line_pixels( IplImage* image, CvPoint pt1, CvPoint pt2 )
{
    CvLineIterator iterator;
    int sum = 0;
    int count = cvInitLineIterator( image, pt1, pt2, &iterator, 4, 1 );

    for( int i = 0; i < count; i++ )
    {
       sum += iterator.ptr[0];

       CV_NEXT_LINE_POINT(iterator);
    }
    return sum;
}

// from the OpenCV docs (slightly simplified)
void mark_line_pixels( IplImage* image, CvPoint pt1, CvPoint pt2 )
{
    CvLineIterator iterator;
    int count = cvInitLineIterator( image, pt1, pt2, &iterator, 4, 1 );

    for( int i = 0; i < count; i++ )
    {
       *iterator.ptr = 255; // mark all iterated pixels in WHITE

       CV_NEXT_LINE_POINT(iterator);
    }
}



void main()
{
    IplImage* img = cvCreateImage(cvSize(30,30),IPL_DEPTH_8U,1);
    CvPoint pt1 = {10,10};
    CvPoint pt2 = {20,20};

    cvSetZero(img);

    cout << "First sum = " << sum_line_pixels(img, pt1, pt2) << endl;

    mark_line_pixels(img, pt1, pt2);       // DRAW WHITE

    cout << "Second sum = " << sum_line_pixels(img, pt1, pt2) << endl;

    cvLine(img, pt1, pt2, CV_RGB(0,0,0),1);// DRAW black

    cout << "Third sum = " << sum_line_pixels(img, pt1, pt2) << endl;


    cvNamedWindow("img");
    cvShowImage("img",img);
    cvWaitKey(0);
    cvReleaseImage(&img);
}

Please advise,
Thanks,
Adi



[Non-text portions of this message have been removed]