Object Detection with SSD-Mobilenet-v2

Hello everyone,
I have problem when i try to build the object detection stack it not working i saw some errors but i don’t know why ?

warning:  importing jetson.utils is deprecated.  please 'import jetson_utils' instead.
warning:  importing jetson.inference is deprecated.  please 'import jetson_inference' instead.
jetson.inference -- detectNet loading build-in network 'ssd-mobilenet-v2'
[TRT]    Could not register plugin creator -  ::FlattenConcat_TRT version 1
[TRT]    didn't load expected number of class colors  (0 of 91)
[TRT]    filling in remaining 91 class colors with default colors

my hardware configuration:
-PI camera V2.1

  • jetson nano
  • Power

my software configuration:
CV2 4.6.0 V
GStreamer Core Library version 1.14.5

this is the code,

import jetson.inference
import jetson.utils
import cv2

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

def gstreamer_pipeline(
    return (
        "nvarguscamerasrc ! "
        "video/x-raw(memory:NVMM), "
        "width=(int)%d, height=(int)%d, framerate=(fraction)%d/1 ! "
        "nvvidconv flip-method=%d ! "
        "video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! "
        "videoconvert ! "
        "video/x-raw, format=(string)BGR ! appsink drop=True"
        % (
# process csi camera
video_file = cv2.VideoCapture(gstreamer_pipeline(), cv2.CAP_GSTREAMER)

if video_file.isOpened():
    cv2.namedWindow("Detection result", cv2.WINDOW_AUTOSIZE)

    print('CSI stream opened. Press ESC or Ctrl + c to stop application')

    while cv2.getWindowProperty("Detection result", 0) >= 0:
        ret, frame = video_file.read()

        # convert and detect
        imgCuda = jetson.utils.cudaFromNumpy(frame)
        detections = net.Detect(imgCuda)

        # draw rectangle and description
        for d in detections:
            x1, y1, x2, y2 = int(d.Left), int(d.Top), int(d.Right), int(d.Bottom)
            className = net.GetClassDesc(d.ClassID)
            cv2.rectangle(frame, (x1,y1), (x2, y2), (0, 0, 0), 2)
            cv2.putText(frame, className, (x1+5, y1+15), cv2.FONT_HERSHEY_DUPLEX, 0.75, (0, 0, 0), 2)

        # show frame
        cv2.imshow("Detection result", frame)

        # stop via ESC key
        keyCode = cv2.waitKey(30) & 0xFF
        if keyCode == 27 or not ret:

    # close
    print('unable to open csi stream')```

Hi @ahmad.elwaly, these are just warnings that you can ignore. Can you describe the issue that you are having with your program? For debugging purposes, are you able to run detectnet.py csi://0 and view detections from that okay?

Hello thanks for your prompt response.

detectnet.py csi://0 it’s working fine without any problem.

the problem with my code that the camera it’s not even opening. as you can see i have if video_file.isOpened(): If the condition is met the camera will work but as i can see the condition doesnt execute and the else condition is execute

    print('unable to open csi stream')

so i want to know why the condition isn’t met from your point of view.


Hi Ahmad, without seeing any errors or exceptions thrown by the OpenCV code, it’s hard to say. I would recommend opening a new topic specifically about that cv2.VideoCapture() issue you are having so that you can resolve that first.

Thanks for you prompt response.
I found the error but i dont know the reason.
when i run it with python it’s working but when i run it with python3 it’s not working.
but i don’t see any function interfere between python 3.
Could you help me to understand why this happen

@ahmad.elwaly can you run python3 -c 'import cv2; print(cv2.getBuildInformation())' and check that GStreamer is enabled in the build? If not, maybe another OpenCV got installed that was not the OpenCV that came with JetPack (which has GStreamer enabled)

Yes it look like this is the problem, because the GStreamer it’s not enable , How I can Solve This ?

You could either re-install the nvidia-opencv package from apt (the version of OpenCV that comes with JetPack has GStreamer enabled), or build it from source like here: GitHub - mdegans/nano_build_opencv: Build OpenCV on Nvidia Jetson Nano

still not working same issue , but i notice that when i check wth jtop comand the opencv adn gstreamer is enabled. but when i run python3 -c 'import cv2; print(cv2.getBuildInformation())' it’s shown that it’s not enable

It seems that your cv2 module installed under Python3 wasn’t built with GStreamer enabled, but the one under Python2 may be (and perhaps the Python3 one got upgraded at some point to a non-GStreamer build). So make sure that you are installing the one for Python3.

Alternatively, you could just use videoSource object from jetson-utils to capture your MIPI CSI camera like shown in the examples.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.