NVIDIA Jetson Nano學習筆記(六):即時影像偵測系統(PiCamera+OpenCV+TensorFlow Lite)

本文章假設讀者已完成TF Runtime的安裝,並且已經自行裝上Pi Camera、設定好Firebase的RealTime Database及Storage。

(1)尚未安裝TF Runtime的讀者可以參考:
NVIDIA Jetson Nano學習筆記(四):安裝與執行Tensorflow Lite Model官方範例

(2)尚未設定好Firebase的RealTime Database及Storage的讀者可以參考:

Learning Firebase(1):Create Your First Project
Learning Firebase(2):CRUD Our Database with Python
Learning Firebase(3):Upload Image to Firebase with Python

NVIDIA Jetson Nano學習筆記(五):即時影像分類系統(PiCamera+OpenCV+TensorFlow Lite+Firebase)一文當中,我和大家介紹了如何在Jetson Nano中,透過PiCamera進行即時的Image Classification。本文延續上次的主題,這次做的是Object Detection

程式碼:

程式碼參考自TensorFlow-Lite-Object-Detection-on-Android-and-Raspberry-Pi,我將其改寫成能在Jetson Nano上執行的版本。

最主要的差異在於:

1. 原先的程式遇到了NoneType errors的錯誤,根據OpenCV: Resolving NoneType errors — PyImageSearch,文章表示,該項錯誤造成的主因是:

Case #1: cv2.imread
Case #2: cv2.VideoCapture and .read

2. 透過OpenCV讀取鏡頭的方式,與原本專屬給Raspberry Pi的程式不同,必須透過以下方式才能在Jetson Nano開啟PiCamera。

# 先自定義一個gstreamer_pipeline的function,接著透過 
# cv2.VideoCapture()來讀取

經過上述的兩個步驟,再搭配上程式內些微調整,目前已經可以正常執行Object Detection的動作。效能的部分,在Nano上有4.X的FPS表現,還算堪用。後續若推廣到性能更好的硬體設備,相信會有更好的表現。

參考資料:

Written by

Machine Learning / Deep Learning / Python / Flutter cakeresume.com/yanwei-liu

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store