简体   繁体   English

OpenCV-Python cv2.CV_CAP_PROP_POS_FRAMES 错误

[英]OpenCV-Python cv2.CV_CAP_PROP_POS_FRAMES error

Currently, I am using opencv 3.1.0, and I encountered the following error when executing the following code:目前我使用的是opencv 3.1.0,在执行以下代码时遇到如下错误:

post_frame = cap.get(cv2.CV_CAP_PROP_POS_FRAMES)

I got the following error Message:我收到以下错误消息:

File "videoOperation.py", line 37, in pos_frame = cap.get(cv2.CV_CAP_PROP_POS_FRAMES) AttributeError: 'module' object has no attribute 'CV_CAP_PROP_POS_FRAMES'文件“videoOperation.py”,第 37 行,在 pos_frame = cap.get(cv2.CV_CAP_PROP_POS_FRAMES) AttributeError: 'module' object has no attribute 'CV_CAP_PROP_POS_FRAMES'

The code should be written in the following format when using OpenCV 2.x:使用 OpenCV 2.x 时,代码应按以下格式编写:

post_frame = cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)

From opencv 3.0.0-dev python bindings not working properly , I know thatopencv 3.0.0-dev python 绑定不能正常工作,我知道

the cv2.cv submodule got removed in opencv3.0, also some constants were changed在 opencv3.0 中删除了 cv2.cv 子模块,也更改了一些常量

But the cv2.CV_CAP_PROP_POS_FRAMES didn't work for me, So what am I supposed to do?但是 cv2.CV_CAP_PROP_POS_FRAMES 对我不起作用,那我该怎么办?

你正在寻找这个:

post_frame = cap.get(cv2.CAP_PROP_POS_FRAMES)

Try typing this instead:尝试输入以下内容:

post_frame = cap.get(1) #CAP_PROP_POS_FRAMES = 1

If you type help('cv2') in the Python shell, you will find some modifications to the syntax.如果您在 Python shell 中键入help('cv2') ,您会发现对语法进行了一些修改。

output truncated

...
CAP_PROP_PAN = 33
CAP_PROP_POS_AVI_RATIO = 2
CAP_PROP_POS_FRAMES = 1
CAP_PROP_POS_MSEC = 0
CAP_PROP_PVAPI_BINNINGX = 304
CAP_PROP_PVAPI_BINNINGY = 305
CAP_PROP_PVAPI_DECIMATIONHORIZONTAL = 302
...

Should search for CV_CAP_PROP_POS_FRAMES in /usr/include/opencv2 or /usr/local/include etc. ,whichever is in your makefile include path .应该在 /usr/include/opencv2 或 /usr/local/include 等中搜索 CV_CAP_PROP_POS_FRAMES ,以您的 makefile 包含路径中的为准。 It would be in videoio/videoio_c.h or /videoio/legacy/constants_c.h .它将在 videoio/videoio_c.h 或 /videoio/legacy/constants_c.h 中。 Use this in your include path #include .在您的包含路径 #include 中使用它。 This is the right way .这是正确的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM