"Exercise 8.5" Contour length computer Cvapproxpoly approximation

Source: Internet
Author: User

In-page index
Topic Requirements Program code Result picture Homilies Miao DAO Learn from Reference

Title Requirements:

A. Detecting contours and calculating contour Lengths

b, using 1/90,1/66,1/11,1/10 as the accuracy parameter, using Cvapproxpoly approximation, calculate the contour length and draw the result

Program code:

1 //OpenCVExerciseTesting.cpp: Defines the entry point of the console application. 2 //3 //string file_full_name = "d:\\work\\work_programming\\source\\image\\opencvexerciseimage\\ 8th chapter \\r20.jpg";4 5 6#include"stdafx.h"7#include <string>8#include <cv.h>9#include Ten#include <iostream> One#include <math.h> A  -#include <opencv2/legacy/legacy.hpp> - //#pragma comment (lib, "Opencv_legacy2411.lib") the  - using namespaceCV; - using namespacestd; -  + //function declaration---->-->--->-->--->-->--->// -  +  A //<--<--<--<--<--<--<--<--<--Function Declaration// at  - int_tmain (intARGC, _tchar*argv[]) - { -     stringFile_full_name ="d:\\work\\work_programming\\source\\image\\opencvexerciseimage\\ 8th Chapter \\r20.jpg"; -  -Iplimage * Image_source =Cvloadimage (File_full_name.c_str (), cv_load_image_grayscale); in Cv_assert (image_source); -  toIplimage * Image_binary =cvcloneimage (image_source); + Cvzero (image_binary); -  theCvthreshold (Image_source, Image_binary, the,255, cv_thresh_binary); *  $Cvmemstorage *storage =cvcreatememstorage ();Panax Notoginsengcvseq* first_contour=NULL; -     intContour_num; theContour_num = Cvfindcontours (image_binary, storage, &first_contour,sizeof(Cvcontour), cv_retr_list); +  Acout <<"Number of outlines"<< Contour_num <<Endl; the      +     Doublecontour_length; -     //For (CVSEQ * c = first_contour; c = NULL; c = c->h_next) $     //{ $     //contour_length = Cvcontourperimeter (c); -     //cout << "perimeter" << contour_length << Endl; -     //} theContour_length =Cvcontourperimeter (first_contour); -cout <<"Perimeter"<< Contour_length <<Endl;Wuyi  the     DoublePerimeter =126.7; -     Doubleparameters[4] = {126.7/ -,126.7/ the,126.7/ One,126.7/Ten }; Wucvmemstorage* Storage_approx =cvcreatememstorage (); -  AboutIplimage *image_approx =cvcloneimage (image_binary); $ Cvzero (Image_approx); -Cvseq *seq_approx=NULL; -      -     stringWindow_name ="approx window";; A      for(inti =0; I <4; ++i) +     {         theSeq_approx = Cvapproxpoly (First_contour,sizeof(Cvcontour), Storage_approx, CV_POLY_APPROX_DP, Parameters[i],0); -Contour_length =Cvcontourperimeter (Seq_approx); $cout << contour_length <<Endl; theWindow_name = Window_name +"."; theCvdrawcontours (Image_approx, Seq_approx, Cvscalar (255), Cvscalar ( the),0); the Cvshowimage (Window_name.c_str (), image_approx); the     } -      inCvwaitkey (0); the  theCvreleaseimage (&image_source); AboutCvreleaseimage (&image_binary); theCvreleaseimage (&Image_approx); the cvdestroyallwindows (); the  +     return 0; -}

Result Picture:

Homilies Miao DAO:

For reference:

"Exercise 8.5" Contour length computer Cvapproxpoly approximation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.