-
Notifications
You must be signed in to change notification settings - Fork 11
/
version.py
132 lines (104 loc) · 4.58 KB
/
version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#####################################################################
# Example : test if opencv environment is working
# Author : Toby Breckon, [email protected]
# Copyright (c) 2017-2022 Toby Breckon, Durham University, UK
# License : LGPL - http://www.gnu.org/licenses/lgpl.html
#####################################################################
import cv2
import numpy as np
import sys
import re
import struct
import matplotlib
#####################################################################
# check if the OpenCV we are using has the extra modules available
def extra_opencv_modules_present():
(is_built, not_built) = cv2.getBuildInformation().split("Disabled:")
return ('xfeatures2d' in is_built)
def non_free_opencv_algorithms_present():
(before, after) = cv2.getBuildInformation().split("Non-free algorithms:")
output_list = after.split("\n")
return ('YES' in output_list[0])
#####################################################################
print()
print("We are using OpenCV: " + cv2.__version__)
print(".. do we have the OpenCV Contrib Modules: " +
str(extra_opencv_modules_present()))
try:
print(".. do we have the OpenCV Non-free algorithms: " +
str(non_free_opencv_algorithms_present()))
except BaseException:
print(".. OpenCV version pre-dates (or does not have) " +
"non-free algorithms module")
try:
print(".. do we have the Intel Performance Primitives (IPP): \n" +
".. version: " + str(cv2.ipp.getIppVersion()) + " (in use: "
+ str(cv2.ipp.useIPP()) + " )")
except BaseException:
print(".. OpenCV version does not have " +
"Intel Performance Primitives (IPP)")
print("We are using numpy: " + np.__version__)
print("We are using matplotlib: " + matplotlib.__version__)
print(".. and this is in Python: " + sys.version +
" (" + str(struct.calcsize("P") * 8) + " bit)")
#####################################################################
print()
print("Check Video I/O (OS identifier: " + sys.platform + ")")
print("... available camera backends: ", end='')
for backend in cv2.videoio_registry.getCameraBackends():
print(" " + cv2.videoio_registry.getBackendName(backend), end='')
print()
print("... available stream backends: ", end='')
for backend in cv2.videoio_registry.getStreamBackends():
print(" " + cv2.videoio_registry.getBackendName(backend), end='')
print()
print("... available video writer backends: ", end='')
for backend in cv2.videoio_registry.getWriterBackends():
print(" " + cv2.videoio_registry.getBackendName(backend), end='')
print()
print()
#####################################################################
# credit to: https://tinyurl.com/y529vzc3
print("Available Cuda Information: ")
cuda_info = [re.sub('\\s+', ' ', ci.strip()) for ci in
cv2.getBuildInformation().strip().split('\n')
if len(ci) > 0 and re.search(r'(nvidia*:?)|(cuda*:)|(cudnn*:)',
ci.lower()) is not None]
print("... " + str(cuda_info))
print()
#####################################################################
for gpu in range(cv2.cuda.getCudaEnabledDeviceCount()):
print("CUDA enabled GPU device index: " + str(gpu) + " ")
cv2.cuda.printShortCudaDeviceInfo(gpu)
print()
#####################################################################
print("DNN module CUDA backend/target availability : ", end='')
try:
targets = cv2.dnn.getAvailableTargets(cv2.dnn.DNN_BACKEND_CUDA)
print()
print("... DNN_TARGET_CUDA: \t\t", end='')
print(cv2.dnn.DNN_TARGET_CUDA in targets)
print("... DNN_TARGET_CUDA_FP16: \t", end='')
print(cv2.dnn.DNN_TARGET_CUDA_FP16 in targets)
targets = cv2.dnn.getAvailableTargets(cv2.dnn.DNN_BACKEND_DEFAULT)
print("... DNN_TARGET_CPU: \t\t", end='')
print(cv2.dnn.DNN_TARGET_CPU in targets)
print("... DNN_TARGET_OPENCL: \t\t", end='')
print(cv2.dnn.DNN_TARGET_OPENCL in targets)
print("... DNN_TARGET_OPENCL_FP16: \t", end='')
print(cv2.dnn.DNN_TARGET_OPENCL_FP16 in targets)
except BaseException:
print("False")
#####################################################################
print()
print("OpenCL available (within OpenCV) ? : " + str(cv2.ocl.haveOpenCL()))
print()
#####################################################################
print("Available CPU Optimizations (*: build enabled; ?: not CPU supported):")
try:
print("... " + cv2.getCPUFeaturesLine())
print()
except BaseException:
print("... [ CPU feature check not available in this version ]")
print()
#####################################################################