Embedded_game/qianrushi/opencv提取颜色.py

19 lines
441 B
Python
Raw Permalink Normal View History

2025-01-02 12:48:11 +08:00
# -*- coding:utf-8 -*-
# @Author len
# @Create 2023/10/22 15:07
import cv2
# 读取二维码图像文件
image_path = 'data/red.jpg'
image = cv2.imread(image_path)
# 获取图像每个像素的颜色值
height, width, _ = image.shape
for y in range(height):
for x in range(width):
# 获取像素的BGR颜色值
b, g, r = image[y, x]
# 输出颜色值
print(f"Pixel at ({x}, {y}): R={r}, G={g}, B={b}")