为什么出现一个问题,告诉我将值设置为浮点数,当我得到时,我需要将其设置为整数?

问题描述 投票:0回答:1

我正在尝试使用免费课程保存摄像机的录像,我说,我需要创建cv2.VideoWriter。我尝试时遇到的问题是:

Traceback (most recent call last):
File ..., line 10, in <module>
    writer = cv2.VideoWriter(filename,cv2.VideoWriter_fourcc(*'DVIX'),20,(width,height))
TypeError: a float is required

我的代码:

import cv2
import numpy as np


cap = cv2.VideoCapture(0)

width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)

  #### THE PROBLEM IS IN THIS LINE ########

    writer = cv2.VideoWriter("images/my_super_vid.mp4",cv2.VideoWriter_fourcc(*'DVIX'),20,(width,height))

######################################

while True:
    ret, frame = cap.read()

    #OPERTAIONS (DRAWING ETC')

    writer.write(frame)

    cv2.imshow("frame",frame)

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

cap.release()
writer.release()
cv2.destroyAllWindows()

我看到了问题,并将其更改为:

writer = cv2.VideoWriter("images/my_super_vid.mp4",cv2.VideoWriter_fourcc(*'DVIX'),float(20),(width,height))

甚至:

writer = cv2.VideoWriter("images/my_super_vid.mp4",cv2.VideoWriter_fourcc(*'DVIX'),20.0,(width,height))

但是在这两次尝试中我都得到了:

Traceback (most recent call last):
  File "....", line 10, in <module>
    writer = cv2.VideoWriter("images/my_super_vid.mp4",cv2.VideoWriter_fourcc(*'DVIX'),20.0,(width,height))
TypeError: integer argument expected, got float

我不知道如何解决它,我尝试了在互联网上看到的解决方案,但没有一个起作用。有同样的问题

opencv python-3.7
1个回答
0
投票

错误是指括号中同一行上的不同值。第一个值必须是浮点数,第二个值必须是int(反之亦然)

© www.soinside.com 2019 - 2024. All rights reserved.