SlideShare a Scribd company logo
1 of 27
OpenCV-5
Adding shapes to images
HarrCascades
Adding shapes
• It is possible to add shapes in the images using OpenCV.
• The function is based on the shape we want to add in the image.
• It can be a line or circle or rectangle or square.
• All depends on the coordinates of the shapes to be present.
• In some cases, the coordinates can be automated meaning that the machine
decides the coordinates for the shape.
Adding a line
• To add a line we have to use the cv2.line() function.
• The first argument is the location of the read image.
• It is nothing but the variable which contains the read image.
• The second argument is the starting point of the line.
• The third argument is the ending point of the line.
• The fourth argument is the color in BGR format.
• The fifth argument is the thickness which is specified as a number.
Color codes
DESIRED COLOR VALUE
Blue (255,0,0)
Green (0,255,0)
Red (0,0,255)
Yellow (0,255,255)
Magenta (255,0,255)
Cyan (255,255,0)
White (255,255,255)
Black (0,0,0)
cv2.line()
Effect of thickness
Adding a rectangle
• A rectangle is a two dimensional object containing two sides.
• The cv2.square() function is used to add a square to the given image.
• The first argument is the location of the image.
• The second and the third argument refers to the coordinates of the square.
• The fourth argument is the color which is the same as before.
• The last argument is the thickness which is the same as before.
cv2.rectangle()
Effect of thickness
Adding a square
• There is no specific function to add a square in an image.
• There is no cv2.square() function in OpenCV.
• We have to bring a square using the cv2.rectangle() function.
• A square is nothing but a rectangle with equal sides.
• The coordinates have to be adjusted in the required fashion.
square
Adding a circle
• It is possible to add a circle to the given image.
• The function is cv2.circle()
• There are two parameters required for a circle, the center and the radius.
• So there are only two changes in the function when compared to previous.
• The second argument is the center point and the third argument is the radius
of the circle.
cv2.circle()
Effect of thickness
Haar cascades
• In all the cases before, the coordinates of the shapes were given by us.
• But we can make the machine determine the coordinates for the shapes.
• This is something like face detection.
• There are more than face detection available in haar cascades.
• These algorithms return the coordinates for the binding box based on the
command we give.
• The algorithms are present in a xml file (extensive markup language).
Xml files
• The type of xml files determine the type of detection to be done in the
image.
• There are xml files for the following:-
• Eye
• Eye with glass
• Frontal face of cat
Contd..
• Frontal face of cat extended version
• Front face of human
• Full body
• Left eye
• License plate
Contd…
• Lower body
• Smile
• Upper body
• Profile face
• Right eye
Procedure
• Convert the image to gray scale.
• Call the haar cascade xml file using the CascadeClassifier.
• Detect the following in the grayscale image using the detectMultiScale
• This will return the x,y coordinates and the height and width values.
• Using a for loop plot a rectangle from the parameters mentioned above.
Alternative
• The conventional procedure is to download the xml file and then show the
location in the IDE.
• However this doesn’t work in most of the cases.
• Also the source for the xml files is not clear.
• Instead we can use the cv2.data.haarcascades along with the xml file name to
get the desired xml file.
Face detection
Face blocker
• -1 in brightness fills the shape with
the specified color.
Eye detector
Eye blocker
Smile detector
Smile blocker
OpenCV presentation series- part 5

More Related Content

What's hot

Practical Digital Image Processing 3
 Practical Digital Image Processing 3 Practical Digital Image Processing 3
Practical Digital Image Processing 3Aly Abdelkareem
 
Practical Digital Image Processing 2
Practical Digital Image Processing 2Practical Digital Image Processing 2
Practical Digital Image Processing 2Aly Abdelkareem
 
Edge Detection using Hough Transform
Edge Detection using Hough TransformEdge Detection using Hough Transform
Edge Detection using Hough TransformMrunal Selokar
 
Morphology in graphics and image processing
Morphology in graphics and image processingMorphology in graphics and image processing
Morphology in graphics and image processingDheeban Smart
 
Chapter 9 morphological image processing
Chapter 9 morphological image processingChapter 9 morphological image processing
Chapter 9 morphological image processingasodariyabhavesh
 
Practical Digital Image Processing 5
Practical Digital Image Processing 5Practical Digital Image Processing 5
Practical Digital Image Processing 5Aly Abdelkareem
 
Image enhancement techniques a review
Image enhancement techniques   a reviewImage enhancement techniques   a review
Image enhancement techniques a revieweSAT Journals
 
Presen_Segmentation
Presen_SegmentationPresen_Segmentation
Presen_SegmentationVikas Goyal
 
A rank based ensemble classifier for image classification
A rank based ensemble classifier for image classificationA rank based ensemble classifier for image classification
A rank based ensemble classifier for image classificationWin Yu
 
COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filterin...
COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filterin...COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filterin...
COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filterin...Hemantha Kulathilake
 
study Image Vectorization using Optimized Gradeint Meshes
study Image Vectorization using Optimized Gradeint Meshesstudy Image Vectorization using Optimized Gradeint Meshes
study Image Vectorization using Optimized Gradeint MeshesChiamin Hsu
 
Hybrid Technique for Copy-Move Forgery Detection Using L*A*B* Color Space
Hybrid Technique for Copy-Move Forgery Detection Using L*A*B* Color Space Hybrid Technique for Copy-Move Forgery Detection Using L*A*B* Color Space
Hybrid Technique for Copy-Move Forgery Detection Using L*A*B* Color Space IJEEE
 
Chapter 3 image enhancement (spatial domain)
Chapter 3 image enhancement (spatial domain)Chapter 3 image enhancement (spatial domain)
Chapter 3 image enhancement (spatial domain)asodariyabhavesh
 
Introductory Digital Image Processing using Matlab, IIT Roorkee
Introductory Digital Image Processing using Matlab, IIT RoorkeeIntroductory Digital Image Processing using Matlab, IIT Roorkee
Introductory Digital Image Processing using Matlab, IIT RoorkeeVinayak Sahai
 
Structure and Motion - 3D Reconstruction of Cameras and Structure
Structure and Motion - 3D Reconstruction of Cameras and StructureStructure and Motion - 3D Reconstruction of Cameras and Structure
Structure and Motion - 3D Reconstruction of Cameras and StructureGiovanni Murru
 

What's hot (20)

Image formation
Image formationImage formation
Image formation
 
Practical Digital Image Processing 3
 Practical Digital Image Processing 3 Practical Digital Image Processing 3
Practical Digital Image Processing 3
 
Image segmentation
Image segmentationImage segmentation
Image segmentation
 
Practical Digital Image Processing 2
Practical Digital Image Processing 2Practical Digital Image Processing 2
Practical Digital Image Processing 2
 
Edge Detection using Hough Transform
Edge Detection using Hough TransformEdge Detection using Hough Transform
Edge Detection using Hough Transform
 
Morphology in graphics and image processing
Morphology in graphics and image processingMorphology in graphics and image processing
Morphology in graphics and image processing
 
Chapter 9 morphological image processing
Chapter 9 morphological image processingChapter 9 morphological image processing
Chapter 9 morphological image processing
 
Practical Digital Image Processing 5
Practical Digital Image Processing 5Practical Digital Image Processing 5
Practical Digital Image Processing 5
 
Image enhancement techniques a review
Image enhancement techniques   a reviewImage enhancement techniques   a review
Image enhancement techniques a review
 
Orb feature by nitin
Orb feature by nitinOrb feature by nitin
Orb feature by nitin
 
Presen_Segmentation
Presen_SegmentationPresen_Segmentation
Presen_Segmentation
 
Morphological operations
Morphological operationsMorphological operations
Morphological operations
 
A rank based ensemble classifier for image classification
A rank based ensemble classifier for image classificationA rank based ensemble classifier for image classification
A rank based ensemble classifier for image classification
 
COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filterin...
COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filterin...COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filterin...
COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filterin...
 
Visual realism
Visual realismVisual realism
Visual realism
 
study Image Vectorization using Optimized Gradeint Meshes
study Image Vectorization using Optimized Gradeint Meshesstudy Image Vectorization using Optimized Gradeint Meshes
study Image Vectorization using Optimized Gradeint Meshes
 
Hybrid Technique for Copy-Move Forgery Detection Using L*A*B* Color Space
Hybrid Technique for Copy-Move Forgery Detection Using L*A*B* Color Space Hybrid Technique for Copy-Move Forgery Detection Using L*A*B* Color Space
Hybrid Technique for Copy-Move Forgery Detection Using L*A*B* Color Space
 
Chapter 3 image enhancement (spatial domain)
Chapter 3 image enhancement (spatial domain)Chapter 3 image enhancement (spatial domain)
Chapter 3 image enhancement (spatial domain)
 
Introductory Digital Image Processing using Matlab, IIT Roorkee
Introductory Digital Image Processing using Matlab, IIT RoorkeeIntroductory Digital Image Processing using Matlab, IIT Roorkee
Introductory Digital Image Processing using Matlab, IIT Roorkee
 
Structure and Motion - 3D Reconstruction of Cameras and Structure
Structure and Motion - 3D Reconstruction of Cameras and StructureStructure and Motion - 3D Reconstruction of Cameras and Structure
Structure and Motion - 3D Reconstruction of Cameras and Structure
 

Similar to OpenCV presentation series- part 5

Similar to OpenCV presentation series- part 5 (20)

CAD/CAM/CAE - Notes
CAD/CAM/CAE - NotesCAD/CAM/CAE - Notes
CAD/CAM/CAE - Notes
 
Parking space detect
Parking space detectParking space detect
Parking space detect
 
05 contours seg_matching
05 contours seg_matching05 contours seg_matching
05 contours seg_matching
 
Aspdot
AspdotAspdot
Aspdot
 
september18.ppt
september18.pptseptember18.ppt
september18.ppt
 
Synthetic Curves.pdf
Synthetic Curves.pdfSynthetic Curves.pdf
Synthetic Curves.pdf
 
MTA managing the graphical interface by using css
MTA managing the graphical interface by using cssMTA managing the graphical interface by using css
MTA managing the graphical interface by using css
 
Paper Presentation (Graph)
Paper Presentation (Graph)Paper Presentation (Graph)
Paper Presentation (Graph)
 
Mvs adas
Mvs adasMvs adas
Mvs adas
 
cnn ppt.pptx
cnn ppt.pptxcnn ppt.pptx
cnn ppt.pptx
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
MATLAB & Image Processing
MATLAB & Image ProcessingMATLAB & Image Processing
MATLAB & Image Processing
 
DAA Notes.pdf
DAA Notes.pdfDAA Notes.pdf
DAA Notes.pdf
 
Graphical Objects and Scene Graphs
Graphical Objects and Scene GraphsGraphical Objects and Scene Graphs
Graphical Objects and Scene Graphs
 
Parameter-free Modelling of 2D Shapes with Ellipses
Parameter-free Modelling of 2D Shapes with EllipsesParameter-free Modelling of 2D Shapes with Ellipses
Parameter-free Modelling of 2D Shapes with Ellipses
 
Group 6 Presentation - Copy.pptx
Group 6 Presentation - Copy.pptxGroup 6 Presentation - Copy.pptx
Group 6 Presentation - Copy.pptx
 
Group 5 Presentation.pptx
Group 5 Presentation.pptxGroup 5 Presentation.pptx
Group 5 Presentation.pptx
 
Group 5 Presentation.pptx
Group 5 Presentation.pptxGroup 5 Presentation.pptx
Group 5 Presentation.pptx
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
JDK and AWT
JDK and AWTJDK and AWT
JDK and AWT
 

More from Sairam Adithya

COUNTERS(Synchronous & Asynchronous)
COUNTERS(Synchronous & Asynchronous)COUNTERS(Synchronous & Asynchronous)
COUNTERS(Synchronous & Asynchronous)Sairam Adithya
 
SEQUENTIAL LOGIC CIRCUITS (FLIP FLOPS AND LATCHES)
SEQUENTIAL LOGIC CIRCUITS (FLIP FLOPS AND LATCHES)SEQUENTIAL LOGIC CIRCUITS (FLIP FLOPS AND LATCHES)
SEQUENTIAL LOGIC CIRCUITS (FLIP FLOPS AND LATCHES)Sairam Adithya
 
Medical waste segregation using deep learning
Medical waste segregation using deep learningMedical waste segregation using deep learning
Medical waste segregation using deep learningSairam Adithya
 
OpenCV presentation series- part 2
OpenCV presentation series- part 2OpenCV presentation series- part 2
OpenCV presentation series- part 2Sairam Adithya
 
OpenCV presentation series- part 1
OpenCV presentation series- part 1OpenCV presentation series- part 1
OpenCV presentation series- part 1Sairam Adithya
 
A Brief Introduction to Diabetes Mellitus
A Brief Introduction to Diabetes MellitusA Brief Introduction to Diabetes Mellitus
A Brief Introduction to Diabetes MellitusSairam Adithya
 
Detection of medical instruments project- PART 2
Detection of medical instruments project- PART 2Detection of medical instruments project- PART 2
Detection of medical instruments project- PART 2Sairam Adithya
 
Detection of medical instruments project- PART 1
Detection of medical instruments project- PART 1Detection of medical instruments project- PART 1
Detection of medical instruments project- PART 1Sairam Adithya
 
TASK-OPTIMIZED DEEP NEURAL NETWORK TO REPLICATE THE HUMAN AUDITORY CORTEX
TASK-OPTIMIZED DEEP NEURAL NETWORK TO REPLICATE THE HUMAN AUDITORY CORTEXTASK-OPTIMIZED DEEP NEURAL NETWORK TO REPLICATE THE HUMAN AUDITORY CORTEX
TASK-OPTIMIZED DEEP NEURAL NETWORK TO REPLICATE THE HUMAN AUDITORY CORTEXSairam Adithya
 

More from Sairam Adithya (9)

COUNTERS(Synchronous & Asynchronous)
COUNTERS(Synchronous & Asynchronous)COUNTERS(Synchronous & Asynchronous)
COUNTERS(Synchronous & Asynchronous)
 
SEQUENTIAL LOGIC CIRCUITS (FLIP FLOPS AND LATCHES)
SEQUENTIAL LOGIC CIRCUITS (FLIP FLOPS AND LATCHES)SEQUENTIAL LOGIC CIRCUITS (FLIP FLOPS AND LATCHES)
SEQUENTIAL LOGIC CIRCUITS (FLIP FLOPS AND LATCHES)
 
Medical waste segregation using deep learning
Medical waste segregation using deep learningMedical waste segregation using deep learning
Medical waste segregation using deep learning
 
OpenCV presentation series- part 2
OpenCV presentation series- part 2OpenCV presentation series- part 2
OpenCV presentation series- part 2
 
OpenCV presentation series- part 1
OpenCV presentation series- part 1OpenCV presentation series- part 1
OpenCV presentation series- part 1
 
A Brief Introduction to Diabetes Mellitus
A Brief Introduction to Diabetes MellitusA Brief Introduction to Diabetes Mellitus
A Brief Introduction to Diabetes Mellitus
 
Detection of medical instruments project- PART 2
Detection of medical instruments project- PART 2Detection of medical instruments project- PART 2
Detection of medical instruments project- PART 2
 
Detection of medical instruments project- PART 1
Detection of medical instruments project- PART 1Detection of medical instruments project- PART 1
Detection of medical instruments project- PART 1
 
TASK-OPTIMIZED DEEP NEURAL NETWORK TO REPLICATE THE HUMAN AUDITORY CORTEX
TASK-OPTIMIZED DEEP NEURAL NETWORK TO REPLICATE THE HUMAN AUDITORY CORTEXTASK-OPTIMIZED DEEP NEURAL NETWORK TO REPLICATE THE HUMAN AUDITORY CORTEX
TASK-OPTIMIZED DEEP NEURAL NETWORK TO REPLICATE THE HUMAN AUDITORY CORTEX
 

Recently uploaded

Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 

Recently uploaded (20)

TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 

OpenCV presentation series- part 5

  • 1. OpenCV-5 Adding shapes to images HarrCascades
  • 2. Adding shapes • It is possible to add shapes in the images using OpenCV. • The function is based on the shape we want to add in the image. • It can be a line or circle or rectangle or square. • All depends on the coordinates of the shapes to be present. • In some cases, the coordinates can be automated meaning that the machine decides the coordinates for the shape.
  • 3. Adding a line • To add a line we have to use the cv2.line() function. • The first argument is the location of the read image. • It is nothing but the variable which contains the read image. • The second argument is the starting point of the line. • The third argument is the ending point of the line. • The fourth argument is the color in BGR format. • The fifth argument is the thickness which is specified as a number.
  • 4. Color codes DESIRED COLOR VALUE Blue (255,0,0) Green (0,255,0) Red (0,0,255) Yellow (0,255,255) Magenta (255,0,255) Cyan (255,255,0) White (255,255,255) Black (0,0,0)
  • 7. Adding a rectangle • A rectangle is a two dimensional object containing two sides. • The cv2.square() function is used to add a square to the given image. • The first argument is the location of the image. • The second and the third argument refers to the coordinates of the square. • The fourth argument is the color which is the same as before. • The last argument is the thickness which is the same as before.
  • 10. Adding a square • There is no specific function to add a square in an image. • There is no cv2.square() function in OpenCV. • We have to bring a square using the cv2.rectangle() function. • A square is nothing but a rectangle with equal sides. • The coordinates have to be adjusted in the required fashion.
  • 12. Adding a circle • It is possible to add a circle to the given image. • The function is cv2.circle() • There are two parameters required for a circle, the center and the radius. • So there are only two changes in the function when compared to previous. • The second argument is the center point and the third argument is the radius of the circle.
  • 15. Haar cascades • In all the cases before, the coordinates of the shapes were given by us. • But we can make the machine determine the coordinates for the shapes. • This is something like face detection. • There are more than face detection available in haar cascades. • These algorithms return the coordinates for the binding box based on the command we give. • The algorithms are present in a xml file (extensive markup language).
  • 16. Xml files • The type of xml files determine the type of detection to be done in the image. • There are xml files for the following:- • Eye • Eye with glass • Frontal face of cat
  • 17. Contd.. • Frontal face of cat extended version • Front face of human • Full body • Left eye • License plate
  • 18. Contd… • Lower body • Smile • Upper body • Profile face • Right eye
  • 19. Procedure • Convert the image to gray scale. • Call the haar cascade xml file using the CascadeClassifier. • Detect the following in the grayscale image using the detectMultiScale • This will return the x,y coordinates and the height and width values. • Using a for loop plot a rectangle from the parameters mentioned above.
  • 20. Alternative • The conventional procedure is to download the xml file and then show the location in the IDE. • However this doesn’t work in most of the cases. • Also the source for the xml files is not clear. • Instead we can use the cv2.data.haarcascades along with the xml file name to get the desired xml file.
  • 22. Face blocker • -1 in brightness fills the shape with the specified color.