Coding Your Own Object Detection Program

import jetson.inference

import jetson.utils

#上面兩行是基本要匯入的

#下面這行是做載入模型的動作

net = jetson.inference.detectNet("ssd-mobilenet-v2", threshold=0.5)

#detectNet模型選用ssd-mobilenet-v2,且threshold=0.5

#下面這行做的是開啟視訊串流

#camera = jetson.utils.videoSource("csi://0")      # '/dev/video0' for V4L2

#像我自己的是羅技的鏡頭,所以我要改成下面那行

camera = jetson.utils.videoSource("/dev/video0") 

#下面兩行為顯示迴圈

display = jetson.utils.videoOutput("display://0") # 'my_video.mp4' for file

#設定將輸出到螢幕或儲存成檔案

#下面基本上語法都相同

while display.IsStreaming():

#以下做視訊影響擷取

img = camera.Capture()

#將偵測到的物體回傳為一個清單

detections = net.Detect(img)

#渲染 Finally we'll visualize the results with OpenGL and update the title of the window to display the current peformance 

display.Render(img)

#The Render() function will automatically flip the backbuffer and present the image on-screen. 

      display.SetStatus("Object Detection | Network {:.0f} FPS".format(net.GetNetworkFPS()))