Closed dtraparic closed 1 month ago
i meet with same problem
Dear @LaurentBerger,
I understood the Python Doc but I honestly don't know what to understand in your quoted paragraph. 😕
What I said is that the code provided inside the OpenCV Doc to modify os environment variable, executed as is, raises an error.
The code that reads a video frame doesn't matter much, and it's embedded through MMCV that uses OpenCV, so I'm not able to provide a OpenCV-code-only example. I know this part works, because as I said, it works once the environment variable modified inside Windows parameters.
Please tell me if you really need an example for reading a video frame but I think it's not necessary, as I guess the problem will occur on the set up of every possible OpenCV environment variable.
os.environ["MY_ENV_VARIABLE"] = True
True is not a string
and now I search in doc and I found reference:
I think you can make a PR to change python code
Example in the documentation is wrong because it doesn't use string. However generally this approach should work:
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ["OPENCV_FOR_THREADS_NUM"] = "3"
>>> import cv2
>>> cv2.getNumThreads()
3
Default value without environment change:
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.getNumThreads()
4
Most probably the same as https://stackoverflow.com/questions/5153547/environment-variables-are-different-for-dll-than-exe. It's not related to OpenCV, but OS specific.
I don't understand : opencv documentation is wrong for python
there is a bug in opencv documentation because if you follow documentation it raises an execption
Describe the doc issue
Hello,
I think this is documentation issue + bug issue
First, when reading a video, this warning occured, giving me a None value instead of a frame :
I wanted to create the environment variable inside my Python file to be machine-independant so I followed the instructions in page OpenCV: OpenCV environment variables reference
When I executed this code in the given page :
It raised this error :
Same error if I give an int instead of a bool. So I tried giving a str instead, to the variable :
This prints me 16000, but I still have the first error provided at the top, saying that current value of OPENCV_FFMPEG_READ_ATTEMPTS is 4096, when reading a particular frame of a particular video.
Now that I have created a system environment variable in Windows, plus restarted my computer, it works.
Do anyone know what the opencv Doc is missing and why setting environment variable inside python file seems impossible ?
(Windows 10, opencv-python 4.9.0.80, Python 3.9.12, openCV doc tried on version 4.10.0 and 4.9.0)
Fix suggestion
No response