怎滚滚滚么才能让插入的代码块不出错呢
import numpy as np
import cv2
drawing=False
mode=True
ix,iy=-1,-1
def draw_circle(event,x,y,flags,param):
global ix,iy,drawing,mode#global 全局变量啊
if event==cv2.EVENT_LBUTTONDOWN:
drawing==True
ix,iy=x,y
elif event==cv2.EVENT_MOUSEMOVE and flags==cv2.EVENT_FLAG_LBUTTON:
if drawing==True:
if mode==True:
cv2.rectangle(img,(ix,iy),(x,y),(0,255,0),3)
else:
cv2.circle(img,(x,y),3,(0,0,255),-1)
elif event==cv2.EVENT_LBUTTONUP:
drawing==False
if mode==True:
cv2.rectangle(img,(ix,iy),(x,y),(0,255,0),3)
else:
cv2.circle(img,(x,y),5,(0,0,255),-1)
img=cv2.imread('C:\\Users\\WLX\\Desktop\\2.jpg',cv2.IMREAD_COLOR)
cv2.namedWindow('image')
cv2.setMouseCallback('image',draw_circle)
while(1):
cv2.imshow('image',img)
k=cv2.waitKey(20)&0xFF
if k==ord('m'):
mode=not mode
elif k==27:
break
cv2.imwrite('C:\\Users\\WLX\\Desktop\\fsf.jpg',img)
cv2.destroyAllWindows()
haohaoxuexi
haohaoxuexi
import numpy as np
import cv2
img=cv2.imread('C:\\Users\\WLX\\Desktop\\2.jpg',0)#显示灰色照片
#img=cv2.imread('C:\\Users\\WLX\\Desktop\\2.jpg',cv2.IMREAD_GRAYSCALE)#显示黑白照片
#img=cv2.imread('C:\\Users\\WLX\\Desktop\\2.jpg',cv2.IMREAD_COLOR)#显示彩色照片
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite('C:\\Users\\WLX\\Desktop\\fsf.jpg',img)# 保存一副图像
import numpy as np
import cv2
img=cv2.imread('C:\\Users\\WLX\\Desktop\\2.jpg',0)#显示灰色照片
#img=cv2.imread('C:\\Users\\WLX\\Desktop\\2.jpg',cv2.IMREAD_GRAYSCALE)#显示黑白照片
#img=cv2.imread('C:\\Users\\WLX\\Desktop\\2.jpg',cv2.IMREAD_COLOR)#显示彩色照片
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite('C:\\Users\\WLX\\Desktop\\fsf.jpg',img)# 保存一副图像
hahaha
点击打开链接