Hi @dusty_nv !
Is it possible to use cv2 to creation my own Python script for realtime object detection on a live camera?
I tryied this:
import jetson_inference
import jetson_utils
import cv2
net = jetson_inference.detectNet(argv=[‘–model=/home/jv/jetson-inference/python/training/detection/ssd/models/04obj/ssd-mobilenet.onnx’, ‘–labels=/home/jv/jetson-inference/python/training/detection/ssd/models/04obj/labels.txt’, ‘–input-blob=input_0’, ‘–output-cvg=scores’, ‘–output-bbox=boxes’], threshold=0.5)
camera = cv2.VideoCapture(0)
display = jetson_utils.glDisplay()
while display.IsOpen():
_, img = camera.read()
detections = net.Detect(img)
for detection in detections:
class_id = detection.ClassID
class_name = net.GetClassDesc(class_id)
confidence = detection.Confidence
left = int(detection.Left)
top = int(detection.Top)
right = int(detection.Right)
bottom = int(detection.Bottom)
if confidence > 0.5:
cv2.rectangle(img, (left, top), (right, bottom), (0, 255, 0), 2)
cv2.putText(img, class_name, (left + 5, top + 20), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)
display.RenderOnce(img, img.shape[1], img.shape[0])
display.SetStatus("Object Detection | Network {:.0f} FPS".format(net.GetNetworkFPS()))
But I received this:
[TRT] didn’t load expected number of class colors (0 of 6)
[TRT] filling in remaining 6 class colors with default colors
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (933) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
[OpenGL] glDisplay – X screen 0 resolution: 1920x1080
[OpenGL] glDisplay – X window resolution: 1920x1080
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
X Error of failed request: GLXBadContext
Major opcode of failed request: 154 (GLX)
Minor opcode of failed request: 6 (X_GLXIsDirect)
Serial number of failed request: 43
Current serial number in output stream: 42