0
点赞
收藏
分享

微信扫一扫

Python | OpenCV简单生成调色板

Python芸芸 2022-01-06 阅读 70
opencvpython

一个极其捡漏的调色板…

import cv2
import numpy as np


def nothing(x):
    pass


# 创建一个黑色图像
img = np.zeros((300, 512, 3), np.uint8)
cv2.namedWindow('image')
cv2.createTrackbar('R', 'image', 0, 255, nothing)
cv2.createTrackbar('G', 'image', 0, 255, nothing)
cv2.createTrackbar('B', 'image', 0, 255, nothing)
while 1:
    cv2.imshow('image', img)
    k = cv2.waitKey(1)
    if k == ord('q'):  # 按q键退出
        break
    b = cv2.getTrackbarPos('R', 'image')
    g = cv2.getTrackbarPos('G', 'image')
    r = cv2.getTrackbarPos('B', 'image')
    img[:] = [r, g, b]
cv2.destroyAllWindows()

举报

相关推荐

0 条评论