Reputation: 41
I am trying to store the location of four specific points and then putting it into the cv::fillPoly
function. Currently my locations are stored in a multidimensional array is there a way to convert this or make it straight into a format it accepts?
int PointLocationArray[4][2] = {{point1_x, point1_y}, {point2_x, point2_y}, {point3_x, point3_y}, {point4_x, point4_y}};
and I'm trying to get it into:
cv::fillPoly(newRegion, PointLocationArray, 255);
Upvotes: 1
Views: 177
Reputation: 52417
A very simple way is to start with a flat array and then reshape the matrix:
static const std::vector<double> data = { 1.0, 2.0, 1.0, 2.0 }; // two points
Mat ret = Mat(data).reshape(2, 2);
Note: This way, ret
is a wrapper around data
. If you would like to copy the data instead, use Mat(data, true)
.
Another way is to use a combination of <<
operator and ,
operator for initialization, again, providing the values in a flat manner:
Mat ret = (Mat_<double>(2, 2) << 1.0, 2.0, 1.0, 2.0);
Upvotes: 1