返回
import cv2
import numpy as np
img = cv2.imread("img/img.jpg")
cv2.namedWindow("img", 0)
cv2.resizeWindow("img", 720, 960)
cv2.createTrackbar("x", "img", 0, img.shape[0], lambda x: x)
cv2.createTrackbar("y", "img", 0, img.shape[1], lambda x: x)
while True:
x = cv2.getTrackbarPos("x", "img")
y = cv2.getTrackbarPos("y", "img")
# 在画布上绘制文本
img_copy = img.copy()
text = 'OpenCV' # 文本内容
position = (y, x) # 文本位置
font = cv2.FONT_HERSHEY_TRIPLEX
font_scale = 1.5 # 文本大小
color = (255, 255, 255) # 白色文本
thickness = 2
cv2.putText(img_copy, text, position, font, font_scale, color, thickness)
cv2.imshow('img', img_copy)
k = cv2.waitKey(1) & 0xFF
if k == 27:
cv2.imwrite("img/watermark.jpg", img_copy)
break
cv2.destroyAllWindows()