I'm trying to write a code, in which I can detect different geometric shape except squares, I found : this answer here the answer is given in python, I've tried to write in c++ but my program crashes, any idea what's I'm doing wrong:
int main (){
cv::Mat img = cv::imread("src.jpg",0);
cv::Mat image ;
std::vector<std::vector<cv::Point>> contours;
//std::vector<std::vector<cv::Point2f>> hiararchy;
cv::threshold(img,img,127,255,CV_THRESH_BINARY_INV);
cv::findContours(img,contours,/*hiararchy,*/CV_RETR_EXTERNAL,CV_RETR_CCOMP );
std::vector<cv::Point2f> approx;
for ( int i=0; i<contours.size();i++){
cv::approxPolyDP(cv::Mat(contours[i]),approx,cv::arcLength(cv::Mat(contours[i]),true)*0.02,true);
}
cv::waitKey(0);
return 0;
}
I've debugged the program, and it crashes in the cv::approxPolyDP function!
**update ** after the suggestion of C. Canberk Bacı I'Ve changed the for l
for ( int i=0; i<contours.size();i++){
cv::Mat m(contours[i]);
cv::approxPolyDP(m,approx,cv::arcLength(m,true)*0.02,true);
}
but it didn't change a lot thanks in advance for your help!