Example #1
0
class ObjectTracker(OpenCVVideoFilter):
    __gstmetadata__ = (
        "Object tracker plugin",
        "newelement",
        "Description",
        "Contact")

    def __init__(self):
        super(ObjectTracker, self).__init__()
        self.tracker = Tracker([self.h, self.w])
        self.api = GstVideo.VideoRegionOfInterestMeta.get_info()

    def do_transform(self, b, outbuffer):
        img = self.gst_to_cv(b)
        ts = time.time()
        self.tracker.track(ts, img)
        tag_list = Gst.TagList.new_empty()
	
        for t in self.tracker.to_log():
            blob = t.bestblob()
            info = Gst.Structure.new_empty('roi')
            info.set_value('id', t.id)
            info.set_value('ts', ts)
            info.set_value('bbox', blob.bbox )
            sample = Gst.Sample.new(b, None, None, info)
            logging.debug('new tag with object track info for track %s',str(t.id))
            tag_list.add_value(Gst.TagMergeMode.APPEND, Gst.TAG_APPLICATION_DATA, sample)	
        if tag_list.n_tags()>0:
            outbuffer.add_meta(self.api, tag_list)
            self.post_message(Gst.Message.new_tag(self, tag_list))

        return Gst.FlowReturn.OK