Code Explanation:
1) Importing OpenCV
import cv2
Imports the OpenCV library.
Used for image processing (loading, creating, editing, saving images, etc.).
2) Importing NumPy
import numpy as np
Imports NumPy, which is often used alongside OpenCV.
OpenCV images are represented as NumPy arrays.
3) Creating a Blank Image
img = np.zeros((100,200,3), dtype=np.uint8)
np.zeros(...) creates an array filled with zeros.
Shape: (100, 200, 3)
100 → height (rows / pixels vertically)
200 → width (columns / pixels horizontally)
3 → color channels (BGR: Blue, Green, Red)
dtype=np.uint8: Each pixel value is an unsigned 8-bit integer (0–255).
Since all values are 0, this creates a black image of size 100×200 pixels.
4) Printing the Shape
print(img.shape)
Displays the shape of the NumPy array (image).
Final Output
(100, 200, 3)
Download Book - 500 Days Python Coding Challenges with Explanation
.png)

0 Comments:
Post a Comment