Ask Your Question

Revision history [back]

How to add the points[4] to the contours by using opencv framework

I'm currently using opencv framework(3.4.1) for object measuring, but I am not able to add points[4] to the contours. Please let me know how to add points[4] to the boxContours in the code below. I can pass boxContours to the drawContours only if I add points to the former.

std::vector<std::vector<cv::Point>> contours;
vector<cv::Vec4i> hierarchy;
cv::findContours( gray, contours, hierarchy, CV_RETR_EXTERNAL, 
CV_CHAIN_APPROX_SIMPLE);
for (int i = 0; i< contours.size(); i++)
{
cv::RotatedRect rect = cv::minAreaRect(contours[i]);
cv::Point2f points[4];
rect.points(points);
std::vector<std::vector<cv::Point2f>> boxContours;
cv::drawContours(image, boxContours, i,cvScalar(0,255,0),2);   
}
click to hide/show revision 2
retagged

updated 2018-03-23 02:13:35 -0600

berak gravatar image

How to add the points[4] to the contours by using opencv framework

I'm currently using opencv framework(3.4.1) for object measuring, but I am not able to add points[4] to the contours. Please let me know how to add points[4] to the boxContours in the code below. I can pass boxContours to the drawContours only if I add points to the former.

std::vector<std::vector<cv::Point>> contours;
vector<cv::Vec4i> hierarchy;
cv::findContours( gray, contours, hierarchy, CV_RETR_EXTERNAL, 
CV_CHAIN_APPROX_SIMPLE);
for (int i = 0; i< contours.size(); i++)
{
cv::RotatedRect rect = cv::minAreaRect(contours[i]);
cv::Point2f points[4];
rect.points(points);
std::vector<std::vector<cv::Point2f>> boxContours;
cv::drawContours(image, boxContours, i,cvScalar(0,255,0),2);   
}