确定哪个版本的OpenCV

时间:2012-04-20 15:13:43

标签: python opencv

我想写一下python中的短代码片段,以确定我的系统中安装了哪个版本的OpenCV。我该怎么做 ? 谢谢。

4 个答案:

答案 0 :(得分:24)

>>> from cv2 import __version__
>>> __version__
'$Rev: 4557 $'

如果不起作用,请使用cv代替cv2

答案 1 :(得分:3)

一种方式可以如下: -

enter image description here

答案 2 :(得分:0)

方便的功能可在运行时检查OpenCV版本

def cv2():
    return opencv_version("2")

def cv3():
    return opencv_version("3")

def cv4():
    return opencv_version("4")

def opencv_version(version):
    import cv2
    return cv2.__version__.startswith(version)

在执行cv2.findContours()时很有用,因为返回签名因版本而异

# Using OpenCV 2.X or OpenCV 4
if cv2() or cv4():
    cnts, _ = cv2.findContours(image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

# Using OpenCV 3
elif cv3():
    _, cnts, _ = cv2.findContours(image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

答案 3 :(得分:0)

在终端中写:

  • 对于python 2.X EventBusContext
  • 对于python 3.X Collecting main Using cached https://files.pythonhosted.org/packages/1c/f4/445fbd86d9ebd133a03a263482f72dd539ccc90a0c29693222903e5e145e/main-0.1.tar.gz Installing collected packages: main Running setup.py install for main ... error ERROR: Command errored out with exit status 1: command: 'C:\Python 3.8.1\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\asuit\\AppData\\Local\\Temp\\pip-install-9tqrshss\\main\\setup.py'"'"'; __file__='"'"'C:\\Users\\asuit\\AppData\\Local\\Temp\\pip-install-9tqrshss\\main\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\asuit\AppData\Local\Temp\pip-record-oc5gc9jc\install-record.txt' --single-version-externally-managed --compile --user --prefix= cwd: C:\Users\asuit\AppData\Local\Temp\pip-install-9tqrshss\main\ Complete output (6 lines): running install running build running build_scripts creating build creating build\scripts-3.8 error: file 'C:\Users\asuit\AppData\Local\Temp\pip-install-9tqrshss\main\main' does not exist ---------------------------------------- ERROR: Command errored out with exit status 1: 'C:\Python 3.8.1\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\asuit\\AppData\\Local\\Temp\\pip-install-9tqrshss\\main\\setup.py'"'"'; __file__='"'"'C:\\Users\\asuit\\AppData\\Local\\Temp\\pip-install-9tqrshss\\main\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\asuit\AppData\Local\Temp\pip-record-oc5gc9jc\install-record.txt' --single-version-externally-managed --compile --user --prefix= Check the logs for full command output.