Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If "contours" is vector<vector<point> what are its elements?

I am working with "findcontours". But, cannot get the type correct. Can someone please help? This code hits a error at:

 for (cont : contours);

The test code is as follows:

// ConsoleApplication 1-25-2018.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


/**
* file Smoothing.cpp
* brief Sample code for simple filters
* author OpenCV team
*/

#include <iostream>
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"

using namespace std;
using namespace cv;
Mat frame;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
vector<Point>  cont;

/**
* function main
*/
int main(int argc, char ** argv)
{
    Mat frame;
    frame = imread("lena.jpg");
    imshow("Lena.jpg", frame);
    waitKey();
    dilate(frame, frame, 1);
    imshow("dilate", frame);
    waitKey();
    findContours(frame, contours, hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE);

    for (cont : contours);
    {
        Moments mu = moments(cont, false);
        if (mu.get_m00() > 100.0) {}
    }
}

If "contours" is vector<vector<point> what are its elements?

I am working with "findcontours". But, cannot get the type correct. Can someone please help? This code hits a error at:

 for (cont : contours);

The test code is as follows:

// ConsoleApplication 1-25-2018.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


/**
* file Smoothing.cpp
* brief Sample code for simple filters
* author OpenCV team
*/

#include <iostream>
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"

using namespace std;
using namespace cv;
Mat frame;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
vector<Point>  cont;

/**
* function main
*/
int main(int argc, char ** argv)
{
    Mat frame;
    frame = imread("lena.jpg");
    imshow("Lena.jpg", frame);
    waitKey();
    dilate(frame, frame, 1);
    imshow("dilate", frame);
    waitKey();
    findContours(frame, contours, hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE);

    for (cont : contours);
    {
        Moments mu = moments(cont, false);
        if (mu.get_m00() > 100.0) {}
    }
}

If "contours" is vector<vector<point> what are its elements?

I am working with "findcontours". But, cannot get the type correct. Can someone please help? This code hits a error at:

 for (cont : contours);

The test code is as follows:

// ConsoleApplication 1-25-2018.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


/**
* file Smoothing.cpp
* brief Sample code for simple filters
* author OpenCV team
*/

#include <iostream>
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"

using namespace std;
using namespace cv;
Mat frame;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
vector<Point>  cont;

/**
* function main
*/
int main(int argc, char ** argv)
{
    Mat frame;
    frame = imread("lena.jpg");
    imshow("Lena.jpg", frame);
    waitKey();
    dilate(frame, frame, 1);
    imshow("dilate", frame);
    waitKey();
    findContours(frame, contours, hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE);

    for (cont : contours);
    {
        Moments mu = moments(cont, false);
        if (mu.get_m00() > 100.0) {}
    }
}