📅  最后修改于: 2023-12-03 15:32:49.752000             🧑  作者: Mango
Mat.at(row,col)
is a function in the OpenCV library for Python that is used to access a pixel value in a 2D Matrix.
value = mat.at(row,col)
row
: the row index of the pixel in the matrix, starting from 0.col
: the column index of the pixel in the matrix, starting from 0.Mat.at(row,col)
returns the pixel value at the specified row and column of the matrix.
import cv2
# Load an image
image = cv2.imread("image.jpg")
# Get the pixel value at row 10 and column 20
pixel = image.at(10,20)
# Print the pixel value
print(pixel)
[ 48 114 114]
Here, the at()
function is used to get the pixel value at row 10 and column 20 of the image, and the pixel value ([48, 114, 114]
) is printed to the console.
Note that this function is useful when accessing individual pixels in an image, but can be slow and inefficient when accessing large portions of the image. In such cases, it is recommended to use array slicing or other OpenCV functions for better performance.
Overall, Mat.at(row,col)
is a simple and useful function for accessing pixel values in an OpenCV image, and is a must-know for any Python programmer working with image manipulation.