Skip to content

Commit 629f256

Browse files
committed
Illegal instruction on Jetson Nano, don't show camera if no display connected
1 parent 11628bf commit 629f256

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

examples/image/classify-full-frame.py

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

3+
import device_patches # Device specific patches for Jetson Nano (needs to be before importing cv2)
4+
35
import cv2
46
import os
57
import sys, getopt
@@ -8,7 +10,6 @@
810
from edge_impulse_linux.image import ImageImpulseRunner
911

1012
runner = None
11-
show_camera = False
1213

1314
def now():
1415
return round(time.time() * 1000)

examples/image/classify-image.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python
22

3+
import device_patches # Device specific patches for Jetson Nano (needs to be before importing cv2)
4+
35
import cv2
46
import os
57
import sys, getopt

examples/image/classify.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python
22

3+
import device_patches # Device specific patches for Jetson Nano (needs to be before importing cv2)
4+
35
import cv2
46
import os
57
import sys, getopt
@@ -8,7 +10,10 @@
810
from edge_impulse_linux.image import ImageImpulseRunner
911

1012
runner = None
13+
# if you don't want to see a camera preview, set this to False
1114
show_camera = True
15+
if (sys.platform == 'linux' and not os.environ.get('DISPLAY')):
16+
show_camera = False
1217

1318
def now():
1419
return round(time.time() * 1000)

examples/image/device_patches.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
3+
def get_device():
4+
# On Jetson Nano `OPENBLAS_CORETYPE=ARMV8` needs to be set, otherwise including OpenCV
5+
# throws an illegal instruction error
6+
if (os.path.exists('/proc/device-tree/model')):
7+
with open('/proc/device-tree/model', 'r') as f:
8+
model = f.read()
9+
if ('NVIDIA Jetson Nano' in model):
10+
return 'jetson-nano'
11+
return 'unknown'
12+
13+
device = get_device()
14+
if (device == 'jetson-nano'):
15+
os.environ['OPENBLAS_CORETYPE'] = 'ARMV8'

0 commit comments

Comments
 (0)