Adv-Py: Unit 1 (Book-back Questions)
Generated and Prepared By Thiruselvan (ThiruXD)
Part B – Short Answer Questions (5 Marks Each)
Q9. Define computer vision and image processing. Explain the difference between them with one example each.
Computer Vision is a field of Artificial Intelligence that enables computers to interpret, understand and extract meaningful information from digital images and videos (similar to human vision).
Image Processing is the process of performing operations on images to enhance them, extract features or transform them into a more useful form.
Difference:
| Basis | Image Processing | Computer Vision |
|---|---|---|
| Goal | Improve or transform the image | Understand the content of the image |
| Output | Modified image | Information / Decision |
| Example | Brightness adjustment, noise removal, sharpening | Face detection, object recognition, traffic sign identification |
Example of Image Processing: Increasing the contrast of a low-light photograph.
Example of Computer Vision: Detecting whether a person is wearing a helmet in a factory surveillance video.
Q10. What is OpenCV? List any five important features of OpenCV.
OpenCV (Open Source Computer Vision Library) is a popular open-source library developed for computer vision, image processing and machine learning tasks. It was originally developed by Intel and is widely used with Python, C++, Java etc.
Five Important Features:
- Real-time image and video processing capability
- Large collection of optimized image processing functions
- Support for multiple programming languages (Python, C++, Java)
- Cross-platform (Windows, Linux, macOS, Android, iOS)
- Built-in modules for object detection, tracking, feature matching, camera calibration and DNN (Deep Neural Networks)
Q11. Explain the terms pixel, resolution, channel and colour model.
- Pixel: The smallest unit of a digital image. Each pixel stores intensity or colour information.
- Resolution: The total number of pixels in an image, usually expressed as Width × Height (e.g., 1920 × 1080). Higher resolution means more detail.
- Channel: A single component of colour information. A grayscale image has 1 channel, while a colour image has 3 channels (B, G, R).
- Colour Model: A mathematical model used to represent colours as numbers. Common models are RGB, BGR, HSV, Grayscale etc.
Q12. Differentiate between RGB, BGR, grayscale and HSV colour models.
| Colour Model | Channels | Description | Used In |
|---|---|---|---|
| RGB | Red, Green, Blue | Most common human-friendly model | Matplotlib, PIL, Web |
| BGR | Blue, Green, Red | Default colour order in OpenCV | OpenCV |
| Grayscale | Single intensity | 0 = Black, 255 = White | Simple processing |
| HSV | Hue, Saturation, Value | Separates colour from intensity (lighting) | Colour-based detection |
Key Point: OpenCV uses BGR by default, not RGB.
Q13. Write a Python OpenCV program to read an image, display it and save it with a new filename.
import cv2
# Read the image
img = cv2.imread('input.jpg')
# Check if image is loaded
if img is None:
print("Error: Image not loaded")
else:
# Display the image
cv2.imshow('Original Image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Save the image with a new name
cv2.imwrite('output_image.jpg', img)
print("Image saved successfully")Q14. Explain why it is important to check whether cv.imread() has loaded an image successfully.
If the file path is incorrect, the file is missing, or the image is corrupted, cv2.imread() returns None instead of an image.
If we do not check this and try to use the image (for example, accessing img.shape or displaying it), the program will raise an error such as:
AttributeError: 'NoneType' object has no attribute 'shape'
Checking prevents the program from crashing and helps in proper error handling.
Q15. What is image cropping? Explain the format image[y1:y2, x1:x2].
Image Cropping is the process of selecting and extracting a rectangular Region of Interest (ROI) from an image.
In OpenCV (NumPy), cropping is done using array slicing:
cropped = image[y1:y2, x1:x2]y1:y2→ Starting row to ending row (vertical direction)x1:x2→ Starting column to ending column (horizontal direction)
Note: In OpenCV, the origin (0,0) is at the top-left corner. y increases downward and x increases rightward.
Q16. Explain image.shape, image.size and image.dtype with examples.
Assuming a colour image is loaded:
img = cv2.imread('image.jpg')-
img.shape → Returns a tuple
(height, width, channels)Example:
(480, 640, 3) -
img.size → Total number of pixels × channels
Example:
480 × 640 × 3 = 921600 -
img.dtype → Data type of pixel values
Example:
uint8(values range from 0 to 255)
Part C – Long Answer / Essay Questions (10 Marks Each)
Q17. Explain the complete workflow of a basic computer vision system from image acquisition to decision making. Support your answer with a suitable example such as face detection or traffic sign recognition.
Complete Workflow of a Computer Vision System:
-
Image Acquisition
Capture image/video using camera, upload image, or read from file.
-
Preprocessing
Resize, convert to grayscale, noise removal, contrast enhancement, etc.
-
Feature Extraction / Detection
Detect edges, corners, contours, or use deep learning models to detect objects.
-
Analysis / Recognition
Classify or interpret the extracted features (e.g., identify face, read traffic sign).
-
Decision Making / Output
Take action based on the result (raise alarm, control vehicle, mark attendance, etc.).
Example: Face Detection System
- Acquisition: Webcam captures frame
- Preprocessing: Convert to grayscale
- Detection: Haar Cascade or DNN face detector finds faces
- Decision: Draw rectangle around face and display “Face Detected”
Q18. Discuss the major applications of computer vision in healthcare, agriculture, manufacturing, autonomous vehicles and security. Explain the importance of computer vision in modern society.
Major Applications:
- Healthcare: Tumour detection in MRI/CT scans, diabetic retinopathy detection, surgical assistance, X-ray analysis.
- Agriculture: Crop health monitoring, weed detection, fruit counting, yield estimation using drones.
- Manufacturing: Quality inspection, defect detection on production line, robotic assembly.
- Autonomous Vehicles: Lane detection, traffic sign recognition, pedestrian detection, obstacle avoidance.
- Security: Face recognition, intrusion detection, number plate recognition, surveillance analytics.
Importance in Modern Society:
Computer vision is transforming industries by enabling automation, improving accuracy, reducing human error, enhancing safety, and creating new intelligent applications. It is one of the key technologies driving Industry 4.0 and smart systems.
Q19. Explain digital image representation in detail. Your answer should include pixels, resolution, bit depth, image matrix, colour channels, grayscale images and colour models.
A digital image is represented as a matrix (2D or 3D array) of numbers.
- Pixel: Smallest element of the image.
- Resolution: Number of rows and columns (Height × Width).
- Bit Depth: Number of bits used to store each pixel (8-bit → 0 to 255).
- Image Matrix:
- Grayscale → 2D matrix
- Colour → 3D matrix (Height × Width × Channels)
- Colour Channels: B, G, R in OpenCV.
- Grayscale Image: Single channel, each pixel represents intensity.
- Colour Models: RGB/BGR (additive), HSV (Hue-Saturation-Value), Grayscale etc.
In OpenCV, images are stored as NumPy arrays of data type uint8.
Q20. Describe the basic OpenCV image input-output workflow. Include cv.imread(), cv.imshow(), cv.waitKey(), cv.destroyAllWindows() and cv.imwrite() with suitable code examples.
Basic Workflow:
import cv2
# 1. Read image
img = cv2.imread('image.jpg')
# 2. Display image
cv2.imshow('My Image', img)
# 3. Wait for key press
cv2.waitKey(0) # 0 means wait forever
# 4. Destroy all windows
cv2.destroyAllWindows()
# 5. Save image
cv2.imwrite('new_image.jpg', img)cv2.imread()→ Loads the imagecv2.imshow()→ Displays the image in a windowcv2.waitKey()→ Waits for a key eventcv2.destroyAllWindows()→ Closes all OpenCV windowscv2.imwrite()→ Saves the image to disk
Q21. Explain image manipulation operations in OpenCV, including cropping, resizing, flipping, rotation, drawing and colour conversion. Give syntax and examples wherever necessary.
-
Cropping:
cropped = img[y1:y2, x1:x2] -
Resizing:
resized = cv2.resize(img, (width, height)) -
Flipping:
flipped = cv2.flip(img, 1)# 0 = vertical, 1 = horizontal -
Rotation:
M = cv2.getRotationMatrix2D((cx, cy), angle, scale) rotated = cv2.warpAffine(img, M, (w, h)) -
Drawing:
- Line:
cv2.line() - Rectangle:
cv2.rectangle() - Circle:
cv2.circle() - Text:
cv2.putText()
- Line:
-
Colour Conversion:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
Part D – Analytical / Case-Based Question
Q22 (Case Study). A college wants to build a simple system that captures student ID card images and automatically crops the face region for further processing. Explain which OpenCV operations will be needed for reading the image, checking image properties, cropping the region of interest, resizing the crop and saving the output.
Solution:
Required OpenCV Operations:
-
Reading the Image
img = cv2.imread('id_card.jpg') -
Checking whether image loaded successfully
if img is None: print("Error loading image") -
Checking Image Properties
print(img.shape) # (height, width, channels) print(img.dtype) -
Cropping the Face Region (ROI)
Assuming face is located approximately at coordinates (x1, y1) to (x2, y2):
face = img[y1:y2, x1:x2] -
Resizing the Cropped Face (for standard size)
face_resized = cv2.resize(face, (200, 200)) -
Saving the Output
cv2.imwrite('student_face.jpg', face_resized)
Optional Improvements: Use a face detector (Haar Cascade or DNN) to automatically find the face coordinates instead of hard-coding them.