可以使用OpenCV中的VideoCapture类来解决这个问题。具体方法是在打开视频流之后通过read()方法来读取帧,然后将其显示出来。
示例代码如下:
import cv2
cap = cv2.VideoCapture("video.mp4")
if not cap.isOpened():
print("Cannot open video")
exit()
ret, frame = cap.read()
if not ret:
print("Failed to capture first frame")
exit()
cv2.imshow("First Frame", frame)
cv2.waitKey(0)
cv2.destroyAllWindows()
在上面的代码中,我们首先打开了一个视频流,并检查是否已经成功打开。然后通过调用read()方法来读取第一帧,如果成功读取,则将其显示出来。
下一篇:不活动后的指纹