Skip to content

fillPoly cannot be used #16875

@SYKhor

Description

@SYKhor
System information (version)
  • OpenCV =>4.2, 4.1.2
  • Operating System / Platform => Windows 64 Bit
  • Compiler =>Visual Studio 2019
Detailed description

There is fillPoly bugs on the bellow overload function in drawing folder, It must change as polylines function:

void cv::fillPoly(InputOutputArray img, InputArrayOfArrays pts,
                  const Scalar& color, int lineType, int shift, Point offset)
{
    CV_INSTRUMENT_REGION();
    int i, ncontours = (int)pts.total();

    if( ncontours == 0 )

        return;

    AutoBuffer<Point*> _ptsptr(ncontours);

    AutoBuffer<int> _npts(ncontours);

    Point** ptsptr = _ptsptr.data();

    int* npts = _npts.data();



    for( i = 0; i < ncontours; i++ )

    {

        Mat p = pts.getMat(i);

        CV_Assert(p.checkVector(2, CV_32S) >= 0);

        ptsptr[i] = p.ptr<Point>();

        npts[i] = p.rows*p.cols*p.channels()/2;

    }

    fillPoly(img, (const Point**)ptsptr, npts, (int)ncontours, color, lineType, shift, offset);

}



void cv::polylines(InputOutputArray img, InputArrayOfArrays pts,

                   bool isClosed, const Scalar& color,

                   int thickness, int lineType, int shift)

{

    CV_INSTRUMENT_REGION();



    bool manyContours = pts.kind() == _InputArray::STD_VECTOR_VECTOR ||

                        pts.kind() == _InputArray::STD_VECTOR_MAT;

    int i, ncontours = manyContours ? (int)pts.total() : 1;

    if( ncontours == 0 )

        return;

    AutoBuffer<Point*> _ptsptr(ncontours);

    AutoBuffer<int> _npts(ncontours);

    Point** ptsptr = _ptsptr.data();

    int* npts = _npts.data();



    for( i = 0; i < ncontours; i++ )

    {

        Mat p = pts.getMat(manyContours ? i : -1);

        if( p.total() == 0 )

        {

            ptsptr[i] = NULL;

            npts[i] = 0;

            continue;

        }

        CV_Assert(p.checkVector(2, CV_32S) >= 0);

        ptsptr[i] = p.ptr<Point>();

        npts[i] = p.rows*p.cols*p.channels()/2;

    }

    polylines(img, (const Point**)ptsptr, npts, (int)ncontours, isClosed, color, thickness, lineType, shift);

}
Steps to reproduce

We have to change after CV_INSTRUMENT_REGION();
until if( ncontours == 0 )

It is ncontours number problem it generate error

should let

int i, ncontours = (int)pts.total();

replace by
bool manyContours = pts.kind() == _InputArray::STD_VECTOR_VECTOR ||
pts.kind() == _InputArray::STD_VECTOR_MAT;
int i, ncontours = manyContours ? (int)pts.total() : 1;

Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    answers.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

Labels

Hackathonhttps://opencv.org/opencv-hackathon-starts-next-week/category: imgproc

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions