SlideShare uma empresa Scribd logo
1 de 29
Contours



Module 5
Mayank Prasad
President, roboVITics
   © Copyright Mayank Prasad
                                     1
   roboVITics, 2012
Content Information
• This set of slides has been made with respect to the
  popular book Learning OpenCV by Gary Bradski
  and Adrian Kaehler, O’Reilly Media, Inc.

• The slides are to be used along with the Code
  Gallery shared along with it

• Slides made by Mayank Prasad, B.Tech (IVth
  Year), ECE, VIT University



 © Copyright Mayank Prasad
                                                         2
 roboVITics, 2012
Outline
• Memory Storage
• Sequences
    o   Creating a Sequence
    o   Deleting a Sequence
    o   Direct Access
    o   Slicing, Copying and Moving Data
    o   Sequences as Stack (Not Discussed)
    o   Sequences and Arrays (Not Discussed)

• Contour Finding
    o Contours and Sequences
    o Freeman Chain Codes
    o Drawing Contours

• More to do with Contours (Not Discussed)

 © Copyright Mayank Prasad
                                               3
 roboVITics, 2012
Introduction
• Algorithms like the Canny edge detector used to
  find edge pixels that separate different segments in
  an image, but nothing about them as entities.
• Next step – assemble those edge pixels into
  contours
• cvFindContours() is used




 © Copyright Mayank Prasad
                                                         4
 roboVITics, 2012
Memory Storage
   Handle memory allocation for dynamic objects in OpenCV




© Copyright Mayank Prasad
                                                            5
roboVITics, 2012
Memory Storage
• Linked lists of memory blocks that allow for fast
  allocation and de-allocation of continuous sets of
  blocks
• Accessed by OpenCV function which require
  memory allocation as a part of their normal
  functionality




 © Copyright Mayank Prasad
                                                       6
 roboVITics, 2012
Routines




© Copyright Mayank Prasad
                                       7
roboVITics, 2012
Sequences
                Sequences stored inside memory storage




© Copyright Mayank Prasad
                                                         8
roboVITics, 2012
Sequences
•     Stored inside memory storage
•     Linked lists of other structures
•     Analogous to generic container classes
•     Sequence structure in OpenCV is actually a deque
       o Very fast for random access and add/delete from either end
       o Little slow for such things in the middle

• Direct access to sequence elements (More Later)
       o The most direct way – and the correct way to access any random
         element (apart from accessing from the ends)




    © Copyright Mayank Prasad
                                                                          9
    roboVITics, 2012
Sequence Structure




© Copyright Mayank Prasad
                                10
roboVITics, 2012
Creating/Deleting
                 Sequence




© Copyright Mayank Prasad
                                 11
roboVITics, 2012
Flags – Set 1
Flag                            Type of Object
CV_SEQ_ELTYPE_POINT             (x,y)
CV_SEQ_ELTYPE_CODE              Freeman Code: 0…7
CV_SEQ_ELTYPE_POINT             Pointer to a point: &(x,y)
CV_SEQ_ELTYPE_INDEX             Integer Index of a point: #(x,y)
CV_SEQ_ELTYPE_GRAPH_EDGE        &next_o, &next_d, &vtx_o, &vtx_d
CV_SEQ_ELTYPE_GRAPH_VERTEX      first_edge, &(x,y)
CV_SEQ_ELTYPE_TRIAN_ATR         Vertex of a binary tree
CV_SEQ_ELTYPE_CONNECTED_COMP    Connected Component
CV_SEQ_ELTYPE_POINT3D           (x,y,z)



 © Copyright Mayank Prasad
                                                                   12
 roboVITics, 2012
Flags – Set 2/3
Flags                        Nature of Object
CV_SEQ_KIND_SET              A set of objects
CV_SEQ_KIND_CURVE            A curve defined by the objects
CV_SEQ_KIND_BIN_TREE         A binary tree of the objects
CV_SEQ_KIND_GRAPH            A graph with objects as nodes
Flags                        Other Property of Object
CV_SEQ_FLAG_CLOSED           Sequence is closed (polygons)
CV_SEQ_FLAG_SIMPLE           Sequence is simple (polygons)
CV_SEQ_FLAG_CONVEX           Sequence is convex (polygons)
CV_SEQ_FLAG_HOLE             Sequence is a hole (polygons)




 © Copyright Mayank Prasad
                                                              13
 roboVITics, 2012
Direct Access to Sequence
        Elements
• The most direct way – and correct way to access
  random elements of a sequence (apart from
  accessing at the ends)


• Example usage to print elements as a sequence of
  points (typecast required)




 © Copyright Mayank Prasad
                                                     14
 roboVITics, 2012
Copying Sequences
• To deep copy sequences, use cvCloneSeq()




• More general routine is cvSeqSlice()




 © Copyright Mayank Prasad
                                             15
 roboVITics, 2012
Slicing Sequences
• Slice can be defined using cvSlice(a,b) or the
  macro CV_WHOLE_SEQ
• b can also be set to CV_WHOLE_SEQ_END_INDEX
• Slices used to specify elements to remove/insert into
  a sequence




 © Copyright Mayank Prasad
                                                          16
 roboVITics, 2012
More on Sequences
•     Sorting, Searching & Inverting
•     Sequences as Stack (Deque)
•     Inserting & Removing Elements
•     Sequence Block Size
•     Sequence Readers/Writers
•     Sequences and Arrays

These topics may not be necessary, but will be
discussed as and when necessary


    © Copyright Mayank Prasad
                                                 17
    roboVITics, 2012
Contour Finding
                                  Contour
              List of points representing curve of an Image




© Copyright Mayank Prasad
                                                              18
roboVITics, 2012
Intro to Contours
• List of points representing the curve of an image
• Represented as sequences in which every entry in
  the sequence encodes information about the
  location of the next point on the curve
• cvFindContours() finds contours from binary
  images – working shown in next slide




 © Copyright Mayank Prasad
                                                      19
 roboVITics, 2012
Contour Trees
                                 Working of
                              cvFindContours()


                            Dashed lines represent
                            the exterior boundaries
                                of white region
                                 (contours, c)


                             Dotted lines represent
                            the exterior boundaries
                                of black region
                                  (holes, h)

© Copyright Mayank Prasad
                                                 20
roboVITics, 2012
cvFindContours()
•     img is treated as binary and used as scratch space
•     storage – location for the sequence
•     firstContour – pointer to the head of contour tree
•     headerSize – tells more about allocated objects
•     mode – what to compute
•     method – how to compute
•     Returns total number of contours found




    © Copyright Mayank Prasad
                                                           21
    roboVITics, 2012
mode of
              cvFindContours()
• Indicates the types of contours we want to be
  found and how the result is presented to us
• Determines how tree node variables are hooked up
  together
mode                        Description
CV_RETR_EXTERNAL            Retrieves only extreme outer
                            contours
CV_RETR_LIST                Retrieves all the contours and puts
                            them in the list
CV_RETR_CCOMP               Retrieves all the contours and
                            organizes them into a two-level
                            hierarchy
CV_RETR_TREE                Retrieves all the contours and
                            reconstructs the full hierarchy of
© Copyright Mayank Prasad
                            nested contours                       22
roboVITics, 2012
method of
              cvFindContours()
• Determines how contours are approximated
method                      Description
CV_CHAIN_CODE               Outputs contours in the Freeman
                            chain code; all other methods output
                            polygons
CV_CHAIN_APPROX_NONE        Translates all the points from the
                            chain code into points
CV_CHAIN_APPROX_SIMPLE      Compresses horizontal, vertical, and
                            diagonal segments, leaving only
                            their ending points
CV_CHAIN_APPROX_TC89_L1     Applies one of the flavors of the Teh-
CV_CHAIN_APPROX_TC89_KCOS   Chin chain approximation algorithm
CV_LINK_RUNS                Completely different algorithm that
                            links horizontal segments of 1s
© Copyright Mayank Prasad
                                                                     23
roboVITics, 2012
Contours are Sequences
• Contours are special types of sequences
• Other functions to manipulate them
    o   cvFindContours()
    o   cvStartFindContours()
    o   cvFindNextContour()
    o   cvSubstituteContour()
    o   cvEndFindContour()
    o   cvApproxChains()
    o   cvApproxPoly()




 © Copyright Mayank Prasad
                                            24
 roboVITics, 2012
Freeman Chain Code




© Copyright Mayank Prasad
                            25
roboVITics, 2012
Drawing Contours




© Copyright Mayank Prasad
                               26
roboVITics, 2012
Acknowledgements
        Image Courtesy              References
• Learning OpenCV by         • Learning OpenCV by
  Gary Bradski and             Gary Bradski and
  Adrian Kaehler, O’Reilly     Adrian Kaehler, O’Reilly
  Media, Inc.                  Media, Inc.




 © Copyright Mayank Prasad
                                                          27
 roboVITics, 2012
Up Next
                               Module 6
                  Hardware Interfacing using Visual C++




© Copyright Mayank Prasad
                                                          28
roboVITics, 2012
Contacts
• Mayank Prasad
         President, roboVITics
         mayank@robovitics.in
• Akshat Wahi
         Asst. Project Manager, roboVITics
         +91 909 250 3053
         akshat@core.robovitics.in
• Akash Kashyap
         President, TEC – The Electronics Club of VIT
         akash130791@gmail.com


© Copyright Mayank Prasad
                                                        29
roboVITics, 2012

Mais conteúdo relacionado

Semelhante a RoboCV Module 5: Contours using OpenCV

Auto cad 2006_api_overview
Auto cad 2006_api_overviewAuto cad 2006_api_overview
Auto cad 2006_api_overview
scdhruv5
 

Semelhante a RoboCV Module 5: Contours using OpenCV (20)

Learning to Spot and Refactor Inconsistent Method Names
Learning to Spot and Refactor Inconsistent Method NamesLearning to Spot and Refactor Inconsistent Method Names
Learning to Spot and Refactor Inconsistent Method Names
 
Cnc scala-presentation
Cnc scala-presentationCnc scala-presentation
Cnc scala-presentation
 
Memory Analysis of the Dalvik (Android) Virtual Machine
Memory Analysis of the Dalvik (Android) Virtual MachineMemory Analysis of the Dalvik (Android) Virtual Machine
Memory Analysis of the Dalvik (Android) Virtual Machine
 
Android MvRx Framework 介紹
Android MvRx Framework 介紹Android MvRx Framework 介紹
Android MvRx Framework 介紹
 
«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear
«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear
«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear
 
NoSQL overview implementation free
NoSQL overview implementation freeNoSQL overview implementation free
NoSQL overview implementation free
 
Spatio-temporal reasoning for traffic scene understanding
Spatio-temporal reasoning for traffic scene understandingSpatio-temporal reasoning for traffic scene understanding
Spatio-temporal reasoning for traffic scene understanding
 
20 intro-to-csharp
20 intro-to-csharp20 intro-to-csharp
20 intro-to-csharp
 
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBCBI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
 
Multiple Choice Questions on JAVA (object oriented programming) bank 2 -- bas...
Multiple Choice Questions on JAVA (object oriented programming) bank 2 -- bas...Multiple Choice Questions on JAVA (object oriented programming) bank 2 -- bas...
Multiple Choice Questions on JAVA (object oriented programming) bank 2 -- bas...
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMetrics ekon 14_2_kleiner
Metrics ekon 14_2_kleiner
 
The Dark Side of Objective-C
The Dark Side of Objective-CThe Dark Side of Objective-C
The Dark Side of Objective-C
 
視訊訊號處理與深度學習應用
視訊訊號處理與深度學習應用視訊訊號處理與深度學習應用
視訊訊號處理與深度學習應用
 
Intro_OpenCV.ppt
Intro_OpenCV.pptIntro_OpenCV.ppt
Intro_OpenCV.ppt
 
Csharp
CsharpCsharp
Csharp
 
embedded C.pptx
embedded C.pptxembedded C.pptx
embedded C.pptx
 
Auto cad 2006_api_overview
Auto cad 2006_api_overviewAuto cad 2006_api_overview
Auto cad 2006_api_overview
 
A schema generation approach for column oriented no sql data stores
A schema generation approach for column oriented no sql data storesA schema generation approach for column oriented no sql data stores
A schema generation approach for column oriented no sql data stores
 
Jndi
JndiJndi
Jndi
 
seminar100326a.pdf
seminar100326a.pdfseminar100326a.pdf
seminar100326a.pdf
 

Mais de roboVITics club

Mais de roboVITics club (6)

RoboCV Module 4: Image Processing Techniques using OpenCV
RoboCV Module 4: Image Processing Techniques using OpenCVRoboCV Module 4: Image Processing Techniques using OpenCV
RoboCV Module 4: Image Processing Techniques using OpenCV
 
RoboCV Module 2: Introduction to OpenCV and MATLAB
RoboCV Module 2: Introduction to OpenCV and MATLABRoboCV Module 2: Introduction to OpenCV and MATLAB
RoboCV Module 2: Introduction to OpenCV and MATLAB
 
RoboCV Module 1: Introduction to Machine Vision
RoboCV Module 1: Introduction to Machine VisionRoboCV Module 1: Introduction to Machine Vision
RoboCV Module 1: Introduction to Machine Vision
 
RoboCV - Demo Session Slides
RoboCV - Demo Session SlidesRoboCV - Demo Session Slides
RoboCV - Demo Session Slides
 
ROBO-SUMO Event Details v1.2
ROBO-SUMO Event Details v1.2ROBO-SUMO Event Details v1.2
ROBO-SUMO Event Details v1.2
 
VIT-EDC Problem Statement v1.2
VIT-EDC Problem Statement v1.2VIT-EDC Problem Statement v1.2
VIT-EDC Problem Statement v1.2
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

RoboCV Module 5: Contours using OpenCV

  • 1. Contours Module 5 Mayank Prasad President, roboVITics © Copyright Mayank Prasad 1 roboVITics, 2012
  • 2. Content Information • This set of slides has been made with respect to the popular book Learning OpenCV by Gary Bradski and Adrian Kaehler, O’Reilly Media, Inc. • The slides are to be used along with the Code Gallery shared along with it • Slides made by Mayank Prasad, B.Tech (IVth Year), ECE, VIT University © Copyright Mayank Prasad 2 roboVITics, 2012
  • 3. Outline • Memory Storage • Sequences o Creating a Sequence o Deleting a Sequence o Direct Access o Slicing, Copying and Moving Data o Sequences as Stack (Not Discussed) o Sequences and Arrays (Not Discussed) • Contour Finding o Contours and Sequences o Freeman Chain Codes o Drawing Contours • More to do with Contours (Not Discussed) © Copyright Mayank Prasad 3 roboVITics, 2012
  • 4. Introduction • Algorithms like the Canny edge detector used to find edge pixels that separate different segments in an image, but nothing about them as entities. • Next step – assemble those edge pixels into contours • cvFindContours() is used © Copyright Mayank Prasad 4 roboVITics, 2012
  • 5. Memory Storage Handle memory allocation for dynamic objects in OpenCV © Copyright Mayank Prasad 5 roboVITics, 2012
  • 6. Memory Storage • Linked lists of memory blocks that allow for fast allocation and de-allocation of continuous sets of blocks • Accessed by OpenCV function which require memory allocation as a part of their normal functionality © Copyright Mayank Prasad 6 roboVITics, 2012
  • 7. Routines © Copyright Mayank Prasad 7 roboVITics, 2012
  • 8. Sequences Sequences stored inside memory storage © Copyright Mayank Prasad 8 roboVITics, 2012
  • 9. Sequences • Stored inside memory storage • Linked lists of other structures • Analogous to generic container classes • Sequence structure in OpenCV is actually a deque o Very fast for random access and add/delete from either end o Little slow for such things in the middle • Direct access to sequence elements (More Later) o The most direct way – and the correct way to access any random element (apart from accessing from the ends) © Copyright Mayank Prasad 9 roboVITics, 2012
  • 10. Sequence Structure © Copyright Mayank Prasad 10 roboVITics, 2012
  • 11. Creating/Deleting Sequence © Copyright Mayank Prasad 11 roboVITics, 2012
  • 12. Flags – Set 1 Flag Type of Object CV_SEQ_ELTYPE_POINT (x,y) CV_SEQ_ELTYPE_CODE Freeman Code: 0…7 CV_SEQ_ELTYPE_POINT Pointer to a point: &(x,y) CV_SEQ_ELTYPE_INDEX Integer Index of a point: #(x,y) CV_SEQ_ELTYPE_GRAPH_EDGE &next_o, &next_d, &vtx_o, &vtx_d CV_SEQ_ELTYPE_GRAPH_VERTEX first_edge, &(x,y) CV_SEQ_ELTYPE_TRIAN_ATR Vertex of a binary tree CV_SEQ_ELTYPE_CONNECTED_COMP Connected Component CV_SEQ_ELTYPE_POINT3D (x,y,z) © Copyright Mayank Prasad 12 roboVITics, 2012
  • 13. Flags – Set 2/3 Flags Nature of Object CV_SEQ_KIND_SET A set of objects CV_SEQ_KIND_CURVE A curve defined by the objects CV_SEQ_KIND_BIN_TREE A binary tree of the objects CV_SEQ_KIND_GRAPH A graph with objects as nodes Flags Other Property of Object CV_SEQ_FLAG_CLOSED Sequence is closed (polygons) CV_SEQ_FLAG_SIMPLE Sequence is simple (polygons) CV_SEQ_FLAG_CONVEX Sequence is convex (polygons) CV_SEQ_FLAG_HOLE Sequence is a hole (polygons) © Copyright Mayank Prasad 13 roboVITics, 2012
  • 14. Direct Access to Sequence Elements • The most direct way – and correct way to access random elements of a sequence (apart from accessing at the ends) • Example usage to print elements as a sequence of points (typecast required) © Copyright Mayank Prasad 14 roboVITics, 2012
  • 15. Copying Sequences • To deep copy sequences, use cvCloneSeq() • More general routine is cvSeqSlice() © Copyright Mayank Prasad 15 roboVITics, 2012
  • 16. Slicing Sequences • Slice can be defined using cvSlice(a,b) or the macro CV_WHOLE_SEQ • b can also be set to CV_WHOLE_SEQ_END_INDEX • Slices used to specify elements to remove/insert into a sequence © Copyright Mayank Prasad 16 roboVITics, 2012
  • 17. More on Sequences • Sorting, Searching & Inverting • Sequences as Stack (Deque) • Inserting & Removing Elements • Sequence Block Size • Sequence Readers/Writers • Sequences and Arrays These topics may not be necessary, but will be discussed as and when necessary © Copyright Mayank Prasad 17 roboVITics, 2012
  • 18. Contour Finding Contour List of points representing curve of an Image © Copyright Mayank Prasad 18 roboVITics, 2012
  • 19. Intro to Contours • List of points representing the curve of an image • Represented as sequences in which every entry in the sequence encodes information about the location of the next point on the curve • cvFindContours() finds contours from binary images – working shown in next slide © Copyright Mayank Prasad 19 roboVITics, 2012
  • 20. Contour Trees Working of cvFindContours() Dashed lines represent the exterior boundaries of white region (contours, c) Dotted lines represent the exterior boundaries of black region (holes, h) © Copyright Mayank Prasad 20 roboVITics, 2012
  • 21. cvFindContours() • img is treated as binary and used as scratch space • storage – location for the sequence • firstContour – pointer to the head of contour tree • headerSize – tells more about allocated objects • mode – what to compute • method – how to compute • Returns total number of contours found © Copyright Mayank Prasad 21 roboVITics, 2012
  • 22. mode of cvFindContours() • Indicates the types of contours we want to be found and how the result is presented to us • Determines how tree node variables are hooked up together mode Description CV_RETR_EXTERNAL Retrieves only extreme outer contours CV_RETR_LIST Retrieves all the contours and puts them in the list CV_RETR_CCOMP Retrieves all the contours and organizes them into a two-level hierarchy CV_RETR_TREE Retrieves all the contours and reconstructs the full hierarchy of © Copyright Mayank Prasad nested contours 22 roboVITics, 2012
  • 23. method of cvFindContours() • Determines how contours are approximated method Description CV_CHAIN_CODE Outputs contours in the Freeman chain code; all other methods output polygons CV_CHAIN_APPROX_NONE Translates all the points from the chain code into points CV_CHAIN_APPROX_SIMPLE Compresses horizontal, vertical, and diagonal segments, leaving only their ending points CV_CHAIN_APPROX_TC89_L1 Applies one of the flavors of the Teh- CV_CHAIN_APPROX_TC89_KCOS Chin chain approximation algorithm CV_LINK_RUNS Completely different algorithm that links horizontal segments of 1s © Copyright Mayank Prasad 23 roboVITics, 2012
  • 24. Contours are Sequences • Contours are special types of sequences • Other functions to manipulate them o cvFindContours() o cvStartFindContours() o cvFindNextContour() o cvSubstituteContour() o cvEndFindContour() o cvApproxChains() o cvApproxPoly() © Copyright Mayank Prasad 24 roboVITics, 2012
  • 25. Freeman Chain Code © Copyright Mayank Prasad 25 roboVITics, 2012
  • 26. Drawing Contours © Copyright Mayank Prasad 26 roboVITics, 2012
  • 27. Acknowledgements Image Courtesy References • Learning OpenCV by • Learning OpenCV by Gary Bradski and Gary Bradski and Adrian Kaehler, O’Reilly Adrian Kaehler, O’Reilly Media, Inc. Media, Inc. © Copyright Mayank Prasad 27 roboVITics, 2012
  • 28. Up Next Module 6 Hardware Interfacing using Visual C++ © Copyright Mayank Prasad 28 roboVITics, 2012
  • 29. Contacts • Mayank Prasad President, roboVITics mayank@robovitics.in • Akshat Wahi Asst. Project Manager, roboVITics +91 909 250 3053 akshat@core.robovitics.in • Akash Kashyap President, TEC – The Electronics Club of VIT akash130791@gmail.com © Copyright Mayank Prasad 29 roboVITics, 2012