Create basic design by using connecting dot's using your mouse-
I have been create this by using mouse event check out the code below-
use Python, OpenCv , NumPy
import numpy as np
import cv2
def click_event(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
print(x, " , ", y)
font = cv2.FONT_HERSHEY_SIMPLEX
strXY = str(x) + ' , ' + str(y)
# cv2.putText(img,strXY, (x, y), font, .1, (255, 255, 0), 2)
cv2.circle(img, (x, y), 3, (0, 0, 255), -1)
points.append((x, y))
if len(points) >= 2:
cv2.circle(img, points[-1], 3, (0, 0, 255), -1)
# cv2.putText(img,strXY, points[-1], font, .1, (255, 255, 0), 2)
cv2.line(img, points[-2], points[-1], (0, 0, 255), 1)
cv2.imshow("Image", img)
points = []
img = np.zeros((512, 512, 3))
cv2.imshow("Image", img)
cv2.setMouseCallback('Image', click_event)
cv2.waitKey(0)
cv2.destroyAllWindows()
Check this output -
Comments
Post a Comment