我已经从网络摄像头捕获了图像,但是无法读取并保存图像
def signal_handler(signal, frame):
# KeyboardInterrupt detected, exiting
global is_interrupted
is_interrupted = True
vc = cv2.VideoCapture(0)
plt.ion()
if vc.isOpened(): # try to get the first frame
is_capturing, frame = vc.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # makes the blues image look real colored
webcam_preview = plt.imshow(frame)
else:
is_capturing = False
signal.signal(signal.SIGINT, signal_handler)
signal(signal_handler)
is_interrupted = False
while is_capturing:
is_capturing, frame = vc.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # makes the blues image
look real colored
webcam_preview.set_data(frame)
plt.draw()
try: # Avoids a NotImplementedError caused by `plt.pause`
plt.pause(0.05)
except Exception:
pass
if is_interrupted:
vc.release()
break
此代码捕获了图像,但无法读取图像,并且还希望将其保存到所需位置