1.
OpenCV (cv2) – Computer Vision Library
Full form: Open Source Computer Vision Library
Common Functions
Function Description Example
img =
[Link]('[Link]') Reads an image [Link]('[Link]')
[Link]('Window', img)
Displays an image in
a window
[Link](0)
Waits for a key
press
[Link]()
Closes all OpenCV
windows
[Link]('[Link]', img) Saves image to file
[Link](img, Converts image to
cv2.COLOR_BGR2GRAY) grayscale
[Link](img, (width, height)) Resizes the image
[Link](img, value, max,
type) Applies thresholding
[Link](img, low, high)
Edge detection using
Canny
[Link](img, (5,5), 0)
Smooths/Blurs the
image
[Link](img, pt1, pt2,
color, thickness) Draws rectangle
[Link](img, center, radius,
color, thickness) Draws circle
[Link](img, pt1, pt2, color,
thickness) Draws line
Matplotlib – pyplot Module
Use: Plotting and visualizing data using graphs and charts.
🔹 Import
import [Link] as plt
Common Plotting Functions
Function Description Example
[Link](x, y) Line graph [Link]([1,2,3],[4,5,6])
Function Description Example
[Link](x, y) Bar graph
[Link](data) Histogram
[Link](x, y) Scatter plot
[Link](values, labels=labels) Pie chart
[Link]('Title') Adds title
[Link]('X-axis') Labels X-axis
[Link]('Y-axis') Labels Y-axis
[Link](True) Adds grid lines
[Link]() Displays the plot
Example
import [Link] as plt
x = [1,2,3,4]
y = [10,20,15,25]
[Link](x, y, color='green')
[Link]("Sales Data")
[Link]("Week")
[Link]("Sales")
[Link]()
3. NumPy – Numerical Python
Use: Fast mathematical operations on arrays and matrices.
🔹 Import
import numpy as np
🔹 Common NumPy Functions
Function Description Example
[Link]([1,2,3]) Creates array
[Link]((3,3)) 3x3 matrix of zeros
[Link]((2,2)) 2x2 matrix of ones
[Link](0,10,2) Creates array with step
[Link](0,1,5) 5 equally spaced values
[Link](arr) Returns shape of array
[Link](arr, (r,c)) Changes shape
[Link](arr) Mean
[Link](arr) Median
[Link](arr) Standard deviation
[Link](arr) Sum of elements
[Link](arr) Maximum
Function Description Example
[Link](arr) Minimum
[Link](a,b) Matrix multiplication
[Link](arr) Square root
Example Combining All Three
import cv2
import numpy as np
import [Link] as plt
# Read and process image
img = [Link]('[Link]')
gray = [Link](img, cv2.COLOR_BGR2GRAY)
# Display using matplotlib
[Link](1,2,1)
[Link]("Original")
[Link]([Link](img, cv2.COLOR_BGR2RGB))
[Link](1,2,2)
[Link]("Grayscale")
[Link](gray, cmap='gray')
[Link]()
# Use numpy on image
print("Mean pixel value:", [Link](gray))