findContours problems

asked 2018-05-16 04:25:05 -0500

Hi guys , my mother language is not English , so please forgive my poor English.

I met a problem when I use function "findContours"

and this is my image after threshold、medianBlur、Canny

image description

and I use findContours and drawContours

image description

but I fond it cant use arcLength and i try to figure out what happend , I check the detail of contours and I found this

image description

image description

but I still can use drawContour, does anybody can help me to solve it problem ?

here is my code :

    cv::Mat conT = cv::imread("LMask2.jpg");
cv::cvtColor(conT, conT, CV_BGR2GRAY);

std::vector <std::vector<cv::Point>> contours;
cv::vector<cv::Vec4i> hierarchy;

cv::threshold(conT, conT, 150, 255, cv::THRESH_BINARY | cv::THRESH_OTSU);
cv::medianBlur(conT, conT, 5);
cv::Canny(conT, conT, 50, 150, 3);

cv::Mat resultImage = cv::Mat::zeros(conT.size(), CV_8UC3);
cv::findContours(conT, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE, cv::Point(0, 0));
drawContours(resultImage, contours, -1, cv::Scalar(255, 0, 255));
edit retag flag offensive close merge delete


os, open version ?

make sure to use ONLY release libs with release build, and debug libs with debug build

berak gravatar imageberak ( 2018-05-16 04:36:17 -0500 )edit

My opencv version is 2.4.9. Yes , I only use these libs in debug and release build. thanks for your apply.

Ken15975346 gravatar imageKen15975346 ( 2018-05-16 19:42:44 -0500 )edit

Hi I solved the problem by upgrade the opencv version from 2.4.9 to 2.4.13 i thought maybe its the bug in older version.

Ken15975346 gravatar imageKen15975346 ( 2018-05-16 21:02:41 -0500 )edit