Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass MyClass[][] for MyClass**?

Why can't I pass

    Point src[1][4] = {
        {
            Point(border,border), Point(border,h-border), Point(w-border,h-border), Point(w-border,h-border)
        }
    };

as

polylines(frame, src, ns, 1, true, CV_RGB(255,255,255), 2); 

where

polylines has prototype

void polylines(Mat& img, const Point** pts, const int* npts, int ncontours, bool isClosed, const Scalar& color, int thickness=1, int lineType=8, int shift=0 )

UPDATE

Okay, okay, I remembered this stuff :)

like image 405
Suzan Cioc Avatar asked Mar 24 '23 13:03

Suzan Cioc


1 Answers

Point[1][4] can't be converted to Point** this way.
Have a look at this question: Converting multidimensional arrays to pointers in c++

The actual solution here is to use STL container instead of C-style array, e.g. std::vector:

typedef std::vector<Point> Shape;
std::vector<Shape> myShapes;
...

and pass it by const reference instead of const pointer:

void polylines(Mat& img, const std::vector<Shape>& shapes, ...)

Also note that src, ns, pts, etc. aren't very lucky names for your variables. Try to choose more meaningful names... if not for your own sake, then do it for the sake of future readers of that code :)

like image 173
LihO Avatar answered Apr 06 '23 17:04

LihO