Last active
April 19, 2022 04:30
-
-
Save KeitetsuWorks/7ecea8c1447a4e5f5519994b783eb289 to your computer and use it in GitHub Desktop.
Sample Codes for NVIDIA L4T ML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
## | |
## @file opencv_csi-camera.py | |
## @brief Display the image captured by the CSI camera | |
## @author Keitetsu | |
## @date 2022/01/15 | |
## @copyright Copyright (c) 2022 Keitetsu | |
## @par License | |
## This software is released under the MIT License. | |
## | |
import cv2 | |
GST_STR = "nvarguscamerasrc sensor-id=0 ! \ | |
video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)30/1 ! \ | |
nvvidconv ! \ | |
video/x-raw, width=(int)1920, height=(int)1080, format=(string)BGRx ! \ | |
videoconvert ! \ | |
appsink max-buffers=1 drop=true" | |
if __name__ == "__main__": | |
capture = cv2.VideoCapture(GST_STR, cv2.CAP_GSTREAMER) | |
if capture.isOpened() is False: | |
raise IOError("Failed to open camera device.") | |
while True: | |
retVal, frame = capture.read() | |
if retVal == False: | |
continue | |
cv2.imshow("camera", frame) | |
key = cv2.waitKey(1) | |
if key == 27: # ESC Key | |
break | |
capture.release() | |
cv2.destroyAllWindows() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
## | |
## @file opencv_face-detection_csi-camera.py | |
## @brief Face Detection | |
## @author Keitetsu | |
## @date 2022/01/16 | |
## @copyright Copyright (c) 2022 Keitetsu | |
## @par License | |
## This software is released under the MIT License. | |
## | |
import cv2 | |
GST_STR = "nvarguscamerasrc sensor-id=0 ! \ | |
video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)30/1 ! \ | |
nvvidconv ! \ | |
video/x-raw, width=(int)1920, height=(int)1080, format=(string)BGRx ! \ | |
videoconvert ! \ | |
appsink max-buffers=1 drop=true" | |
cascade_file_path = "/usr/share/opencv4/haarcascades/haarcascade_frontalface_default.xml" | |
if __name__ == "__main__": | |
capture = cv2.VideoCapture(GST_STR, cv2.CAP_GSTREAMER) | |
if capture.isOpened() is False: | |
raise IOError("Failed to open camera device.") | |
cascade = cv2.CascadeClassifier(cascade_file_path) | |
face_rect_line_color = (255, 255, 255) | |
while True: | |
retVal, frame = capture.read() | |
if retVal == False: | |
continue | |
# グレースケールに変換 | |
frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
# 顔検出 | |
faces = cascade.detectMultiScale(frame_gray, scaleFactor=1.1, minNeighbors=3, minSize=(192, 192)) | |
# 顔が1つ以上検出されている場合に矩形を描画 | |
if len(faces) > 0: | |
for (x, y, width, height) in faces: | |
cv2.rectangle(frame, (x, y), (x + width, y + height), face_rect_line_color, thickness=2) | |
cv2.imshow("camera", frame) | |
key = cv2.waitKey(1) | |
if key == 27: # ESC Key | |
break | |
capture.release() | |
cv2.destroyAllWindows() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
xhost + | |
sudo docker run \ | |
-it \ | |
--rm \ | |
--net=host \ | |
--runtime nvidia \ | |
-e DISPLAY=$DISPLAY \ | |
-v /tmp/.X11-unix/:/tmp/.X11-unix \ | |
-v ${PWD}:/data \ | |
nvcr.io/nvidia/l4t-ml:r32.6.1-py3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
xhost + | |
sudo docker run \ | |
-it \ | |
--rm \ | |
--net=host \ | |
--runtime nvidia \ | |
-e DISPLAY=$DISPLAY \ | |
-v /tmp/.X11-unix/:/tmp/.X11-unix \ | |
-v /tmp/argus_socket:/tmp/argus_socket \ | |
-v ${PWD}:/data \ | |
nvcr.io/nvidia/l4t-ml:r32.6.1-py3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment