nnstreamer / nnstreamer-example

Example applications of nnstreamer. Note that we have to enable the 'apptest" CI module in the near future.
GNU Lesser General Public License v2.1
77 stars 72 forks source link

[EXAMPLE] tensor_crop example #307

Closed Harshj20 closed 1 year ago

Harshj20 commented 1 year ago

Example for Tensor_crop plugin which crops the input video from v4l2src and renders the cropped video using autovideosink. Use a video source with an aspect ratio of 1:1 to avoid distortion.

It uses the following pipeline:

gst-launch-1.0 v4l2src ! decodebin ! videoconvert ! videoscale ! video/x-raw, width=640, height=480, framerate=30/1, format=RGB ! videocrop left=170 right=170 top=90 bottom=90 ! tee name=t t. ! queue leaky=2 max-size-buffers=2 ! tensor_converter ! crop.raw t. ! queue leaky=2 max-size-buffers=10 ! tensor_converter ! tensor_transform mode=arithmetic option=typecast:float32,add:-127.5,div:127.5 ! tensor_filter framework=tensorflow2-lite model=tflite_model/ssd_mobilenet_v2_coco.tflite ! tensor_decoder mode=tensor_region option1=1 option2=tflite_model/coco_labels_list.txt option3=tflite_model/box_priors.txt option4=300:300 ! crop.info tensor_crop name=crop ! other/tensors,format=flexible ! tensor_converter ! tensor_decoder mode=direct_video ! videoconvert ! videoscale ! video/x-raw,format=RGB ! videoconvert ! autovideosink name=cropped t. ! queue ! autovideosink name=original

The second autovideosink element is to view the original video.

taos-ci commented 1 year ago

:memo: TAOS-CI Version: 1.5.20200925. Thank you for submitting PR #307. Please a submit 1commit/1PR (one commit per one PR) policy to get comments quickly from reviewers. Your PR must pass all verificiation processes of cibot before starting a review process from reviewers. If you are new member to join this project, please read manuals in documentation folder and wiki page. In order to monitor a progress status of your PR in more detail, visit http://ci.nnstreamer.ai/.

gichan-jang commented 1 year ago

This is a good example to understand tensor_crop. Thanks. How about the example below to show that we can crop multiple areas?

gst-launch-1.0 v4l2src ! videoconvert ! videoscale ! video/x-raw, width=640, height=480, framerate=30/1, format=RGB ! \
  videocrop left=170 right=170 top=90 bottom=90 ! tee name=t  t. ! queue leaky=2 max-size-buffers=2 ! tensor_converter ! crop.raw \
  t. ! queue leaky=2 max-size-buffers=10 ! tensor_converter ! tensor_transform mode=arithmetic option=typecast:float32,add:-127.5,div:127.5 ! \
    tensor_filter framework=tensorflow2-lite model=tflite_model/ssd_mobilenet_v2_coco.tflite ! \
    tensor_decoder mode=tensor_region option1=2 option2=tflite_model/coco_labels_list.txt option3=tflite_model/box_priors.txt option4=300:300 ! \
      crop.info tensor_crop name=crop ! other/tensors,format=flexible ! tensor_demux name=demux \
        demux.src_0 ! queue ! tensor_converter ! tensor_decoder mode=direct_video ! \
        videoconvert ! videoscale ! video/x-raw,format=RGB ,height=300,width=300 ! videoconvert ! xvimagesink \
        demux.src_1 ! queue ! tensor_converter ! tensor_decoder mode=direct_video ! \
        videoconvert ! videoscale ! video/x-raw,format=RGB ,height=300,width=300 ! videoconvert ! xvimagesink \
  t. ! queue ! videoconvert ! xvimagesink name=original
Harshj20 commented 1 year ago

This is a good example to understand tensor_crop. Thanks. How about the example below to show that we can crop multiple areas?

gst-launch-1.0 v4l2src ! videoconvert ! videoscale ! video/x-raw, width=640, height=480, framerate=30/1, format=RGB ! \
  videocrop left=170 right=170 top=90 bottom=90 ! tee name=t  t. ! queue leaky=2 max-size-buffers=2 ! tensor_converter ! crop.raw \
  t. ! queue leaky=2 max-size-buffers=10 ! tensor_converter ! tensor_transform mode=arithmetic option=typecast:float32,add:-127.5,div:127.5 ! \
    tensor_filter framework=tensorflow2-lite model=tflite_model/ssd_mobilenet_v2_coco.tflite ! \
    tensor_decoder mode=tensor_region option1=2 option2=tflite_model/coco_labels_list.txt option3=tflite_model/box_priors.txt option4=300:300 ! \
      crop.info tensor_crop name=crop ! other/tensors,format=flexible ! tensor_demux name=demux \
        demux.src_0 ! queue ! tensor_converter ! tensor_decoder mode=direct_video ! \
        videoconvert ! videoscale ! video/x-raw,format=RGB ,height=300,width=300 ! videoconvert ! xvimagesink \
        demux.src_1 ! queue ! tensor_converter ! tensor_decoder mode=direct_video ! \
        videoconvert ! videoscale ! video/x-raw,format=RGB ,height=300,width=300 ! videoconvert ! xvimagesink \
  t. ! queue ! videoconvert ! xvimagesink name=original

I have been trying to test-run this pipeline. I will update the code as soon as I can generate the desired results.

gichan-jang commented 1 year ago

This is a good example to understand tensor_crop. Thanks. How about the example below to show that we can crop multiple areas?

gst-launch-1.0 v4l2src ! videoconvert ! videoscale ! video/x-raw, width=640, height=480, framerate=30/1, format=RGB ! \
  videocrop left=170 right=170 top=90 bottom=90 ! tee name=t  t. ! queue leaky=2 max-size-buffers=2 ! tensor_converter ! crop.raw \
  t. ! queue leaky=2 max-size-buffers=10 ! tensor_converter ! tensor_transform mode=arithmetic option=typecast:float32,add:-127.5,div:127.5 ! \
    tensor_filter framework=tensorflow2-lite model=tflite_model/ssd_mobilenet_v2_coco.tflite ! \
    tensor_decoder mode=tensor_region option1=2 option2=tflite_model/coco_labels_list.txt option3=tflite_model/box_priors.txt option4=300:300 ! \
      crop.info tensor_crop name=crop ! other/tensors,format=flexible ! tensor_demux name=demux \
        demux.src_0 ! queue ! tensor_converter ! tensor_decoder mode=direct_video ! \
        videoconvert ! videoscale ! video/x-raw,format=RGB ,height=300,width=300 ! videoconvert ! xvimagesink \
        demux.src_1 ! queue ! tensor_converter ! tensor_decoder mode=direct_video ! \
        videoconvert ! videoscale ! video/x-raw,format=RGB ,height=300,width=300 ! videoconvert ! xvimagesink \
  t. ! queue ! videoconvert ! xvimagesink name=original

I have been trying to test-run this pipeline. I will update the code as soon as I can generate the desired results.

Let's update this in next PR. LGTM.