Python opencv学习-5创建带调色板的画板

test5:带调色板的画板,可改变线的粗细,颜色,缺点,其实是不断画圆,鼠标动作快了能看出执行间隔
import cv2
import numpy as np

drawing = False


# mouse callback function
def nothing(x):
    pass


def draw_circle(event, x, y, flags, param):
    global drawing
    s = cv2.getTrackbarPos('size', 'image')
    b = cv2.getTrackbarPos('B', 'image')
    r = cv2.getTrackbarPos('R', 'image')
    g = cv2.getTrackbarPos('G', 'image')

    if event == cv2.EVENT_LBUTTONDOWN:
        drawing = True

    elif event == cv2.EVENT_MOUSEMOVE:
        # cv2.circle(img,(x,y),s,(b,g,r),-1)
        if drawing:
            cv2.circle(img, (x, y), s, (b, g, r), -1)

    elif event == cv2.EVENT_LBUTTONUP:
        drawing = False


# Create a black image, a window and bind the function to window
img = np.zeros((1024, 1024, 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)
cv2.createTrackbar('size', 'image', 1, 255, nothing)
cv2.setMouseCallback('image', draw_circle)

while (1):
    cv2.imshow('image', img)
    if cv2.waitKey(20) & 0xFF == 27:
        break
cv2.destroyAllWindows()

Python opencv学习-5创建带调色板的画板

上一篇:转载:.NET Core 图片操作在 Linux/Docker 下的坑


下一篇:.Net Core 使用 System.Drawing.Common 在CentOS下报错