I want to set different color circle in grayscale image when I click left and right button. However, the both circle color are only black and they does not change?
Would you tell me what is the problem in the case?
The writing function is the below.
def mouse_event(event, x, y, flags, parmas):
img2 = img_gray.copy()
cv2.circle(img2, center=(x, y), radius=2, color=(0, 0, 255), thickness=-1)
if event == cv2.EVENT_MOUSEMOVE:
# coordinate
pos_str = '(x,y)=(' str(x) ', ' str(y) ')'
cv2.putText(img2, text=pos_str, org=(30, 30), fontFace=cv2.FONT_HERSHEY_PLAIN,
fontScale=1, color=255, thickness=1, lineType=cv2.LINE_AA)
# gray
pixelval = img_gray[y,x]
gray_str ='(pixel value)=(' str(pixelval) ')'
cv2.putText(img2, text=gray_str,org=(30,60),fontFace=cv2.FONT_HERSHEY_PLAIN,
fontScale=1,color=255,thickness=1,lineType=cv2.LINE_AA)
elif event == cv2.EVENT_LBUTTONDBLCLK:
# store spots
cv2.circle(img_gray, (x,y), 10, (0, 255, 255), 2)
cv2.putText(img2, text='Saved!', org=(30, 50), fontFace=cv2.FONT_HERSHEY_PLAIN,
fontScale=3, color=200, thickness=1, lineType=cv2.LINE_AA)
listA.append(img_gray[y,x])
elif event == cv2.EVENT_RBUTTONDBLCLK:
# store skin
cv2.circle(img_gray, (x,y), 10, (0, 0, 255), 2)
cv2.putText(img2, text='Saved!', org=(30, 50), fontFace=cv2.FONT_HERSHEY_PLAIN,
fontScale=3, color=200, thickness=1, lineType=cv2.LINE_AA)
listB.append(img_gray[y,x])
#display
cv2.imshow('window', img2)
CodePudding user response:
