Images are arrays
How does OpenCV represent a picture?
Understand it
OpenCV loads an image into a matrix-like array. Rows come before columns, and a colour image usually has multiple channels. In common OpenCV Python workflows, colour order is BGR rather than RGB, so conversion matters when using other libraries.
Choose a step to inspect it, or run the complete sequence.
A useful analogy
A spreadsheet cell has a row, column and value; a colour pixel has a row, column and channel values.
Worked example
Load an image, inspect shape and dtype, read one pixel, then save a grayscale copy.
import cv2 as cv
image = cv.imread("object.jpg")
print(image.shape, image.dtype)
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
cv.imwrite("object-gray.png", gray) - Create a tiny coloured grid on paper.
- Index three cells as row, column.
- Predict the array shape for height 100, width 200 and three channels.
Quick checkFor img[y, x], which coordinate comes first?
Answer: The row or y-coordinate comes first, followed by the column or x-coordinate.