我的图像是一个ndarray(2048,2048,3)。我想对其进行修改,并保留以前版本的副本(约5个),以便我可以撤销通过click事件所做的任何修改。
在下面的代码中,每次单击图像我都会画一个圆圈。但是,我想存储多个图像,并为每次右键单击删除最后一个图像(pop()
)。
click_pts = []
def click(event, x, y, flags, param):
global click_pts, image, image_ref
if event == cv2.EVENT_LBUTTONDOWN:
click_pts.append((x, y))
image_ref = np.ndarray.copy(image)
cv2.circle(image, (x, y), 5, (255, 0, 0), -1)
cv2.imshow("image", image)
print((x, y))
elif event == cv2.EVENT_RBUTTONDOWN:
click_pts.pop()
image = np.ndarray.copy(image_ref)
cv2.imshow("image", image)
image = cv2.imread('images/RT1_2th.png')
image_ref = np.ndarray.copy(image)
cv2.namedWindow("image")
cv2.setMouseCallback("image", click)
# Loop until 'q' is pressed
while True:
cv2.imshow("image", image)
key = cv2.waitKey(1) & 0xFF
if key == ord('q'):
break
cv2.destroyAllWindows()
我无法找到任何可靠的方式来将多个图像存储在一个数组中……它与数组的类型无关,但是具有.pop()
功能会很棒。
另外,(旁注)在OpenCV example中,image
没有传递到函数中,并且导致单击(如果我从global image
中删除click
,则:]]]
UnboundLocalError: local variable 'image' referenced before assignment
我不太喜欢全局变量,我想知道,还有什么选择?
我的图像是一个ndarray(2048,2048,3)。我想对其进行修改,并保留以前版本的副本(约5个),以便我可以撤销通过click事件所做的任何修改。在下面的代码中,我正在绘制...
创建一个NumPy零数组。