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

asked 2018-03-23 01:57:46 -0600

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

berak gravatar image

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);   
}
edit retag flag offensive close merge delete

Comments

1

I think you have already posted here and got the answers. What else do you need?

Balaji R gravatar imageBalaji R ( 2018-03-23 02:03:17 -0600 )edit
1
  • this is entirely unrelated to IOS.
  • as @Balaji already pointed out on your (same) SO question, you don't have to use drawContours() (and you probably shouldn't), but can use easy line() calls
  • drawContours needs a vector<vector<Point>> (not the Point2f version)
berak gravatar imageberak ( 2018-03-23 02:03:44 -0600 )edit

Thanks @Balaji i will try it and let you know

santhosh21 gravatar imagesanthosh21 ( 2018-03-27 00:53:49 -0600 )edit