Search code examples
c++opencvsequencescontour

Dealing with sequences in OpenCV?


I have 2 sequences. One (lets call this cvSeq x), which contains a number of contours (derived from cvFindContours) and a second (lets call this cvSeq y) which I have used cvCreateSeq upon, but doesn't actually have anything in it. I am looping through all the contours in x, and if a contour meets specific criteria, I add it to y. I am able to do the looping, but I don't know how to add an contour in x to y if it meets the criteria.

Does anyone know how to add a contour in a sequence to another sequence (that is empty)? Code examples will be appreciated.

PS: cvStartFindContours is not an option.


Solution

  • A solution would be to use the C++ interface, instead of the old one. It is much simpler to use. Contours are stored as vector<vector<Point>>

    You can use it in a similar way:

    Mat myImg = (Mat)myIplImage;
    //or better
    Mat myImg = imread("image.jpg");
    
    vector<vector<Point>> contours;
    
    cv::findContours(myImg, contours,...);
    

    Now access to contours and points is much simpler and easier

    Note I did not checked the code accuracy. You must verify the correct way to send params to findContours, and all the rest.