相关疑难解决方法(0)

OpenCV Python视频播放 - 如何为cv2.waitKey()设置正确的延迟

我使用以下代码捕获视频文件,翻转并保存.

#To save a Video File

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

# Define the codec and create VideoWriter object
fourcc = cv2.cv.CV_FOURCC(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        frame = cv2.flip(frame,0)

        # write the flipped frame
        out.write(frame)

        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

该程序将输出保存为output.avi

现在,为了播放视频文件,我使用了以下程序

#Playing Video from File

import numpy as np
import cv2

cap …
Run Code Online (Sandbox Code Playgroud)

python video opencv frame-rate delay

4
推荐指数
1
解决办法
2万
查看次数

ord('q')和0xFF的用法

我无法理解以下代码段-

if cv2.waitKey(0) & 0xFF == ord('q'):
break
Run Code Online (Sandbox Code Playgroud)

在此代码中-

    1 import numpy as np
    2 import cv2
    3 
    4 cap = cv2.VideoCapture(0)
    5 
    6 while(True):
    7     # Capture frame-by-frame
    8     ret, frame = cap.read()
    9 
   10     # Our operations on the frame come here
   11     gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
   12 
   13     # Display the resulting frame
   14     cv2.imshow('frame',gray)
   15     if cv2.waitKey(1) & 0xFF == ord('q'):
   16         break
   17 
   18 # When everything done, release the capture
   19 cap.release()
   20 cv2.destroyAllWindows() …
Run Code Online (Sandbox Code Playgroud)

python opencv

0
推荐指数
2
解决办法
2759
查看次数

标签 统计

opencv ×2

python ×2

delay ×1

frame-rate ×1

video ×1