Ask Your Question

Marko's profile - activity

2014-03-12 11:20:07 -0600 received badge  Scholar (source)
2014-03-12 05:16:31 -0600 asked a question findContours - theory

I am working on my thesis in which i am focusing on Computer vision. I need to write explanation to every part of my implementation. One part of my implementation is using method findContours, but i cant find any documentation which would explain the algorithm behind this method. If someone could point me to documentation which would descibe how this method works, that would be great. Thank you.

2014-02-20 03:38:19 -0600 commented question c++ OpenCV approxPolyDP causes Unhandled exception

Could be problem with my integration of openCV into VS2012 ??

2014-02-20 02:57:58 -0600 asked a question c++ OpenCV approxPolyDP causes Unhandled exception

Hi i am working on my school project regarding contours. Everything worked fine until i tried to use approxPolyDP which causes my VS2012 to throw this: Unhandled exception at at 0x000007FEFD0E940D in hugh.exe: Microsoft C++ exception: cv::Exception at memory location 0x00000000002DEC40.

I think that code should be fine, so thats why i am kinda lost.

Here is my code, all help is appreciated:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

#include <sstream>
#include <string>
#include <iostream>
#include <opencv\highgui.h>
#include <opencv\cv.h>
#include <opencv\ml.h>
#include <math.h>


using namespace cv;
using namespace std;

  vector<vector<Point> > contours0; 
  vector<vector<Point> > contours;
  vector<Vec4i> hierarchy;


int main( int argc, char** argv )
{
  const char* filename = argc >= 2 ? argv[1] : "pic1.jpg";

 Mat src = imread(filename, 0);
 if(src.empty())
 {
     cout << "can not open " << filename << endl;
     return -1;
 }
 Mat out;
  Canny(src, out, 100,400, 3);


    out = out > 1;
    namedWindow( "Source", 1 );
    imshow( "Source", out );





    findContours( out, contours0, hierarchy,
        CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );


    contours.resize(contours0.size());
    for( size_t k = 0; k < contours0.size(); k++ ){
         approxPolyDP(Mat(contours0[k]), contours[k], 3, true);
    }


    int idx = 0;
    for( ; idx >= 0; idx = hierarchy[idx][0] )
    {
        drawContours( src, contours0, idx, Scalar(128,255,255), 5, 8, hierarchy );
    }

    namedWindow( "Components", 1 );
    imshow( "Components", src );
    waitKey(0);
}