|
4 | 4 |
|
5 | 5 | from __future__ import print_function
|
6 | 6 | import cv2
|
| 7 | +import sys |
7 | 8 |
|
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] |
12 | 10 |
|
13 |
| -(cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) |
14 | 11 |
|
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