时间:2021-05-22
如下所示:
def draw_circle(event,x,y,flags,param): global ix,iy,drawing,mode,start_x,start_y if event == cv2.EVENT_LBUTTONDOWN: if drawing == False: start_x, start_y = x,y ix,iy = x,y drawing = True elif drawing == True: cv2.line(img,(ix,iy),(x,y),(0,255,0),3) ix, iy = x, y print(drawing) elif event == cv2.EVENT_MBUTTONDOWN: drawing = False cv2.line(img, (ix, iy), (start_x, start_y), (0, 255, 0), 3) print(drawing) # # elif event == cv2.EVENT_RBUTTONUP: # cv2.line(img,(ix,iy),(x,y),(0,255,0),3)# Next we have to bind this mouse callback function to OpenCV # # window. In the main loop, we should set a keyboard binding for# key ‘m' to toggle between rectangle and circle.img = np.zeros((512,512,3), np.uint8)cv2.namedWindow('image')cv2.setMouseCallback('image',draw_circle)while(1): cv2.imshow('image',img) k = cv2.waitKey(1) & 0xFF if k == ord('m'): # 切换模式 mode = not mode elif k == 27: breakcv2.destroyAllWindows()以上这篇python_opencv用线段画封闭矩形的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例为大家分享了python-opencv鼠标事件画框圈定目标的具体代码,供大家参考,具体内容如下在视频/相机中,用鼠标画矩形框,圈定目标,从而获得鼠标的起
最近跟着OpenCV2-Python-Tutorials在学习python_opencv中直方图的反向投影时,第一种方法是使用numpy实现将图中的红色玫瑰分割
OpenCV中circle与rectangle函数显示,只不过rectangle在图像中画矩形,circle在图像中画圆。voidcircle(Matimg,P
本文实例为大家分享了OpenCV检测图像中矩形的具体代码,供大家参考,具体内容如下前言1.OpenCV没有内置的矩形检测的函数,如果想检测矩形,要自己去实现。2
本文实例为大家分享了OpenCV鼠标绘制截取矩形区域图像的具体代码,供大家参考,具体内容如下在opencv中利用鼠标绘制矩形,代码如下:#include#inc