在此之前它一直没有工作。我不明白为什么,我必须将其全部更改为功能吗?第16行以前工作过,我想稍后再将其他所有内容转换为函数。我看到框架无法调用。
import cv2
import time
cap = cv2.VideoCapture(0)
start = time.time()
count=0
while(True):
ret, frame = cap.read()
frame = frame/255
count+=1
cv2.imshow('frame A',frame)
m= (frame[:,::-1])
cv2.imshow('mirror',m)
halved= (frame[:,::2])
cv2.imshow('halved',halved)
gray= ((frame[:,:,2]+ frame[:,:,1]+frame[:,:,0])/3)
cv2.imshow('gray', gray)
negative_gray= ((frame[:,:,-2]+ frame[:,:,-1]+frame[:,:,0])/3)
cv2.imshow= ('negative gray', 1-negative_gray)
border = 20
border_frame= (frame[border:-border,border:-border,:])
cv2.imshow=('border_frame', border_frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.imwrite('final_image.jpg', frame*255) #Save last image to disk
cv2.imwrite('mirror.jpg',m)
cv2.imwrite('halved.jpg',halved)
cv2.imwrite('gray.jpg', gray)
cv2.imwrite('negative_gray.jpg', 1-negative_gray)
cv2.imwrite('border_frame.jpg', border_frame)
break
elapsed_time = time.time()-start
print('Capture speed: {0:.2f} frames per second'.format(count/elapsed_time))
cap.release()
cv2.destroyAllWindows()