作者:宝丁2502907973 | 来源:互联网 | 2024-10-18 18:51
ImusingOpenCVtodosomecalculationsonmoviesImadeinexperiments.TodothisIneedsomepro
I'm using OpenCV to do some calculations on movies I made in experiments. To do this I need some properties from the movies and it would be handy if I could automaticly detect them from the movie itself. In the documentation I find the following code:
我正在使用OpenCV对我在实验中制作的电影进行一些计算。要做到这一点,我需要电影中的一些属性,如果我可以从电影本身自动检测它们,它会很方便。在文档中,我找到以下代码:
cv2.VideoCapture.get(propId) → retval
In the list below it states that for the total number of frames propId
should be CV_CAP_PROP_FRAME_WIDTH
. However when I try the following I get an error:
在下面的列表中,它指出,对于总帧数,propId应为CV_CAP_PROP_FRAME_WIDTH。但是当我尝试以下操作时出现错误:
>> cap = cv2.VideoCapture('runoff.MOV')
>> print cap.get('CV_CAP_PROP_FRAME_WIDTH')
TypeError: an integer is required
If I input an integer in the code:
如果我在代码中输入一个整数:
>> cap = cv2.VideoCapture('runoff.MOV')
>> print cap.get(3)
1920.0
CV_CAP_PROP_FRAME_WIDTH
is the 4th item in the list in the documentation and indeed when I use the correct integer counter 3
I get this property. I wonder if there is a neater way to do this, making use of the class itself and writing a dictionary for it with all key, integer combinations.
CV_CAP_PROP_FRAME_WIDTH是文档列表中的第4项,实际上当我使用正确的整数计数器3时,我得到了这个属性。我想知道是否有更简洁的方法来实现这一点,利用类本身并使用所有键,整数组合为它编写字典。
3 个解决方案