Unable to get detection result or draw line on test app 2 with CSI camera

Hi,
I am using DS test2 python application. I was able to draw line and detection on .h264 input video but when I update code for CSI camera i am able to open camera but not getting detection result or draw line. please help.

main function is:

def main(args):
    # Check input arguments
    # if len(args) != 2:
    #     sys.stderr.write("usage: %s <media file or uri>\n" % args[0])
    #     sys.exit(1)

    # Standard GStreamer initialization
    GObject.threads_init()
    Gst.init(None)

    # Create gstreamer elements
    # Create Pipeline element that will form a connection of other elements
    print("Creating Pipeline \n ")
    pipeline = Gst.Pipeline()

    if not pipeline:
        sys.stderr.write(" Unable to create Pipeline \n")

    # Source element for reading from the file
    print("Creating Source \n ")
    source = Gst.ElementFactory.make("nvarguscamerasrc", "src_elem")
    if not source:
        sys.stderr.write(" Unable to create Source \n")

    caps_picamsrc = Gst.ElementFactory.make("capsfilter", "src_cap_filter")
    if not caps_picamsrc:
        sys.stderr.write(" Unable to create picamsrc capsfilter \n")


    # Video convertor
    print("Creating Video Converter \n")
    nvvidconv1 = Gst.ElementFactory.make("nvvidconv", "convertor1")
    if not nvvidconv1:
        sys.stderr.write(" Unable to create Nvvideoconvert \n")
    
    caps_nvvidconv1 = Gst.ElementFactory.make("capsfilter", "nvmm_caps")
    if not caps_nvvidconv1:
        sys.stderr.write(" Unable to create capsfilter \n")

    # Create nvstreammux instance to form batches from one or more sources.
    streammux = Gst.ElementFactory.make("nvstreammux", "Stream-muxer")
    if not streammux:
        sys.stderr.write(" Unable to create NvStreamMux \n")

    # Use nvinfer to run inferencing on decoder's output,
    # behaviour of inferencing is set through config file
    pgie = Gst.ElementFactory.make("nvinfer", "primary-inference")
    if not pgie:
        sys.stderr.write(" Unable to create pgie \n")

    # Use convertor to convert from NV12 to RGBA as required by nvosd
    nvvidconv2 = Gst.ElementFactory.make("nvvidconv", "converto2r")
    if not nvvidconv2:
        sys.stderr.write(" Unable to create nvvidconv \n")

    tracker = Gst.ElementFactory.make("nvtracker", "tracker")
    if not tracker:
        sys.stderr.write(" Unable to create tracker \n")

    # Create OSD to draw on the converted RGBA buffer
    nvosd = Gst.ElementFactory.make("nvdsosd", "onscreendisplay")

    if not nvosd:
        sys.stderr.write(" Unable to create nvosd \n")

    # Finally render the osd output
    if is_aarch64():
        transform = Gst.ElementFactory.make("nvegltransform", "nvegl-transform")


    print("Creating EGLSink \n")
    sink = Gst.ElementFactory.make("nveglglessink", "sink_sub_bin_sink1")
    if not sink:
        sys.stderr.write(" Unable to create egl sink \n")

    caps_picamsrc.set_property('caps', Gst.Caps.from_string('video/x-raw(memory:NVMM), width=1280, height=720, framerate=21/1, format=NV12,flip-method=2'))
    caps_nvvidconv1.set_property('caps', Gst.Caps.from_string('video/x-raw,width=1280, height=720'))



    #print("Playing file %s " %args[1])
    #source.set_property('location', args[1])
    streammux.set_property('width', 1280)
    streammux.set_property('height', 720)
    streammux.set_property('batch-size', 1)
    streammux.set_property('batched-push-timeout', 4000000)
    #caps_nvvidconv1.set_property('flip-method', 2)

    #Set properties of pgie and sgie
    pgie.set_property('config-file-path', "Resnet_10_head.txt")

    sink.set_property('sync', False)


    #Set properties of tracker
    config = configparser.ConfigParser()
    config.read('dstest2_tracker_config.txt')
    config.sections()

    for key in config['tracker']:
        if key == 'tracker-width' :
            tracker_width = config.getint('tracker', key)
            tracker.set_property('tracker-width', tracker_width)
        if key == 'tracker-height' :
            tracker_height = config.getint('tracker', key)
            tracker.set_property('tracker-height', tracker_height)
        if key == 'gpu-id' :
            tracker_gpu_id = config.getint('tracker', key)
            tracker.set_property('gpu_id', tracker_gpu_id)
        if key == 'll-lib-file' :
            tracker_ll_lib_file = config.get('tracker', key)
            tracker.set_property('ll-lib-file', tracker_ll_lib_file)
        if key == 'll-config-file' :
            tracker_ll_config_file = config.get('tracker', key)
            tracker.set_property('ll-config-file', tracker_ll_config_file)
        if key == 'enable-batch-process' :
            tracker_enable_batch_process = config.getint('tracker', key)
            tracker.set_property('enable_batch_process', tracker_enable_batch_process)
   

    print("Adding elements to Pipeline \n")
    pipeline.add(source)
    pipeline.add(caps_picamsrc)
    pipeline.add(sink)
    pipeline.add(nvvidconv1)
    pipeline.add(streammux)
    pipeline.add(caps_nvvidconv1)
    pipeline.add(nvvidconv2)
    if is_aarch64():
        pipeline.add(transform)
    pipeline.add(pgie)
    pipeline.add(tracker)    
    pipeline.add(nvosd)
    
    

    # we link the elements together
    # file-source -> h264-parser -> nvh264-decoder ->
    # nvinfer -> nvvidconv -> nvosd -> video-renderer

    #  gst-launch-1.0 nvarguscamerasrc ! 
    # 'video/x-raw(memory:NVMM),width=3820, height=2464, framerate=21/1, format=NV12' 
    # ! nvvidconv flip-method=2 ! 'video/x-raw,width=960, height=616' ! nvvidconv ! nvegltransform ! nveglglessink -e

    print("Linking elements in the Pipeline \n")
    source.link(caps_picamsrc)
    caps_picamsrc.link(nvvidconv1)
    nvvidconv1.link(caps_nvvidconv1)
    caps_nvvidconv1.link(nvvidconv2)
    if is_aarch64():
        nvvidconv2.link(transform)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
        transform.link(sink)
    else:    
         nvvidconv2.link(sink)

    sinkpad = streammux.get_request_pad("sink_0")
    srcpad = caps_nvvidconv1.get_static_pad("src")
    srcpad.link(sinkpad)
    streammux.link(pgie)
    pgie.link(tracker)

    #tracker.link(nvvidconv2)
    tracker.link(nvosd)
    if is_aarch64():
        nvosd.link(transform)
        transform.link(sink)
    else:
        nvosd.link(sink)


    # create and event loop and feed gstreamer bus mesages to it
    loop = GObject.MainLoop()

    bus = pipeline.get_bus()
    bus.add_signal_watch()
    bus.connect ("message", bus_call, loop)

    # Lets add probe to get informed of the meta data generated, we add probe to
    # the sink pad of the osd element, since by that time, the buffer would have
    # had got all the metadata.
    osdsinkpad = nvosd.get_static_pad("sink")
    if not osdsinkpad:
        sys.stderr.write(" Unable to get sink pad of nvosd \n")
    osdsinkpad.add_probe(Gst.PadProbeType.BUFFER, osd_sink_pad_buffer_probe, 0)


    print("Starting pipeline \n")
    
    # start play back and listed to events
    pipeline.set_state(Gst.State.PLAYING)
    try:
      loop.run()
    except:
      pass

    # cleanup
    pipeline.set_state(Gst.State.NULL)

config file is :

################################################################################
# Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
################################################################################

# Following properties are mandatory when engine files are not specified:
#   int8-calib-file(Only in INT8)
#   Caffemodel mandatory properties: model-file, proto-file, output-blob-names
#   UFF: uff-file, input-dims, uff-input-blob-name, output-blob-names
#   ONNX: onnx-file
#
# Mandatory properties for detectors:
#   num-detected-classes
#
# Optional properties for detectors:
#   enable-dbscan(Default=false), interval(Primary mode only, Default=0)
#   custom-lib-path,
#   parse-bbox-func-name
#
# Mandatory properties for classifiers:
#   classifier-threshold, is-classifier
#
# Optional properties for classifiers:
#   classifier-async-mode(Secondary mode only, Default=false)
#
# Optional properties in secondary mode:
#   operate-on-gie-id(Default=0), operate-on-class-ids(Defaults to all classes),
#   input-object-min-width, input-object-min-height, input-object-max-width,
#   input-object-max-height
#
# Following properties are always recommended:
#   batch-size(Default=1)
#
# Other optional properties:
#   net-scale-factor(Default=1), network-mode(Default=0 i.e FP32),
#   model-color-format(Default=0 i.e. RGB) model-engine-file, labelfile-path,
#   mean-file, gie-unique-id(Default=0), offsets, gie-mode (Default=1 i.e. primary),
#   custom-lib-path, network-mode(Default=0 i.e FP32)
#
# The values in the config file are overridden by values set through GObject
# properties.


[property]

[property]
gpu-id=0
net-scale-factor=0.0039215697906911373
uff-input-dims=3;720;1280;0
uff-input-blob-name=input_1


gpu-id=0
net-scale-factor=0.0039215697906911373
#model-engine-file=./Resnet10_head_460/resnet10_detector.trt
#tlt-model-file=./CAR_WEIGHTS/CAR_WEIGHTS.tlt
model-engine-file=./Resnet10_head_460/resnet10_detector.etlt_b8_fp16.engine
#tlt-encoded-model=./Resnet10_head_460/resnet10_detector.etlt
tlt-model-key="aWRubW10bjZsbTRyanFnZXFybjE0ZXFnMjc6MmYwYTNiOTQtYTIyOS00ZTNhLTg1ZGYtMTgxNWFiNGEzMz"
labelfile-path=./Resnet10_head_460/labels.txt
#int8-calib-file=./Resnet10_head_460/calibration.bin
batch-size=8
network-mode=1
process-mode=1
model-color-format=0
num-detected-classes=1
interval=0
gie-unique-id=1
#output-blob-names=conv2d_bbox;conv2d_cov/Sigmoid
output-blob-names=output_cov/Sigmoid;output_bbox/BiasAdd


[class-attrs-all]
threshold=0.1
eps=0.1
group-threshold=1
#roi-top-offset=20
#roi-bottom-offset=10
detected-min-w=180
detected-min-h=180
detected-max-w=300
detected-max-h=300

Hi,
Did you use same model when running with .h264 input video and CSI camera?

Thanks amycao for response.
Yes my trained model was working fine with .h264 but when i am using it with CSI camera getting error like internal data stream error.
I had resolved it by changing the in file attaching below But I think it is wrong way.
There I am able to see camera streaming but it is not detecting anything and also unable to draw line on the frames. when I was running on .h264 file i was able to draw line able to detect object. :

def main(args):
    # Check input arguments
    # if len(args) != 2:
    #     sys.stderr.write("usage: %s <media file or uri>\n" % args[0])
    #     sys.exit(1)

    # Standard GStreamer initialization
    GObject.threads_init()
    Gst.init(None)

    # Create gstreamer elements
    # Create Pipeline element that will form a connection of other elements
    print("Creating Pipeline \n ")
    pipeline = Gst.Pipeline()

    if not pipeline:
        sys.stderr.write(" Unable to create Pipeline \n")

    # Source element for reading from the file
    print("Creating Source \n ")
    source = Gst.ElementFactory.make("nvarguscamerasrc", "src_elem")
    if not source:
        sys.stderr.write(" Unable to create Source \n")

    caps_picamsrc = Gst.ElementFactory.make("capsfilter", "src_cap_filter")
    if not caps_picamsrc:
        sys.stderr.write(" Unable to create picamsrc capsfilter \n")

# Video convertor
    print("Creating Video Converter \n")
    nvvidconv1 = Gst.ElementFactory.make("nvvidconv", "convertor1")
    if not nvvidconv1:
        sys.stderr.write(" Unable to create Nvvideoconvert \n")
    
    caps_nvvidconv1 = Gst.ElementFactory.make("capsfilter", "nvmm_caps")
    if not caps_nvvidconv1:
        sys.stderr.write(" Unable to create capsfilter \n")

    # Create nvstreammux instance to form batches from one or more sources.
    streammux = Gst.ElementFactory.make("nvstreammux", "Stream-muxer")
    if not streammux:
        sys.stderr.write(" Unable to create NvStreamMux \n")

    # Use nvinfer to run inferencing on decoder's output,
    # behaviour of inferencing is set through config file
    pgie = Gst.ElementFactory.make("nvinfer", "primary-inference")
    if not pgie:
        sys.stderr.write(" Unable to create pgie \n")

    # Use convertor to convert from NV12 to RGBA as required by nvosd
    nvvidconv2 = Gst.ElementFactory.make("nvvidconv", "converto2r")
    if not nvvidconv2:
        sys.stderr.write(" Unable to create nvvidconv \n")

    tracker = Gst.ElementFactory.make("nvtracker", "tracker")
    if not tracker:
        sys.stderr.write(" Unable to create tracker \n")

    # Create OSD to draw on the converted RGBA buffer
    nvosd = Gst.ElementFactory.make("nvdsosd", "onscreendisplay")

    if not nvosd:
        sys.stderr.write(" Unable to create nvosd \n")

    # Finally render the osd output
    if is_aarch64():
        transform = Gst.ElementFactory.make("nvegltransform", "nvegl-transform")

print("Creating EGLSink \n")
    sink = Gst.ElementFactory.make("nveglglessink", "sink_sub_bin_sink1")
    if not sink:
        sys.stderr.write(" Unable to create egl sink \n")

    caps_picamsrc.set_property('caps', Gst.Caps.from_string('video/x-raw(memory:NVMM), width=1280, height=720, framerate=21/1, format=NV12,flip-method=2'))
    caps_nvvidconv1.set_property('caps', Gst.Caps.from_string('video/x-raw,width=1280, height=720'))

#print("Playing file %s " %args[1])
    #source.set_property('location', args[1])
    streammux.set_property('width', 1280)
    streammux.set_property('height', 720)
    streammux.set_property('batch-size', 1)
    streammux.set_property('batched-push-timeout', 4000000)
    #caps_nvvidconv1.set_property('flip-method', 2)

    #Set properties of pgie and sgie
    pgie.set_property('config-file-path', "Resnet_10_head.txt")

    sink.set_property('sync', False)

#Set properties of tracker
    config = configparser.ConfigParser()
    config.read('dstest2_tracker_config.txt')
    config.sections()

    for key in config['tracker']:
        if key == 'tracker-width' :
            tracker_width = config.getint('tracker', key)
            tracker.set_property('tracker-width', tracker_width)
        if key == 'tracker-height' :
            tracker_height = config.getint('tracker', key)
            tracker.set_property('tracker-height', tracker_height)
        if key == 'gpu-id' :
            tracker_gpu_id = config.getint('tracker', key)
            tracker.set_property('gpu_id', tracker_gpu_id)
        if key == 'll-lib-file' :
            tracker_ll_lib_file = config.get('tracker', key)
            tracker.set_property('ll-lib-file', tracker_ll_lib_file)
        if key == 'll-config-file' :
            tracker_ll_config_file = config.get('tracker', key)
            tracker.set_property('ll-config-file', tracker_ll_config_file)
        if key == 'enable-batch-process' :
            tracker_enable_batch_process = config.getint('tracker', key)
            tracker.set_property('enable_batch_process', tracker_enable_batch_process)

print("Adding elements to Pipeline \n")
    pipeline.add(source)
    pipeline.add(caps_picamsrc)
    pipeline.add(nvvidconv1)
    pipeline.add(caps_nvvidconv1)
    pipeline.add(nvvidconv2)
    if is_aarch64():
        pipeline.add(transform)
    pipeline.add(sink)
    pipeline.add(streammux)
    pipeline.add(pgie)
    pipeline.add(tracker)    
    pipeline.add(nvosd)

# we link the elements together
    # file-source -> h264-parser -> nvh264-decoder ->
    # nvinfer -> nvvidconv -> nvosd -> video-renderer

    #  gst-launch-1.0 nvarguscamerasrc ! 
    # 'video/x-raw(memory:NVMM),width=3820, height=2464, framerate=21/1, format=NV12' 
    # ! nvvidconv flip-method=2 ! 'video/x-raw,width=960, height=616' ! nvvidconv ! nvegltransform ! nveglglessink -e

    print("Linking elements in the Pipeline \n")
    source.link(caps_picamsrc)
    caps_picamsrc.link(nvvidconv1)
    nvvidconv1.link(caps_nvvidconv1)
    caps_nvvidconv1.link(nvvidconv2)
    if is_aarch64():
        nvvidconv2.link(transform)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
        transform.link(sink)
    else:    
         nvvidconv2.link(sink)

    sinkpad = streammux.get_request_pad("sink_0")
    srcpad = caps_nvvidconv1.get_static_pad("src")
    srcpad.link(sinkpad)
    streammux.link(pgie)
    pgie.link(tracker)

    #tracker.link(nvvidconv2)
    tracker.link(nvosd)
    if is_aarch64():
        nvosd.link(transform)
        transform.link(sink)
    else:
        nvosd.link(sink)

# create and event loop and feed gstreamer bus mesages to it
    loop = GObject.MainLoop()

    bus = pipeline.get_bus()
    bus.add_signal_watch()
    bus.connect ("message", bus_call, loop)

    # Lets add probe to get informed of the meta data generated, we add probe to
    # the sink pad of the osd element, since by that time, the buffer would have
    # had got all the metadata.
    osdsinkpad = nvosd.get_static_pad("sink")
    if not osdsinkpad:
        sys.stderr.write(" Unable to get sink pad of nvosd \n")
    osdsinkpad.add_probe(Gst.PadProbeType.BUFFER, osd_sink_pad_buffer_probe, 0)

print("Starting pipeline \n")
    
    # start play back and listed to events
    pipeline.set_state(Gst.State.PLAYING)
    try:
      loop.run()
    except:
      pass

    # cleanup
    pipeline.set_state(Gst.State.NULL)

if __name__ == '__main__':
    sys.exit(main(sys.argv))

Please help me out I am stuck in this problem from long time.
Thanks

Hi
Please refer to sources/apps/apps-common/src/deepstream_source_bin.c::create_camera_source_bin
where CSI camera source bin is created.

Please try the sample code in https://devtalk.nvidia.com/default/topic/1071110/deepstream-sdk/unable-to-run-inference-pipeline-using-csi-camera-source-in-deepstream-python-app/post/5435300/#5435300