提交 9dfe922e 编写于 作者: F feilong

添加资源目录

上级 de8888b3
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
"export": [ "export": [
"img_read_write.json", "img_read_write.json",
"video_read_write.json", "video_read_write.json",
"img_buffer_convert.json" "img_buffer_convert.json",
"doodle.json"
] ]
} }
\ No newline at end of file
import numpy as np
import cv2 as cv
class Painter:
def __init__(self, background, color) -> None:
self.mouse_is_pressed = False
self.last_pos = (-1, -1)
self.img = np.zeros((300, 512, 3), np.uint8)
self.background = background
self.color = color
self.title = '画板,拖动鼠标绘制矩形框,按ESC退出'
self.window_name = 'painter'
def run(self):
cv.namedWindow(self.window_name, title=self.title)
cv.setMouseCallback(self.window_name, lambda event, x, y,
flags, param: self.draw_circle(event, x, y, flags, param))
while(1):
cv.imshow(self.window_name, self.img)
k = cv.waitKey(1) & 0xFF
if k == 27:
break
cv.destroyAllWindows()
def draw_circle(self, event, x, y, flags, param):
current_pos = (x, y)
if event == cv.EVENT_LBUTTONDOWN:
self.mouse_is_pressed = True
self.last_pos = current_pos
elif event == cv.EVENT_MOUSEMOVE:
if self.mouse_is_pressed == True:
cv.rectangle(self.img, self.last_pos,
current_pos, (0, 255, 0), -1)
elif event == cv.EVENT_LBUTTONUP:
self.mouse_is_pressed = False
cv.rectangle(self.img, self.last_pos, current_pos, (0, 255, 0), -1)
if __name__ == '__main__':
p = Painter(background=(100, 100, 100), color=(200, 150, 50))
p.run()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册