解决保存图片为空的错误
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 11 KiB |
@@ -1,21 +1,25 @@
|
|||||||
|
from pickletools import uint8
|
||||||
|
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
img=np.ones((512,512))
|
img = np.ones((512, 512, 3), dtype=np.uint8) * 255
|
||||||
|
|
||||||
|
|
||||||
|
def draw_circle(event, x, y, flags, param):
|
||||||
|
if event == cv.EVENT_LBUTTONDOWN:
|
||||||
|
cv.circle(img, (x, y), 20, (0, 0, 0), -1)
|
||||||
|
|
||||||
def draw_circle(event,x,y,flags,param):
|
|
||||||
if event==cv.EVENT_LBUTTONDOWN:
|
|
||||||
cv.circle(img,(x,y),20,0,-1)
|
|
||||||
|
|
||||||
cv.namedWindow('show_img')
|
cv.namedWindow('show_img')
|
||||||
|
|
||||||
cv.setMouseCallback('show_img',draw_circle)
|
cv.setMouseCallback('show_img', draw_circle)
|
||||||
while(1):
|
while (1):
|
||||||
cv.imshow('show_img',img)
|
cv.imshow('show_img', img)
|
||||||
pressedKey=cv.waitKey(5)
|
pressedKey = cv.waitKey(5)
|
||||||
if pressedKey==ord('q'):
|
if pressedKey == ord('q'):
|
||||||
break
|
break
|
||||||
elif pressedKey==ord('s'):
|
elif pressedKey == ord('s'):
|
||||||
cv.imwrite("mouse_draw_circle.jpg",img);
|
cv.imwrite("mouse_draw_circle.jpg", img);
|
||||||
print("save success")
|
print("save success")
|
||||||
cv.destroyAllWindows()
|
cv.destroyAllWindows()
|
||||||
Reference in New Issue
Block a user