Lab 1_ Introduction to OpenCV for Computer Vision
Lab 1_ Introduction to OpenCV for Computer Vision
td
3. Convert Colour Spaces: Explore how to convert images between different color
spaces, such as BGR to grayscale or HSV.
tl
4. Perform Basic Image Transformations: Apply basic transformations to images,
including resizing, rotating, and flipping.
Pv
Prerequisites:
ng
● Basic Python Knowledge: Familiarity with Python programming.
● Environment Setup: A Python environment with the ability to install libraries.
Tasks :
ni
ar
Step-by-Step Lab Guide:
Le
2. Verify Installation:
○ You can verify that OpenCV is installed by importing it in a Python script or in an
AL
interactive session.
import cv2
print(cv2.__version__)
import cv2
td
# Check if the image was loaded correctly
if image is None:
tl
print("Error loading image")
else:
Pv
print("Image loaded successfully")
ng
○ Display the image in a window using cv2.imshow().
cv2.waitKey(0)
cv2.destroyAllWindows()
IE
td
# Convert the image to HSV
tl
hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
Pv
# Display the HSV image
cv2.imshow('HSV Image', hsv_image)
cv2.waitKey(0)
ng
cv2.destroyAllWindows()
ni
Step 4: Perform Basic Image Transformations
ar
1. Resize an Image:
○ Resize the image using cv2.resize().
Le
cv2.waitKey(0)
cv2.destroyAllWindows()
N
2. Rotate an Image:
AL
td
cv2.destroyAllWindows()
tl
3. Flip an Image:
Pv
○ Flip the image horizontally, vertically, or both using cv2.flip().
ng
flipped_image = cv2.flip(image, 1)
Conclusion:
IE
This lab provides a foundational understanding of working with images using OpenCV, an
essential skill in computer vision tasks.
AL