简体   繁体   中英

how do i access contour sequentially in opencv

I am segmenting a handwritten word using contours in opencv (cpp). But after segmenting is gives random output contour.It is not gives as left to right ordering of word.Help me to obtain order.

Assuming that you have something like the following to extract the contours:

// Contros found from input array
cv::Mat _src = src.getMat();
std::vector<std::vector<cv::Point>> contours;
std::vector<cv::Vec4i> hierarchy;
cv::findContours(_src, contours, hierarchy, CV_RETR_EXTERNAL,
        params.contourDetMethod);

You can iterate through your contours (here contors ) and create bounding boxes using cv::boundingRect . Now you can use coordination of the resulting Rect with others and find out their spatial order.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM