SlideShare a Scribd company logo
1 of 17
OpenCV In Python
Kaizen Group presentation
Jun 2023
Why AI?
Conditions ….
For example:
X<100
-10<Y <20
Table of contents
• Introduction
• Drawing shapes and lines
• Simple & Logical operations on images
• Threshold & Watermark
• Morphologic transformations
• Edge & Corner Detection
Table of contents
• Object recognition with Template & Feature Matching
• Histogram of images
• Color spaces (RGB, BGR, HSV)
• Video and Color detection
• Video – Face detection
• Video – Hand gesture Detection
Drawing shapes and lines
import cv2
import numpy as np
#creating a black square
image=np.zeros((512,512,3),np.uint8)
#we can also create this in black and white,however there would not be any changes
image_bw=np.zeros((512,512),np.uint8)
cv2.imshow("black rectangle(color)",image)
cv2.imshow("black rectangle(B&W)",image_bw)
• #create a line over black square
• #cv2.line(image, starting coordinates, ending coordinates, color, thickness)
• #drawing a diagonal line of thickness 6 pixels
• image=np.zeros((512,512,3),np.uint8)
• cv2.line(image,(0,0),(511,511),(255,127,0),6)
• cv2.imshow("blue line",image)
Drawing shapes and lines
• #create a rectangle over a black square
• #cv2.rectangle(image,starting coordinates, ending coordinates,
color, thickness)
• #drawing a rectangle of thickness 5 pixels
• image=np.zeros((512,512,3),np.uint8)
• cv2.rectangle(image,(30,50),(100,150),(255,127,0),5)
• cv2.imshow("rectangle",image)
Drawing shapes and lines
• #creating a circle over a black square
• #cv2.circle(image,center,radius,color,fill)
• image=np.zeros((512,512,3),np.uint8)
• cv2.circle(image,(100,100),(50),(255,127,0),-1)
• cv2.imshow("circle",image)
Drawing shapes and lines
• #creating a polygon
• image=np.zeros((512,512,3),np.uint8)
• #lets define four points
• pts=np.array([[10,50], [400,60], [30,89], [90,68]], np.int32)
• #lets now reshape our points in form required by polylines
• pts=pts.reshape((-1,1,2))
• cv2.polylines(image, [pts], True, (0,255,255), 3)
• cv2.imshow("polygon",image)
Drawing shapes and lines
• #putting text using opencv
• #cv2.putText(image,'text to display',bootom left starting point, font,font
size, color, thickness)
• image=np.zeros((512,512,3),np.uint8)
• cv2.putText(image,"hello world", (75,290),
cv2.FONT_HERSHEY_COMPLEX,2,(100,170,0),3)
• cv2.imshow("hello world",image)
• cv2.waitKey(0)
• cv2.destroyAllWindows()
Drawing shapes and lines
hello world
Simple & Logical operations on images
• img = cv.imread ("/content/drive/MyDrive/totfarangi.jpg", cv.IMREAD_COLOR)
• # Show the image
• cv2_imshow(img)
• cv.waitKey(0)
• cv.destroyAllWindows()
• img.shape (524, 650, 3)
• red_Strawberry = img [240:500 , 50:320 ]
• cv2_imshow(red_Strawberry)
• cv.waitKey(0)
• cv.destroyAllWindows()
Logical operations on images
• ret, maskimg = cv.threshold(img2gray, 40 ,255, cv.THRESH_BINARY)
• mask_inv = cv.bitwise_not(maskimg)
•
cv2_imshow(mask_inv)
• cv2.waitKey(0)
• cv2.destroyAllWindows()
• img1_m = cv.bitwise_and(img1, img2, mask=maskimg)
•
cv2_imshow(img1_m)
• cv2.waitKey(0)
• cv2.destroyAllWindows()
Logical operations on images
Color spaces
BGR, RGB , HSV
• #BGR
• image_bgr = cv.imread('/content/drive/MyDrive/totfarangi.jpg')
• image_gr = cv.cvtColor(image_bgr, cv.COLOR_BGR2GRAY)
• cv2_imshow(image_bgr)
• cv2_imshow(image_gr)
• cv2.waitKey(0)
• cv2.destroyAllWindows()
• # RGB
• #blue_ch, green_ch, red_ch = cv.split(image)
• image_rgb = cv.cvtColor(image_bgr, cv.COLOR_BGR2RGB)
• # BGR opencv
• # BGRA / RGBA 4 channel alpha opacity
• cv2_imshow(image_rgb)
• cv2.waitKey(0)
• cv2.destroyAllWindows()
Color spaces
• # HSV [20, 100, 100]
• image_hsv = cv.cvtColor(image_bgr, cv.COLOR_BGR2HSV)
• cv2_imshow(image_hsv)
• cv2.waitKey(0)
• cv2.destroyAllWindows()
• plt.imshow(image_hsv)
• plt.show()
Color spaces
Open CV library In Python_Vahid ebrahimian.pptx

More Related Content

Similar to Open CV library In Python_Vahid ebrahimian.pptx

Build Your Own 3D Scanner: 3D Scanning with Structured Lighting
Build Your Own 3D Scanner: 3D Scanning with Structured LightingBuild Your Own 3D Scanner: 3D Scanning with Structured Lighting
Build Your Own 3D Scanner: 3D Scanning with Structured LightingDouglas Lanman
 
CE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdfCE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdfUmarMustafa13
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvasGary Yeh
 
SVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generationSVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generationAnthony Starks
 
Python: Migrating from Procedural to Object-Oriented Programming
Python: Migrating from Procedural to Object-Oriented ProgrammingPython: Migrating from Procedural to Object-Oriented Programming
Python: Migrating from Procedural to Object-Oriented ProgrammingDamian T. Gordon
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
Build Your Own 3D Scanner: 3D Scanning with Swept-Planes
Build Your Own 3D Scanner: 3D Scanning with Swept-PlanesBuild Your Own 3D Scanner: 3D Scanning with Swept-Planes
Build Your Own 3D Scanner: 3D Scanning with Swept-PlanesDouglas Lanman
 
Efficient realization for geometric transformation of digital images in run l...
Efficient realization for geometric transformation of digital images in run l...Efficient realization for geometric transformation of digital images in run l...
Efficient realization for geometric transformation of digital images in run l...Shlomo Pongratz
 
Can someone please explain what the code below is doing and comment on.pdf
Can someone please explain what the code below is doing and comment on.pdfCan someone please explain what the code below is doing and comment on.pdf
Can someone please explain what the code below is doing and comment on.pdfkuldeepkumarapgsi
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer GraphicsAdri Jovin
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7decoupled
 
Introduction to Image Processing with MATLAB
Introduction to Image Processing with MATLABIntroduction to Image Processing with MATLAB
Introduction to Image Processing with MATLABSriram Emarose
 
You are task to add a yawning detection to the programme below;i.pdf
You are task to add a yawning detection to the programme below;i.pdfYou are task to add a yawning detection to the programme below;i.pdf
You are task to add a yawning detection to the programme below;i.pdfsales223546
 
[Ultracode Munich #4] Demo on Animatron by Anton Kotenko
[Ultracode Munich #4] Demo on Animatron by Anton Kotenko[Ultracode Munich #4] Demo on Animatron by Anton Kotenko
[Ultracode Munich #4] Demo on Animatron by Anton KotenkoBeMyApp
 
Lecture01 intro ece
Lecture01 intro eceLecture01 intro ece
Lecture01 intro eceKesava Shiva
 
Overview of graphics systems
Overview of  graphics systemsOverview of  graphics systems
Overview of graphics systemsJay Nagar
 

Similar to Open CV library In Python_Vahid ebrahimian.pptx (20)

Build Your Own 3D Scanner: 3D Scanning with Structured Lighting
Build Your Own 3D Scanner: 3D Scanning with Structured LightingBuild Your Own 3D Scanner: 3D Scanning with Structured Lighting
Build Your Own 3D Scanner: 3D Scanning with Structured Lighting
 
CE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdfCE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdf
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvas
 
Mmclass3
Mmclass3Mmclass3
Mmclass3
 
SVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generationSVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generation
 
Python: Migrating from Procedural to Object-Oriented Programming
Python: Migrating from Procedural to Object-Oriented ProgrammingPython: Migrating from Procedural to Object-Oriented Programming
Python: Migrating from Procedural to Object-Oriented Programming
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Build Your Own 3D Scanner: 3D Scanning with Swept-Planes
Build Your Own 3D Scanner: 3D Scanning with Swept-PlanesBuild Your Own 3D Scanner: 3D Scanning with Swept-Planes
Build Your Own 3D Scanner: 3D Scanning with Swept-Planes
 
Efficient realization for geometric transformation of digital images in run l...
Efficient realization for geometric transformation of digital images in run l...Efficient realization for geometric transformation of digital images in run l...
Efficient realization for geometric transformation of digital images in run l...
 
Can someone please explain what the code below is doing and comment on.pdf
Can someone please explain what the code below is doing and comment on.pdfCan someone please explain what the code below is doing and comment on.pdf
Can someone please explain what the code below is doing and comment on.pdf
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Introduction to Image Processing with MATLAB
Introduction to Image Processing with MATLABIntroduction to Image Processing with MATLAB
Introduction to Image Processing with MATLAB
 
You are task to add a yawning detection to the programme below;i.pdf
You are task to add a yawning detection to the programme below;i.pdfYou are task to add a yawning detection to the programme below;i.pdf
You are task to add a yawning detection to the programme below;i.pdf
 
[Ultracode Munich #4] Demo on Animatron by Anton Kotenko
[Ultracode Munich #4] Demo on Animatron by Anton Kotenko[Ultracode Munich #4] Demo on Animatron by Anton Kotenko
[Ultracode Munich #4] Demo on Animatron by Anton Kotenko
 
ip111.ppt
ip111.pptip111.ppt
ip111.ppt
 
Lecture01 intro ece
Lecture01 intro eceLecture01 intro ece
Lecture01 intro ece
 
Overview of graphics systems
Overview of  graphics systemsOverview of  graphics systems
Overview of graphics systems
 
Dip syntax 4
Dip syntax 4Dip syntax 4
Dip syntax 4
 

Recently uploaded

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 

Recently uploaded (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 

Open CV library In Python_Vahid ebrahimian.pptx

  • 1. OpenCV In Python Kaizen Group presentation Jun 2023
  • 2. Why AI? Conditions …. For example: X<100 -10<Y <20
  • 3. Table of contents • Introduction • Drawing shapes and lines • Simple & Logical operations on images • Threshold & Watermark • Morphologic transformations • Edge & Corner Detection
  • 4. Table of contents • Object recognition with Template & Feature Matching • Histogram of images • Color spaces (RGB, BGR, HSV) • Video and Color detection • Video – Face detection • Video – Hand gesture Detection
  • 5. Drawing shapes and lines import cv2 import numpy as np #creating a black square image=np.zeros((512,512,3),np.uint8) #we can also create this in black and white,however there would not be any changes image_bw=np.zeros((512,512),np.uint8) cv2.imshow("black rectangle(color)",image) cv2.imshow("black rectangle(B&W)",image_bw)
  • 6. • #create a line over black square • #cv2.line(image, starting coordinates, ending coordinates, color, thickness) • #drawing a diagonal line of thickness 6 pixels • image=np.zeros((512,512,3),np.uint8) • cv2.line(image,(0,0),(511,511),(255,127,0),6) • cv2.imshow("blue line",image) Drawing shapes and lines
  • 7. • #create a rectangle over a black square • #cv2.rectangle(image,starting coordinates, ending coordinates, color, thickness) • #drawing a rectangle of thickness 5 pixels • image=np.zeros((512,512,3),np.uint8) • cv2.rectangle(image,(30,50),(100,150),(255,127,0),5) • cv2.imshow("rectangle",image) Drawing shapes and lines
  • 8. • #creating a circle over a black square • #cv2.circle(image,center,radius,color,fill) • image=np.zeros((512,512,3),np.uint8) • cv2.circle(image,(100,100),(50),(255,127,0),-1) • cv2.imshow("circle",image) Drawing shapes and lines
  • 9. • #creating a polygon • image=np.zeros((512,512,3),np.uint8) • #lets define four points • pts=np.array([[10,50], [400,60], [30,89], [90,68]], np.int32) • #lets now reshape our points in form required by polylines • pts=pts.reshape((-1,1,2)) • cv2.polylines(image, [pts], True, (0,255,255), 3) • cv2.imshow("polygon",image) Drawing shapes and lines
  • 10. • #putting text using opencv • #cv2.putText(image,'text to display',bootom left starting point, font,font size, color, thickness) • image=np.zeros((512,512,3),np.uint8) • cv2.putText(image,"hello world", (75,290), cv2.FONT_HERSHEY_COMPLEX,2,(100,170,0),3) • cv2.imshow("hello world",image) • cv2.waitKey(0) • cv2.destroyAllWindows() Drawing shapes and lines hello world
  • 11. Simple & Logical operations on images • img = cv.imread ("/content/drive/MyDrive/totfarangi.jpg", cv.IMREAD_COLOR) • # Show the image • cv2_imshow(img) • cv.waitKey(0) • cv.destroyAllWindows() • img.shape (524, 650, 3) • red_Strawberry = img [240:500 , 50:320 ] • cv2_imshow(red_Strawberry) • cv.waitKey(0) • cv.destroyAllWindows()
  • 12. Logical operations on images • ret, maskimg = cv.threshold(img2gray, 40 ,255, cv.THRESH_BINARY) • mask_inv = cv.bitwise_not(maskimg) • cv2_imshow(mask_inv) • cv2.waitKey(0) • cv2.destroyAllWindows()
  • 13. • img1_m = cv.bitwise_and(img1, img2, mask=maskimg) • cv2_imshow(img1_m) • cv2.waitKey(0) • cv2.destroyAllWindows() Logical operations on images
  • 14. Color spaces BGR, RGB , HSV • #BGR • image_bgr = cv.imread('/content/drive/MyDrive/totfarangi.jpg') • image_gr = cv.cvtColor(image_bgr, cv.COLOR_BGR2GRAY) • cv2_imshow(image_bgr) • cv2_imshow(image_gr) • cv2.waitKey(0) • cv2.destroyAllWindows()
  • 15. • # RGB • #blue_ch, green_ch, red_ch = cv.split(image) • image_rgb = cv.cvtColor(image_bgr, cv.COLOR_BGR2RGB) • # BGR opencv • # BGRA / RGBA 4 channel alpha opacity • cv2_imshow(image_rgb) • cv2.waitKey(0) • cv2.destroyAllWindows() Color spaces
  • 16. • # HSV [20, 100, 100] • image_hsv = cv.cvtColor(image_bgr, cv.COLOR_BGR2HSV) • cv2_imshow(image_hsv) • cv2.waitKey(0) • cv2.destroyAllWindows() • plt.imshow(image_hsv) • plt.show() Color spaces