代码:
#coding=utf8
#图像边缘检测
import numpy as np
import cv2
import time
def cannyedge():
capInput = cv2.VideoCapture(0)
if not capInput.isOpened(): print('Cap failed because of camera')
while 1:
ret, img = capInput.read()
edges = cv2.Canny(img, 80, 150)#显示图像边缘
cv2.imshow('Edge', edges)
if cv2.waitKey(1) & 0xFF == 27:
break
elif cv2.waitKey(1) & 0xFF== ord(' '):#按下空格键之后暂停屏幕
while cv2.waitKey(1) & 0xFF != ord(' '): time.sleep(.1)
# When everything done, release the capture
capInput.release()
cv2.destroyAllWindows()
cannyedge()