{"id":373,"date":"2022-08-30T15:00:16","date_gmt":"2022-08-30T15:00:16","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/06\/cvfindcontours-not-working-in-opencv-2-3-1-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:00:16","modified_gmt":"2022-08-30T15:00:16","slug":"cvfindcontours-not-working-in-opencv-2-3-1-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/cvfindcontours-not-working-in-opencv-2-3-1-collection-of-common-programming-errors\/","title":{"rendered":"cvFindContours() not working in OpenCV 2.3.1-Collection of common programming errors"},"content":{"rendered":"<p>I have been having some problems running my application on OpenCV 2.3.1. It works like a charm on OpenCV 2.1 but gives a run time error in OpenCV 2.3.1. OpenCV Error: Assertion failed in unknown function,<\/p>\n<pre><code>#include \n#include\n#include \n#include \n#define MAXX_CONTOUR_AREA  200\n\nCvMemStorage* storage=0;\nCvSeq* lines;\nCvSeq* lines1;\nCvSeq* contours;\nCvSeq* _contours;\n\nvoid segment()\n{\n\n    IplImage *img = cvLoadImage(\"save.jpg\",0);\n    int height =img-&gt;height;\n    IplImage *cnt_img = cvCreateImage( cvGetSize(img), 8, 3 );\n    CvPoint* line;\n    storage = cvCreateMemStorage(0); \n    \/\/********************Find contours****************************************\/\/       \nint i=cvFindContours( img, storage, &amp;contours, sizeof(CvContour),\n       CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );\nlines1=contours;\n_contours = contours;\nvoid* element;\nCvRect rect;\nCvPoint p,p1,p2;\nwhile(_contours-&gt;h_next!=NULL)  \n{\n_contours = _contours-&gt;h_next;\ncvDrawContours( cnt_img, _contours, CV_RGB(0,255,0), CV_RGB(0,0,0), 7, 3, CV_AA, cvPoint(0,0));\nrect=cvContourBoundingRect (_contours,0); \n\/\/*****************Get the co-ordinates of the bounding rectangle***************\/\/\np.x=(int)rect.x;\np.y=(int)rect.y;\np1.x=(int) rect.x+ (int) rect.width;\np1.y=(int) rect.y+ (int) rect.height;\np2.x=(p.x+p1.x)\/2;\nif((rect.height*rect.width)&gt;=MAXX_CONTOUR_AREA)\n{cvRectangle(cnt_img,p,p1,CV_RGB(255,255,255),1);\nprintf(\"\\nCo-ordinates: (%d,%d)\",(p.x+p1.x)\/2,(p1.y+p.y)\/2);\n}\n}\nlines1=cvApproxChains(contours, storage, CV_CHAIN_APPROX_SIMPLE, 0, 0, 0);\ncvSaveImage(\"saved.jpg\",cnt_img);\n}            \n\n\nmain()\n{\nIplImage *src=cvLoadImage(\"u.JPG\",0); \/\/-1--&gt;color,0--&gt;b&amp;w\nIplImage *dst = cvCreateImage( cvGetSize(src), 8, 1 );\ncvCanny( src, dst, 150,200 , 3 );\ncvSaveImage(\"save.jpg\",dst);\n\/\/cvShowImage(\"Display\",dst);\nsegment();\nsystem(\"PAUSE\");\n}    \n<\/code><\/pre>\n<p>I am using DEV C++ with OpenCV 2.3.1 Earlier i was using OpenCV 2.1 with DEV C++.<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-06 03:31:08. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have been having some problems running my application on OpenCV 2.3.1. It works like a charm on OpenCV 2.1 but gives a run time error in OpenCV 2.3.1. OpenCV Error: Assertion failed in unknown function, #include #include #include #include #define MAXX_CONTOUR_AREA 200 CvMemStorage* storage=0; CvSeq* lines; CvSeq* lines1; CvSeq* contours; CvSeq* _contours; void segment() [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-373","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=373"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/373\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}