SlideShare a Scribd company logo
1 of 38
By
Mayank Prasad
President, roboVITics
VIT University, Vellore




                          DELVING DEEPER
                          INTO OPENCV
                          Data Types in OpenCV
Outline
2


       OpenCV Primitive Data types
         CvPoint,CvSize, CvRect, CvScalar
         Constructors of data types

       Matrix and Image Types
         CvArr,CvMat, IplImage
         CvMat Matrix Structure

         IplImage Data structure

       Matrix and Image Operators

                      © roboVITics | Mayank Prasad, 2012
3   OpenCV Data Types
    Primitive Data Types
    Matrix and Image Types
    Inheritance Relationship




              © roboVITics | Mayank Prasad, 2012
OpenCV Primitive Data types
4


       Several primitive data types in OpenCV
       Not present in the traditional ANSI C
       CvPoint – CvPoint2D32f, CvPoint3D32f
       CvSize, CvSize2D32f, CvRect, CvScalar




                  © roboVITics | Mayank Prasad, 2012
OpenCV Primitive Data types
5


       Primitive Data types are normal C structures
       Each data type has constructor method like
        cvSize(), cvPoint(), cvRect()
       Since this is C, not C++, these “constructors” are
        inline functions which take in list of arguments
        and returns the desired data structure with
        values set properly.
       CvScalar has three constructors:
        cvScalar(), cvRealScalar(), cvScalarA
        ll()
                      © roboVITics | Mayank Prasad, 2012
Matrix and Image Types
6




             © roboVITics | Mayank Prasad, 2012
Inheritance Relationship
7


       Though OpenCV is programmed entirely in
        C, its structures implemented can be thought to
        exhibit object oriented design
       IplImage is derived from CvMat, which is in
        turn derived from CvArr
       Wherever CvArr* appears in function
        prototypes, it is acceptable to pass CvMat or
        IplImage to the routine


                     © roboVITics | Mayank Prasad, 2012
8   CvMat Matrix Structure
    Matrix Header
    Creating, Initializing & Releasing Matrix
    Accessing Matrix Data




               © roboVITics | Mayank Prasad, 2012
CvMat Matrix Structure
9


       Can be created from the following definition:

       Type can be of the form:

       For example
         32bit floats CV_32FC1
         Unsigned integer 8 bit triplets CV_8UC3

        For multichannel images like RGB, operators
         act on each channel separately.
                      © roboVITics | Mayank Prasad, 2012
CvMat Structure: Matrix Header
10

                                          Matrices have
                                               Width
                                               Height
                                               Type
                                               Step (length of row in
                                                bytes)
                                               Pointer to data array
                                               And many more!!
                                          All members can be
                                           accessed by de-
                                           referencing pointers or
                                           by calling accessory
                                           functions

               © roboVITics | Mayank Prasad, 2012
Creating Matrices
11


        Can be created in three ways:
          Create using cvCreateMat()
          Create using cvCreateMatHeader() and
           cvCreateData()
          Create from an existing one by cloning it
           cvCloneMat(CvMat*)
        cvCreateMatHeader() creates CvMat
         structure without allocating any data
        cvCreateData() handles data allocation
        Release using cvReleaseMat(CvMat**)
                          © roboVITics | Mayank Prasad, 2012
Matrix Creation
12




              © roboVITics | Mayank Prasad, 2012
Header Initialization
13




               © roboVITics | Mayank Prasad, 2012
Header Initialization
14




               © roboVITics | Mayank Prasad, 2012
Clone & Release Matrix
15




              © roboVITics | Mayank Prasad, 2012
Create OpenCV Matrix
16


        Create an OpenCV Matrix with some fixed data
         float vals[] = {0.8660225, -0.5000000, 0.5000000, 0.4326678};
         CvMat rotmat;
         cvInitMatHeader( &rotmat, 2, 2, CV_32FC1, vals );

        Simple Matrix Operations
          cvGetElemType()  : Returns the type like CV_64FC4
          cvGetDims() : Returns width & height

          cvGetDimSize() : Returns the size




                          © roboVITics | Mayank Prasad, 2012
Accessing Matrix Data
17


        The easy way!
        The hard way!!
        The right way!!!




                       © roboVITics | Mayank Prasad, 2012
The Easy Way
18


        Use the CV_MAT_ELEM() macro
        Takes in the matrix, type of element to be
         retrieved, row and column numbers
        Returns the desired element



        Under the hood, it calls CV_MAT_ELEM_PTR()
        Type casting is required

                      © roboVITics | Mayank Prasad, 2012
Why not the easy way?
19


        Re-computes pointer needed on every call
          Look up the pointer to the base element
          Calculate the offset of the desired point

          Add the offset to the base element pointer

        Easy to use, but not the best way, especially
         when every element is to be accessed
         sequentially



                       © roboVITics | Mayank Prasad, 2012
The Hard Way
20


        Easy way deals with 1D and 2D matrices
        Hard way can deal with N-dimensional matrices
        Has a lot of set/get/pointer functions
        It is a rarely used way, since many a times, vision is a
         processor-intensive activity, which requires greater
         efficiency
        So, do your own pointer arithmetic and de-
         reference your way into the matrix
        Important in cases when an OpenCV routine is not
         available for performing a particular task

                        © roboVITics | Mayank Prasad, 2012
The Right Way
21


        Direct access to innards of matrix
          Data storedsequentially in raster scan order
          Columns (“x”) are fastest running variable

          Channels are interleaved




                         © roboVITics | Mayank Prasad, 2012
The Right Way
22


        Element data is Union
        Step element can be used for offset
        Since step element is in bytes, all pointer
         arithmetic is done in bytes, and later typecast
         into float
        Pointer is recomputed for every row rather than
         starting from the beginning



                      © roboVITics | Mayank Prasad, 2012
Arrays of Points
23


        Not discussed




                     © roboVITics | Mayank Prasad, 2012
24   IplImage Data Structure
     Header Structure
     Accessing Image Data
     ROI and widthStep




               © roboVITics | Mayank Prasad, 2012
IplImage Data Structure
25


        Similar to CvMat, but with some extra goodies
        Makes the matrix more interpretable as an
         image
        This structure was originally defined as a part of
         Intel’s Image Processing Library (IPL)
        It is defined as:




                       © roboVITics | Mayank Prasad, 2012
IplImage Header Structure
26




              © roboVITics | Mayank Prasad, 2012
Depth & Channels
27


        width & height is ubiquitous
        depth & nChannels are next most crucial




        nChannels can be 1, 2, 3 or 4

                      © roboVITics | Mayank Prasad, 2012
Origin & Data Order
28


        origin can take two values
          Upper-left of the image, IPL_ORIGIN_TL
          Lower-left of the image, IPL_ORIGIN_BL

        dataOrder can be of two types
          IPL_DATA_ORDER_PIXEL      – data packed with
           multiple channels one after the other for each pixel
           i.e. interleaving
          IPL_DATA_ORDER_PLANE – all the channels
           clustered into image planes with planes facing each
           other – not supported in OpenCV

                           © roboVITics | Mayank Prasad, 2012
Interleaved Images
29




                                              Interleaving  True




                                              Interleaving  False




              © roboVITics | Mayank Prasad, 2012
Step, Data & ROI
30


        widthStep contains number of bytes between
         elements of same column and successive rows
        imageData contains pointer to the first row of
         the image data
        IplROI defines the practical Region of Interest
          Contains
           xOffset, yOffset, height, width, coi
          COI means Channel of Interest, though not
           respected by all OpenCV functions

                      © roboVITics | Mayank Prasad, 2012
Accessing Image Data
31


        All tasks may not have prepackaged well-
         optimized subroutine in OpenCV
        So we need to access each pixel of the image
         sequentially
        So, we need to handle the pointers ourselves
        widthStep can be used in bytes “as is” without
         worrying because the data pointer is always of
         byte type


                      © roboVITics | Mayank Prasad, 2012
Accessing Image Data – Example
32




              © roboVITics | Mayank Prasad, 2012
ROI & widthStep
33


        ROI stands for Region Of Interest
        widthStep is the size in bytes between a pixel
         and the pixel vertically below it
        In other words, widthStep refers to the size of a
         row in bytes




                       © roboVITics | Mayank Prasad, 2012
34   Matrix & Image Operators
     Different Types of Matrix Operators




                © roboVITics | Mayank Prasad, 2012
Matrix & Image Operators
35


        A variety of routines are available for matrix
         manipulation, most of which work equally well
         for images
        They do most of the usual as well as complicated
         things
        E.g.
         cvAdd(), cvAddS(), cvCvtColor(), cvSe
         t(), cvTranspose(), etc.


                      © roboVITics | Mayank Prasad, 2012
Acknowledments
36



     References                            Image Courtesy

        Gary Bradski and                     Gary Bradski and
         Adrian                                Adrian
         Kaehler, Learning                     Kaehler, Learning
         OpenCV, O’Reilly                      OpenCV, O’Reilly
         Media, Inc.                           Media, Inc.




                      © roboVITics | Mayank Prasad, 2012
UP NEXT
Image Processing Techniques using OpenCV
Contacts
38


        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

                          © roboVITics | Mayank Prasad, 2012

More Related Content

Viewers also liked

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 MATLABroboVITics club
 
RoboCV Module 5: Contours using OpenCV
RoboCV Module 5: Contours using OpenCVRoboCV Module 5: Contours using OpenCV
RoboCV Module 5: Contours using OpenCVroboVITics club
 
OpenCV祭り (配布用)
OpenCV祭り (配布用)OpenCV祭り (配布用)
OpenCV祭り (配布用)tomoaki0705
 
RoboCV - Demo Session Slides
RoboCV - Demo Session SlidesRoboCV - Demo Session Slides
RoboCV - Demo Session SlidesroboVITics club
 
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 VisionroboVITics club
 
Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Luigi De Russis
 
Image Processing with OpenCV
Image Processing with OpenCVImage Processing with OpenCV
Image Processing with OpenCVdebayanin
 
How to make a Line Follower Robot
How to make a Line Follower RobotHow to make a Line Follower Robot
How to make a Line Follower RobotroboVITics club
 

Viewers also liked (9)

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 5: Contours using OpenCV
RoboCV Module 5: Contours using OpenCVRoboCV Module 5: Contours using OpenCV
RoboCV Module 5: Contours using OpenCV
 
OpenCV祭り (配布用)
OpenCV祭り (配布用)OpenCV祭り (配布用)
OpenCV祭り (配布用)
 
RoboCV - Demo Session Slides
RoboCV - Demo Session SlidesRoboCV - Demo Session Slides
RoboCV - Demo Session Slides
 
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
 
OpenCV Workshop
OpenCV WorkshopOpenCV Workshop
OpenCV Workshop
 
Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)
 
Image Processing with OpenCV
Image Processing with OpenCVImage Processing with OpenCV
Image Processing with OpenCV
 
How to make a Line Follower Robot
How to make a Line Follower RobotHow to make a Line Follower Robot
How to make a Line Follower Robot
 

Similar to RoboCV Module 3: Delving Deeper into OpenCV

MVVM Presentation.pptx
MVVM Presentation.pptxMVVM Presentation.pptx
MVVM Presentation.pptxAsfandyarZaidi
 
MV(C, mvvm) in iOS and ReactiveCocoa
MV(C, mvvm) in iOS and ReactiveCocoaMV(C, mvvm) in iOS and ReactiveCocoa
MV(C, mvvm) in iOS and ReactiveCocoaYi-Shou Chen
 
Starting from Scratch with the MEAN Stack
Starting from Scratch with the MEAN StackStarting from Scratch with the MEAN Stack
Starting from Scratch with the MEAN StackMongoDB
 
Reactive Stream Processing in Industrial IoT using DDS and Rx
Reactive Stream Processing in Industrial IoT using DDS and RxReactive Stream Processing in Industrial IoT using DDS and Rx
Reactive Stream Processing in Industrial IoT using DDS and RxSumant Tambe
 
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOSSoftware architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOSJinkyu Kim
 
Dataflows: The abstraction that powers Big Data by Raul Castro Fernandez at ...
 Dataflows: The abstraction that powers Big Data by Raul Castro Fernandez at ... Dataflows: The abstraction that powers Big Data by Raul Castro Fernandez at ...
Dataflows: The abstraction that powers Big Data by Raul Castro Fernandez at ...Big Data Spain
 
Towards a metamodel for the Rubus Component Model
Towards a metamodel for the Rubus Component ModelTowards a metamodel for the Rubus Component Model
Towards a metamodel for the Rubus Component ModelAlessio Bucaioni
 
IRJET- Identification of Scene Images using Convolutional Neural Networks - A...
IRJET- Identification of Scene Images using Convolutional Neural Networks - A...IRJET- Identification of Scene Images using Convolutional Neural Networks - A...
IRJET- Identification of Scene Images using Convolutional Neural Networks - A...IRJET Journal
 
IRJET- Review on Java Database Connectivity
IRJET- Review on Java Database ConnectivityIRJET- Review on Java Database Connectivity
IRJET- Review on Java Database ConnectivityIRJET Journal
 
Traffic Sign Recognition Model
Traffic Sign Recognition ModelTraffic Sign Recognition Model
Traffic Sign Recognition ModelIRJET Journal
 
Ms Sql Business Inteligence With My Sql
Ms Sql Business Inteligence With My SqlMs Sql Business Inteligence With My Sql
Ms Sql Business Inteligence With My Sqlrsnarayanan
 
IRJET - Gender and Age Prediction using Wideresnet Architecture
IRJET - Gender and Age Prediction using Wideresnet ArchitectureIRJET - Gender and Age Prediction using Wideresnet Architecture
IRJET - Gender and Age Prediction using Wideresnet ArchitectureIRJET Journal
 
Real time Traffic Signs Recognition using Deep Learning
Real time Traffic Signs Recognition using Deep LearningReal time Traffic Signs Recognition using Deep Learning
Real time Traffic Signs Recognition using Deep LearningIRJET Journal
 
Principles of Data Visualization
Principles of Data VisualizationPrinciples of Data Visualization
Principles of Data VisualizationEamonn Maguire
 
The New Perception Framework in Autonomous Driving: An Introduction of BEV N...
The New Perception Framework  in Autonomous Driving: An Introduction of BEV N...The New Perception Framework  in Autonomous Driving: An Introduction of BEV N...
The New Perception Framework in Autonomous Driving: An Introduction of BEV N...Yu Huang
 
GENERATION OF HTML CODE AUTOMATICALLY USING MOCK-UP IMAGES WITH MACHINE LEARN...
GENERATION OF HTML CODE AUTOMATICALLY USING MOCK-UP IMAGES WITH MACHINE LEARN...GENERATION OF HTML CODE AUTOMATICALLY USING MOCK-UP IMAGES WITH MACHINE LEARN...
GENERATION OF HTML CODE AUTOMATICALLY USING MOCK-UP IMAGES WITH MACHINE LEARN...IRJET Journal
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: AndroidJitendra Kumar
 
Dance With AI – An interactive dance learning platform
Dance With AI – An interactive dance learning platformDance With AI – An interactive dance learning platform
Dance With AI – An interactive dance learning platformIRJET Journal
 

Similar to RoboCV Module 3: Delving Deeper into OpenCV (20)

MVVM Presentation.pptx
MVVM Presentation.pptxMVVM Presentation.pptx
MVVM Presentation.pptx
 
mvcExpress training course : part1
mvcExpress training course : part1mvcExpress training course : part1
mvcExpress training course : part1
 
MV(C, mvvm) in iOS and ReactiveCocoa
MV(C, mvvm) in iOS and ReactiveCocoaMV(C, mvvm) in iOS and ReactiveCocoa
MV(C, mvvm) in iOS and ReactiveCocoa
 
Starting from Scratch with the MEAN Stack
Starting from Scratch with the MEAN StackStarting from Scratch with the MEAN Stack
Starting from Scratch with the MEAN Stack
 
Reactive Stream Processing in Industrial IoT using DDS and Rx
Reactive Stream Processing in Industrial IoT using DDS and RxReactive Stream Processing in Industrial IoT using DDS and Rx
Reactive Stream Processing in Industrial IoT using DDS and Rx
 
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOSSoftware architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
 
Dataflows: The abstraction that powers Big Data by Raul Castro Fernandez at ...
 Dataflows: The abstraction that powers Big Data by Raul Castro Fernandez at ... Dataflows: The abstraction that powers Big Data by Raul Castro Fernandez at ...
Dataflows: The abstraction that powers Big Data by Raul Castro Fernandez at ...
 
ASP .Net MVC 5
ASP .Net MVC 5ASP .Net MVC 5
ASP .Net MVC 5
 
Towards a metamodel for the Rubus Component Model
Towards a metamodel for the Rubus Component ModelTowards a metamodel for the Rubus Component Model
Towards a metamodel for the Rubus Component Model
 
IRJET- Identification of Scene Images using Convolutional Neural Networks - A...
IRJET- Identification of Scene Images using Convolutional Neural Networks - A...IRJET- Identification of Scene Images using Convolutional Neural Networks - A...
IRJET- Identification of Scene Images using Convolutional Neural Networks - A...
 
IRJET- Review on Java Database Connectivity
IRJET- Review on Java Database ConnectivityIRJET- Review on Java Database Connectivity
IRJET- Review on Java Database Connectivity
 
Traffic Sign Recognition Model
Traffic Sign Recognition ModelTraffic Sign Recognition Model
Traffic Sign Recognition Model
 
Ms Sql Business Inteligence With My Sql
Ms Sql Business Inteligence With My SqlMs Sql Business Inteligence With My Sql
Ms Sql Business Inteligence With My Sql
 
IRJET - Gender and Age Prediction using Wideresnet Architecture
IRJET - Gender and Age Prediction using Wideresnet ArchitectureIRJET - Gender and Age Prediction using Wideresnet Architecture
IRJET - Gender and Age Prediction using Wideresnet Architecture
 
Real time Traffic Signs Recognition using Deep Learning
Real time Traffic Signs Recognition using Deep LearningReal time Traffic Signs Recognition using Deep Learning
Real time Traffic Signs Recognition using Deep Learning
 
Principles of Data Visualization
Principles of Data VisualizationPrinciples of Data Visualization
Principles of Data Visualization
 
The New Perception Framework in Autonomous Driving: An Introduction of BEV N...
The New Perception Framework  in Autonomous Driving: An Introduction of BEV N...The New Perception Framework  in Autonomous Driving: An Introduction of BEV N...
The New Perception Framework in Autonomous Driving: An Introduction of BEV N...
 
GENERATION OF HTML CODE AUTOMATICALLY USING MOCK-UP IMAGES WITH MACHINE LEARN...
GENERATION OF HTML CODE AUTOMATICALLY USING MOCK-UP IMAGES WITH MACHINE LEARN...GENERATION OF HTML CODE AUTOMATICALLY USING MOCK-UP IMAGES WITH MACHINE LEARN...
GENERATION OF HTML CODE AUTOMATICALLY USING MOCK-UP IMAGES WITH MACHINE LEARN...
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: Android
 
Dance With AI – An interactive dance learning platform
Dance With AI – An interactive dance learning platformDance With AI – An interactive dance learning platform
Dance With AI – An interactive dance learning platform
 

Recently uploaded

Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

RoboCV Module 3: Delving Deeper into OpenCV

  • 1. By Mayank Prasad President, roboVITics VIT University, Vellore DELVING DEEPER INTO OPENCV Data Types in OpenCV
  • 2. Outline 2  OpenCV Primitive Data types  CvPoint,CvSize, CvRect, CvScalar  Constructors of data types  Matrix and Image Types  CvArr,CvMat, IplImage  CvMat Matrix Structure  IplImage Data structure  Matrix and Image Operators © roboVITics | Mayank Prasad, 2012
  • 3. 3 OpenCV Data Types Primitive Data Types Matrix and Image Types Inheritance Relationship © roboVITics | Mayank Prasad, 2012
  • 4. OpenCV Primitive Data types 4  Several primitive data types in OpenCV  Not present in the traditional ANSI C  CvPoint – CvPoint2D32f, CvPoint3D32f  CvSize, CvSize2D32f, CvRect, CvScalar © roboVITics | Mayank Prasad, 2012
  • 5. OpenCV Primitive Data types 5  Primitive Data types are normal C structures  Each data type has constructor method like cvSize(), cvPoint(), cvRect()  Since this is C, not C++, these “constructors” are inline functions which take in list of arguments and returns the desired data structure with values set properly.  CvScalar has three constructors: cvScalar(), cvRealScalar(), cvScalarA ll() © roboVITics | Mayank Prasad, 2012
  • 6. Matrix and Image Types 6 © roboVITics | Mayank Prasad, 2012
  • 7. Inheritance Relationship 7  Though OpenCV is programmed entirely in C, its structures implemented can be thought to exhibit object oriented design  IplImage is derived from CvMat, which is in turn derived from CvArr  Wherever CvArr* appears in function prototypes, it is acceptable to pass CvMat or IplImage to the routine © roboVITics | Mayank Prasad, 2012
  • 8. 8 CvMat Matrix Structure Matrix Header Creating, Initializing & Releasing Matrix Accessing Matrix Data © roboVITics | Mayank Prasad, 2012
  • 9. CvMat Matrix Structure 9  Can be created from the following definition:  Type can be of the form:  For example  32bit floats CV_32FC1  Unsigned integer 8 bit triplets CV_8UC3  For multichannel images like RGB, operators act on each channel separately. © roboVITics | Mayank Prasad, 2012
  • 10. CvMat Structure: Matrix Header 10  Matrices have  Width  Height  Type  Step (length of row in bytes)  Pointer to data array  And many more!!  All members can be accessed by de- referencing pointers or by calling accessory functions © roboVITics | Mayank Prasad, 2012
  • 11. Creating Matrices 11  Can be created in three ways:  Create using cvCreateMat()  Create using cvCreateMatHeader() and cvCreateData()  Create from an existing one by cloning it cvCloneMat(CvMat*)  cvCreateMatHeader() creates CvMat structure without allocating any data  cvCreateData() handles data allocation  Release using cvReleaseMat(CvMat**) © roboVITics | Mayank Prasad, 2012
  • 12. Matrix Creation 12 © roboVITics | Mayank Prasad, 2012
  • 13. Header Initialization 13 © roboVITics | Mayank Prasad, 2012
  • 14. Header Initialization 14 © roboVITics | Mayank Prasad, 2012
  • 15. Clone & Release Matrix 15 © roboVITics | Mayank Prasad, 2012
  • 16. Create OpenCV Matrix 16  Create an OpenCV Matrix with some fixed data float vals[] = {0.8660225, -0.5000000, 0.5000000, 0.4326678}; CvMat rotmat; cvInitMatHeader( &rotmat, 2, 2, CV_32FC1, vals );  Simple Matrix Operations  cvGetElemType() : Returns the type like CV_64FC4  cvGetDims() : Returns width & height  cvGetDimSize() : Returns the size © roboVITics | Mayank Prasad, 2012
  • 17. Accessing Matrix Data 17  The easy way!  The hard way!!  The right way!!! © roboVITics | Mayank Prasad, 2012
  • 18. The Easy Way 18  Use the CV_MAT_ELEM() macro  Takes in the matrix, type of element to be retrieved, row and column numbers  Returns the desired element  Under the hood, it calls CV_MAT_ELEM_PTR()  Type casting is required © roboVITics | Mayank Prasad, 2012
  • 19. Why not the easy way? 19  Re-computes pointer needed on every call  Look up the pointer to the base element  Calculate the offset of the desired point  Add the offset to the base element pointer  Easy to use, but not the best way, especially when every element is to be accessed sequentially © roboVITics | Mayank Prasad, 2012
  • 20. The Hard Way 20  Easy way deals with 1D and 2D matrices  Hard way can deal with N-dimensional matrices  Has a lot of set/get/pointer functions  It is a rarely used way, since many a times, vision is a processor-intensive activity, which requires greater efficiency  So, do your own pointer arithmetic and de- reference your way into the matrix  Important in cases when an OpenCV routine is not available for performing a particular task © roboVITics | Mayank Prasad, 2012
  • 21. The Right Way 21  Direct access to innards of matrix  Data storedsequentially in raster scan order  Columns (“x”) are fastest running variable  Channels are interleaved © roboVITics | Mayank Prasad, 2012
  • 22. The Right Way 22  Element data is Union  Step element can be used for offset  Since step element is in bytes, all pointer arithmetic is done in bytes, and later typecast into float  Pointer is recomputed for every row rather than starting from the beginning © roboVITics | Mayank Prasad, 2012
  • 23. Arrays of Points 23  Not discussed © roboVITics | Mayank Prasad, 2012
  • 24. 24 IplImage Data Structure Header Structure Accessing Image Data ROI and widthStep © roboVITics | Mayank Prasad, 2012
  • 25. IplImage Data Structure 25  Similar to CvMat, but with some extra goodies  Makes the matrix more interpretable as an image  This structure was originally defined as a part of Intel’s Image Processing Library (IPL)  It is defined as: © roboVITics | Mayank Prasad, 2012
  • 26. IplImage Header Structure 26 © roboVITics | Mayank Prasad, 2012
  • 27. Depth & Channels 27  width & height is ubiquitous  depth & nChannels are next most crucial  nChannels can be 1, 2, 3 or 4 © roboVITics | Mayank Prasad, 2012
  • 28. Origin & Data Order 28  origin can take two values  Upper-left of the image, IPL_ORIGIN_TL  Lower-left of the image, IPL_ORIGIN_BL  dataOrder can be of two types  IPL_DATA_ORDER_PIXEL – data packed with multiple channels one after the other for each pixel i.e. interleaving  IPL_DATA_ORDER_PLANE – all the channels clustered into image planes with planes facing each other – not supported in OpenCV © roboVITics | Mayank Prasad, 2012
  • 29. Interleaved Images 29 Interleaving  True Interleaving  False © roboVITics | Mayank Prasad, 2012
  • 30. Step, Data & ROI 30  widthStep contains number of bytes between elements of same column and successive rows  imageData contains pointer to the first row of the image data  IplROI defines the practical Region of Interest  Contains xOffset, yOffset, height, width, coi  COI means Channel of Interest, though not respected by all OpenCV functions © roboVITics | Mayank Prasad, 2012
  • 31. Accessing Image Data 31  All tasks may not have prepackaged well- optimized subroutine in OpenCV  So we need to access each pixel of the image sequentially  So, we need to handle the pointers ourselves  widthStep can be used in bytes “as is” without worrying because the data pointer is always of byte type © roboVITics | Mayank Prasad, 2012
  • 32. Accessing Image Data – Example 32 © roboVITics | Mayank Prasad, 2012
  • 33. ROI & widthStep 33  ROI stands for Region Of Interest  widthStep is the size in bytes between a pixel and the pixel vertically below it  In other words, widthStep refers to the size of a row in bytes © roboVITics | Mayank Prasad, 2012
  • 34. 34 Matrix & Image Operators Different Types of Matrix Operators © roboVITics | Mayank Prasad, 2012
  • 35. Matrix & Image Operators 35  A variety of routines are available for matrix manipulation, most of which work equally well for images  They do most of the usual as well as complicated things  E.g. cvAdd(), cvAddS(), cvCvtColor(), cvSe t(), cvTranspose(), etc. © roboVITics | Mayank Prasad, 2012
  • 36. Acknowledments 36 References Image Courtesy  Gary Bradski and  Gary Bradski and Adrian Adrian Kaehler, Learning Kaehler, Learning OpenCV, O’Reilly OpenCV, O’Reilly Media, Inc. Media, Inc. © roboVITics | Mayank Prasad, 2012
  • 37. UP NEXT Image Processing Techniques using OpenCV
  • 38. Contacts 38  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 © roboVITics | Mayank Prasad, 2012