Getting Started With Python OpenCV - GeeksforGeeks
Getting Started With Python OpenCV - GeeksforGeeks
org/python/getting-started-with-python-opencv/
1 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
print(img)
[[ 87 157 14]
[ 87 157 14]
[ 87 157 14]
...
[ 87 157 14]
[ 87 157 14]
[ 87 157 14]]
[[ 87 157 14]
[ 87 157 14]
[ 87 157 14]
...
[ 87 157 14]
[ 87 157 14]
[ 87 157 14]]
...
[[ 72 133 9]
[ 72 133 9]
[ 72 133 9]
...
[ 87 157 14]
[ 87 157 14]
[ 87 157 14]]
[[ 72 133 9]
2 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
[ 72 133 9]
[ 72 133 9]
...
[ 87 157 14]
[ 87 157 14]
[ 87 157 14]]
[[ 72 133 9]
[ 72 133 9]
[ 72 133 9]
...
[ 87 157 14]
[ 87 157 14]
[ 87 157 14]]]
3 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
# importing cv2
import cv2
image_path = '[Link]'
# Filename
filename = '[Link]'
[Link](0)
[Link]()
4 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
# importing cv2
import cv2
# path
path = '[Link]'
import cv2
import numpy as np
FILE_NAME = '[Link]'
5 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
[Link]("GeeksforGeeks", res)
[Link](0)
[Link]()
•
•
•
import cv2
import numpy as np
import [Link] as plt
image = [Link]("[Link]", 1)
# Loading the image
for i in range(count):
[Link](2, 3, i + 1)
[Link](Titles[i])
[Link](images[i])
6 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
[Link]()
# importing cv2
import cv2
# path
path = '[Link]'
[Link](0)
[Link]()
7 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
# organizing imports
import cv2
import numpy as np
8 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
image1 = [Link]('[Link]')
image2 = [Link]('[Link]')
# organizing imports
import cv2
import numpy as np
9 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
•
•
•
•
# organizing imports
import cv2
import numpy as np
10 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
img2 = [Link]('[Link]')
# organizing imports
import cv2
import numpy as np
11 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
# organizing imports
import cv2
import numpy as np
12 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
# organizing imports
import cv2
import numpy as np
13 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
import cv2
import numpy as np
image = [Link]('[Link]')
[Link]('Translation', img_translation)
[Link](0)
[Link]()
import cv2
FILE_NAME = '[Link]'
14 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
If f (x, y) < T
then f (x, y) = 0
else
f (x, y) = 255
where
f (x, y) = Coordinate Pixel Value
T = Threshold Value.
•
•
15 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
# organizing imports
import cv2
import numpy as np
16 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
# organizing imports
import cv2
import numpy as np
17 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
# organizing imports
import cv2
import numpy as np
18 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
# importing libraries
import cv2
import numpy as np
image = [Link]('[Link]')
# Gaussian Blur
Gaussian = [Link](image, (7, 7), 0)
[Link]('Gaussian Blurring', Gaussian)
[Link](0)
# Median Blur
median = [Link](image, 5)
[Link]('Median Blurring', median)
[Link](0)
# Bilateral Blur
bilateral = [Link](image, 9, 75, 75)
[Link]('Bilateral Blurring', bilateral)
[Link](0)
[Link]()
19 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
•
•
import cv2
20 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
import cv2
import numpy as np
# Grayscale
gray = [Link](image, cv2.COLOR_BGR2GRAY)
# Finding Contours
# Use a copy of the image e.g. [Link]()
# since findContours alters the image
contours, hierarchy = [Link](edged,
cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
[Link]('Contours', image)
[Link](0)
[Link]()
21 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
•
•
•
•
•
•
•
•
•
•
•
[Link]('Input', img)
[Link]('Erosion', img_erosion)
[Link]('Dilation', img_dilation)
[Link](0)
[Link]()
22 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
import numpy as np
import cv2
# Convert it to grayscale
query_img_bw = [Link](query_img,cv2.COLOR_BGR2GRAY)
train_img_bw = [Link](train_img, cv2.COLOR_BGR2GRAY)
23 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
•
•
•
•
24 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
# Creating rectangle
[Link](img, (30, 30), (300, 200), (0, 255, 0), 5)
[Link]('dark', img)
•
•
•
•
25 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
26 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
27 of 28 2/5/2026, 1:19 PM
Getting Started with Python OpenCV - GeeksforGeeks [Link]
28 of 28 2/5/2026, 1:19 PM