Skip to content

Instantly share code, notes, and snippets.

@Ayke
Last active December 22, 2020 00:00
Show Gist options
  • Save Ayke/283a29c7b12bdaadb55dfa779bcf2882 to your computer and use it in GitHub Desktop.
Save Ayke/283a29c7b12bdaadb55dfa779bcf2882 to your computer and use it in GitHub Desktop.
Configure YOLO Detection on TX2

First I assumed that you have already downloaded YOLO to /home/nvidia/darknet where nvidia is the host name.

YOLO installation

mavx options unavailable

CC: error: unrecognized command line option ‘-mavx’
CC: error: unrecognized command line option ‘-mavx2’
CC: error: unrecognized command line option ‘-msse3’
CC: error: unrecognized command line option ‘-msse4.1’
CC: error: unrecognized command line option ‘-msse4.2’
CC: error: unrecognized command line option ‘-msse4a’

Go into the cmakelist.txt, just remove the two lines involved with mavx etc., as they're x86 options and not available on tx2. The detection works fine for me.

YOLO Detection

Just like it said in YOLO website,

./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights

will run a real-time YOLO detection. However if we want to make use of the built-in camera on TX2 board, this command doesn't work.

Use built-in camera on TX2

To make use of the built-in camera, a sample OpenCV python program is:

import cv2 as cv

gst_str = 'nvarguscamerasrc ! video/x-raw(memory:NVMM), ' + 
          'width=(int)1920, height=(int)1080, ' +
          'format=(string)NV12, framerate=(fraction)30/1 ! ' +
          'nvvidconv flip-method=2 ! ' +
          'video/x-raw, format=(string)BGRx ! ' +
          'videoconvert ! appsink'
cap = cv.VideoCapture(gst_str, cv.CAP_GSTREAMER)

_, img = cap.read()
cv.imshow('foo', img)
cv.waitKey(0)

Similarly, we can run gst-launch-1.0 to preview the camera: gst-launch-1.0 nvarguscamerasrc ! "video/x-raw(memory:NVMM)" ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! omxh265enc ! matroskamux ! appsink

To run darknet with built-in camera, the command is:

./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv flip-method=0 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment