Skip to content

Commit 66ad003

Browse files
cv2 import error bugfix (#16)
Co-authored-by: AIWintermuteAI <32562299+AIWintermuteAI@users.noreply.github.com>
1 parent 2f69d12 commit 66ad003

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

edge_impulse_linux/image.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
#!/usr/bin/env python
22

33
import numpy as np
4-
import cv2
4+
opencv_installed = True
5+
6+
try:
7+
import cv2
8+
except ModuleNotFoundError as e: # can alternatively drop the boolean check for NameError exception when cv2 is called
9+
opencv_installed = False
10+
11+
512
from edge_impulse_linux.runner import ImpulseRunner
613
import math
714
import psutil
815

916
class ImageImpulseRunner(ImpulseRunner):
1017
def __init__(self, model_path: str):
18+
if not opencv_installed: # can alternatively drop the boolean check for NameError exception when cv2 is called
19+
raise Exception("OpenCV Not found. To use ImageImpulseRunner, ensure opencv-python>=4.5.1.48 is installed.")
20+
1121
super(ImageImpulseRunner, self).__init__(model_path)
1222
self.closed = True
1323
self.labels = []

0 commit comments

Comments
 (0)