在VideoWriter方法中,FPS值不能理解为十进制或整数值

2024-05-19 15:39:44 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,目前,我正在尝试提取一个原始视频文件,附加文件名以创建一个新文件,对原始文件的每一帧进行操作,并将每一帧写入新视频

我已经查出了错误。在这里 newVid=cv2.VideoWriter(输出,-1,30.0,(newW,newH))

当我以每秒30帧的速度运行这行代码时,python(在Spyder 4.1 IDE上)说30是一个元组,而不是一个实数。当我用30.0运行它时,它说它需要一个整数,而不是浮点

现在,忽略对原始图像的操作,它只是一个模板对象检测,按照我需要的方式工作。这是我在更广泛的脚本中遇到的唯一错误

# importing libraries 
import cv2 
import numpy as np 

# Create a VideoCapture object and read from input file 
path = r'C:\Users\BeckerLab\Downloads\20200314165554.MTS'

cap = cv2.VideoCapture(path) 

point = path.find('.')

def insert_dash(path, point):
    return path[:point] + '_processed' + path[point:]

newH = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
newW = cap.get(cv2.CAP_PROP_FRAME_WIDTH)

output = insert_dash(path, point)

newVid = cv2.VideoWriter(output,-1, 30.0, (newW, newH))

cap.release() 
newVid.release()
# Closes all the frames 
cv2.destroyAllWindows()

核结果

Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 7.2.0 -- An enhanced Interactive Python.
Traceback (most recent call last):

  File "C:\Users\BeckerLab\almost.py", line 20, in <module>
    newVid = cv2.VideoWriter(output,-1, 30.0, (newW, newH))

TypeError: integer argument expected, got float


runfile('C:/Users/BeckerLab/almost.py', wdir='C:/Users/BeckerLab')
Traceback (most recent call last):

  File "C:\Users\BeckerLab\almost.py", line 20, in <module>
    newVid = cv2.VideoWriter(output,-1, 30, (newW, newH))

TypeError: must be real number, not tuple

Tags: 文件pathpyoutput错误cv2userspoint