Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Ok I switch on my crystal ball and it says to me that either you try to make contourArea() on your whole image or you do the contourArea() function on the whole vector of your found contours. So use contourArea() like this:

Mat img = imread("My/image/path", IMREAD_ANYCOLOR);
Mat imgThresh;
threshold(img, imgThresh, nThreshold, 255, THRESH_BINARY);

vector<Mat> myContours; // This is the same as vector<vector<Point>> myContours
findContours(imgThresh, myContours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE, Point(0,0));

for(int i=0; i<myContours.rows; i++) { // or myContours.size() if vector<vector<Point>> is used
    double area = contourArea(myContours[i]);
}

The negative vote from me is for switching on the crystal ball. Next time write some example code in your question.

Ok I switch on my crystal ball and it says to me that either you try to make contourArea() on your whole image or you do the contourArea() function on the whole vector of your found contours. So use contourArea() like this:

Mat img = imread("My/image/path", imread("My/image/path.bmp", IMREAD_ANYCOLOR);
Mat imgThresh;
threshold(img, imgThresh, nThreshold, 255, THRESH_BINARY);

vector<Mat> myContours; // This is the same as vector<vector<Point>> myContours
findContours(imgThresh, myContours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE, Point(0,0));

for(int i=0; i<myContours.rows; i++) { // or myContours.size() if vector<vector<Point>> is used
    double area = contourArea(myContours[i]);
}

The negative vote from me is for switching on the crystal ball. Next time write some example code in your question.

Ok I switch on my crystal ball and it says to me that either you try to make contourArea() on your whole image or you do the contourArea() function on the whole vector of your found contours. So use contourArea() like this:

Mat cv::Mat img = imread("My/image/path.bmp", cv::imread("My/image/path.bmp", IMREAD_ANYCOLOR);
Mat cv::Mat imgThresh;
threshold(img, cv::threshold(img, imgThresh, nThreshold, 255, THRESH_BINARY);

vector<Mat> vector<cv::Mat> myContours; // This is the same as vector<vector<Point>> myContours
findContours(imgThresh, cv::findContours(imgThresh, myContours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE, Point(0,0));

for(int i=0; i<myContours.rows; i++) { // or myContours.size() if vector<vector<Point>> is used
    double area = contourArea(myContours[i]);
cv::contourArea(myContours[i]);
}

The negative vote from me is for switching on the crystal ball. Next time write some example code in your question.

Ok I switch on my crystal ball and it says to me that either you try to make contourArea() on your whole image or you do the contourArea() function on the whole vector of your found contours. So use contourArea() like this:

cv::Mat //This should include most of the OpenCV functions
#include <opencv2/opencv.hpp>

using namespace cv;


Mat img = cv::imread("My/image/path.bmp", imread("My/image/path.bmp", IMREAD_ANYCOLOR);
cv::Mat Mat imgThresh;
cv::threshold(img, threshold(img, imgThresh, nThreshold, 255, THRESH_BINARY);

vector<cv::Mat> vector<Mat> myContours; // This is the same as vector<vector<Point>> myContours
cv::findContours(imgThresh, findContours(imgThresh, myContours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE, Point(0,0));

for(int i=0; i<myContours.rows; i++) { // or myContours.size() if vector<vector<Point>> is used
    double area = cv::contourArea(myContours[i]);
contourArea(myContours[i]);
}

The negative vote from me is for switching on the crystal ball. Next time write some example code in your question.

Edit: Added #include and using namespace to code snippet

Ok I switch on my crystal ball and it says to me that either you try to make contourArea() on your whole image or you do the contourArea() function on the whole vector of your found contours. So use contourArea() like this:

//This should include most of the OpenCV functions
#include <opencv2/opencv.hpp>

using namespace cv;


Mat img = imread("My/image/path.bmp", IMREAD_ANYCOLOR);
Mat imgThresh;
threshold(img, imgThresh, nThreshold, 255, THRESH_BINARY);

vector<Mat> myContours; // This is the same as vector<vector<Point>> std::vector<std::vector<Point>> myContours
findContours(imgThresh, myContours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE, Point(0,0));

for(int i=0; i<myContours.rows; i++) { // or myContours.size() if vector<vector<Point>> std::vector<std::vector<Point>> is used
    double area = contourArea(myContours[i]);
contourArea(myContours[i]); // Perhabs it is contourArea(Mat(myContours[i])) when using std::vector<std::vector<Points>>
}

The negative vote from me is for switching on the crystal ball. Next time write some example code in your question.

Edit: Added #include and using namespace to code snippet

Ok I switch on my crystal ball and it says to me that either you try to make contourArea() on your whole image or you do the contourArea() function on the whole vector of your found contours. So use contourArea() like this:

//This should include most of the OpenCV functions
#include <opencv2/opencv.hpp>
<opencv2/opencv.hpp> // When using Opencv 3
//#include <opencv2/imgproc/imgproc.hpp> // When using OpenCV 2

using namespace cv;


Mat img = imread("My/image/path.bmp", IMREAD_ANYCOLOR);
Mat imgThresh;
threshold(img, imgThresh, nThreshold, 255, THRESH_BINARY);

vector<Mat> myContours; // This is the same as std::vector<std::vector<Point>> myContours
findContours(imgThresh, myContours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE, Point(0,0));

for(int i=0; i<myContours.rows; i++) { // or myContours.size() if std::vector<std::vector<Point>> is used
    double area = contourArea(myContours[i]); // Perhabs it is contourArea(Mat(myContours[i])) when using std::vector<std::vector<Points>>
}

The negative vote from me is for switching on the crystal ball. Next time write some example code in your question.

Edit: Added #include and using namespace to code snippet

Ok I switch on my crystal ball and it says to me that either you try to make contourArea() on your whole image or you do the contourArea() function on the whole vector of your found contours. So use contourArea() like this:

//This should include most of the OpenCV functions
#include <opencv2/opencv.hpp> // When using Opencv OpenCV 3
//#include <opencv2/imgproc/imgproc.hpp> // When using OpenCV 2

using namespace cv;


Mat img = imread("My/image/path.bmp", IMREAD_ANYCOLOR);
Mat imgThresh;
threshold(img, imgThresh, nThreshold, 255, THRESH_BINARY);

vector<Mat> myContours; // This is the same as std::vector<std::vector<Point>> myContours
findContours(imgThresh, myContours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE, Point(0,0));

for(int i=0; i<myContours.rows; i++) { // or myContours.size() if std::vector<std::vector<Point>> is used
    double area = contourArea(myContours[i]); // Perhabs it is contourArea(Mat(myContours[i])) when using std::vector<std::vector<Points>>
}

The negative vote from me is for switching on the crystal ball. Next time write some example code in your question.

Edit: Added #include and using namespace to code snippet