Ask Your Question

Revision history [back]

Change your code to this, and it will work :)

std::vector<Mat> contours;
Mat temp = gray_img->clone();
cv::findContours(temp, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
for (int i = 0; i < contours.size(); i++){
   double area = cv::contourArea(contours[i]); //"area" is correct, such as 5000.               
   int W2 = contours[i].rows;
   int H2 = contours[i].cols;
   cout << "W2 = " << W2 << ", H2 = " << H2 << endl;
}

Let the internal functionality of the Mat element handle the points vectorization.