Lets say I was given a boundingRect based on some points and stored it into a Rect object.
How can I use those points and create a mask in openCV? that is, everythin
You can call fillConvexPoly() by passing the four end points of the bounding Rect
.
// assume all four end points are stored in "vector roi_vertices" already
// the order of the vertices don't matter
Mat mask = Mat(height, width, CV_8UC1, Scalar(0));
// Create Polygon from vertices
vector roi_poly;
approxPolyDP(roi_vertices, roi_poly, 1.0, true);
// Fill polygon white
fillConvexPoly(mask, &roi_poly[0], (int)roi_poly.size(), 255, 8, 0);
P.S.: the above method will also work for generating masks for any (convex) polygons.