OpenCV-Python cv2.CV_CAP_PROP_POS_FRAMES error

2024/10/13 21:10:54

Currently, I am using opencv 3.1.0, and I encountered the following error when executing the following code:

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'

The code should be written in the following format when using 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 that

the cv2.cv submodule got removed in opencv3.0, also some constants were changed

But the cv2.CV_CAP_PROP_POS_FRAMES didn't work for me, So what am I supposed to do?

Answer

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.

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
...
https://en.xdnf.cn/q/69488.html

Related Q&A

How to get the total number of tests passed, failed and skipped from pytest

How can I get to the statistics information of a test session in pytest?Ive tried to define pytest_sessionfinish in the conftest.py file, but I only see testsfailed and testscollected attributes on th…

Tensorflow ArgumentError Running CIFAR-10 example

I am trying to run the CIFAR-10 example of Tensorflow. However when executing python cifar10.py I am getting the error attached below. I have installed Version 0.6.0 of the Tensorflow package using pip…

How to plot multiple density plots on the same figure in python

I know this is going to end up being a really messy plot, but I am curious to know what the most efficient way to do this is. I have some data that looks like this in a csv file:ROI Band Min…

Running Tkinter on Mac

I am an absolute newbie. Im trying to make Python GUI for my school project so I decided to use Tkinter. When I try to import Tkinter it throws this message: >>> import tkinter Traceback (most…

Object-based default value in SQLAlchemy declarative

With SQLAlchemy, it is possible to add a default value to every function. As I understand it, this may also be a callable (either without any arguments or with an optional ExecutionContext argument).No…

High Resolution Image of a Graph using NetworkX and Matplotlib

I have a python code to generate a random graph of 300 nodes and 200 edges and display itimport networkx as nx import matplotlib.pyplot as pltG = nx.gnm_random_graph(300,200) graph_pos = nx.spring_layo…

how to read an outputted fortran binary NxNxN matrix into Python

I wrote out a matrix in Fortran as follows:real(kind=kind(0.0d0)), dimension(256,256,256) :: dense[...CALCULATION...]inquire(iolength=reclen)dense open(unit=8,file=fname,& form=unformatted,access=d…

python argparse subcommand with dependency and conflict

I want to use argparse to build a tool with subcommand. The possible syntax could be/tool.py download --from 1234 --interval 60 /tool.py download --build 1432 /tool.py clean --numbers 10So I want to us…

Running django project without django installation

I have developed a project with Django framework(python and mysql DB) in Linux OS(Ubuntu 12.04), I want to run this project in localhost in another machine with Linux(Ubuntu 12.04) without installing D…

redefine __and__ operator

Why I cant redefine the __and__ operator?class Cut(object):def __init__(self, cut):self.cut = cutdef __and__(self, other):return Cut("(" + self.cut + ") && (" + other.cut +…