Skip to content

Commit aa21757

Browse files
author
--replace-all
committed
Updated python installation test
1 parent d575d4a commit aa21757

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
CMakeLists.txt.user
22
.clang-format
33
build/
4+
.idea/

tests/cpp_opencv_test/main.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ check_build_info( )
3838

3939
std::cout << "Cpu NEON support: " << cv::checkHardwareSupport( CV_CPU_NEON ) << std::endl;
4040
if ( cv::checkHardwareSupport( CV_CPU_NEON ) == 0 ) {
41-
std::cout << "ERROR: TBB is not enabled." << std::endl;
41+
std::cout << "ERROR: NEON is not enabled." << std::endl;
4242
error_found = true;
4343
}
4444

@@ -48,18 +48,17 @@ check_build_info( )
4848
int
4949
main( )
5050
{
51-
bool build_version_ok = check_build_info( );
52-
if ( build_version_ok ) {
51+
if ( !check_build_info( ) ) {
5352
std::cout << "SUCCESS: You are using latest OpenCV version, with NEON/TBB support enabled." << std::endl;
5453
} else {
5554
std::cout << "FAIL: You are using OpenCV without NEON/TBB support enabled." << std::endl;
56-
return -1;
55+
return 1;
5756
}
5857

5958
auto image = cv::imread( IMAGE );
6059
if ( !image.data ) {
6160
std::cout << "ERROR: Could not open or find the image" << std::endl;
62-
return -1;
61+
return 1;
6362
}
6463

6564
cv::Mat gray_image, thresholded_image;

tests/python_opencv_test/test.py

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,55 @@
44

55
from __future__ import print_function
66
import cv2
7+
import sys
78

8-
print("OpenCV Version: {}".format(cv2.__version__))
9-
image = cv2.imread("tetris_blocks.png")
10-
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
11-
thresh = cv2.threshold(gray, 225, 255, cv2.THRESH_BINARY_INV)[1]
9+
CURRENT_OPENCV_BUILD_VERSION = [4, 1, 0]
1210

13-
(cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
1411

15-
# draw the contours on the image
16-
cv2.drawContours(image, cnts, -1, (240, 0, 159), 3)
17-
cv2.imshow("Image", image)
18-
cv2.waitKey(0)
12+
def check_build_info():
13+
success = True
14+
15+
print("OpenCV Version:")
16+
if (cv2.getVersionMajor() != CURRENT_OPENCV_BUILD_VERSION[0]) and (
17+
cv2.getVersionMinor() != CURRENT_OPENCV_BUILD_VERSION[1]) and (
18+
cv2.getVersionRevision() != CURRENT_OPENCV_BUILD_VERSION[2]):
19+
print("ERROR: OpenCV version is different than the expected.")
20+
success = False
21+
22+
print("Available CPUs: ", cv2.getNumberOfCPUs())
23+
print("Available threads: ", cv2.getNumThreads())
24+
if cv2.getNumThreads() < cv2.getNumberOfCPUs():
25+
print("ERROR: TBB is not enabled.")
26+
success = False
27+
28+
cv2.CPU_NEON = 100 # Value taken from OpenCV doc. CPU labels don't work correctly in Python
29+
print("Cpu NEON support: ", cv2.checkHardwareSupport(cv2.CPU_NEON))
30+
if not cv2.checkHardwareSupport(cv2.CPU_NEON):
31+
print("ERROR: NEON is not enabled.")
32+
success = False
33+
34+
return success
35+
36+
37+
def main():
38+
if not check_build_info():
39+
print("FAIL: You are using OpenCV without NEON/TBB support enabled.")
40+
sys.exit(1)
41+
print("SUCCESS: You are using latest OpenCV version, with NEON/TBB support enabled.")
42+
43+
image = cv2.imread("tetris_blocks.png")
44+
if not image.data:
45+
print("ERROR: Could not open or find the image")
46+
sys.exit(1)
47+
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
48+
threshold = cv2.threshold(gray_image, 225, 255, cv2.THRESH_BINARY_INV)[1]
49+
(contours, _) = cv2.findContours(threshold.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
50+
51+
# draw the contours on the image
52+
cv2.drawContours(image, contours, -1, (240, 0, 159), 3)
53+
cv2.imshow("Image", image)
54+
cv2.waitKey(0)
55+
56+
57+
if __name__ == '__main__':
58+
main()

0 commit comments

Comments
 (0)