def do_transform_ip(self, buf): try: with buf.map(Gst.MapFlags.READ | Gst.MapFlags.WRITE) as info: # Create a NumPy ndarray from the memoryview and modify it in place. A = np.ndarray(shape=(self.height, self.width), dtype=np.uint8, buffer=info.data) Gst.trace("A=%s" % (str(A))) A[:] = A * 0.1 Gst.trace("A=%s" % (str(A))) return Gst.FlowReturn.OK except Gst.MapError as e: Gst.error("Mapping error: %s" % e) return Gst.FlowReturn.ERROR
def do_transform_ip(self, buf): try: with buf.map(Gst.MapFlags.READ | Gst.MapFlags.WRITE) as info: Gst.trace('info=%s, size=%d' % (str(info), info.size)) # Create a NumPy ndarray from the memoryview and modify it in place. buf_np = np.ndarray(shape=(self.height, self.width), dtype=np.uint8, buffer=info.data) Gst.trace("buf_np=%s" % (str(buf_np))) # Create tensors. t1 = tf.constant(buf_np) Gst.trace("t1=%s" % (str(t1))) t2 = t1 / 4 Gst.trace("t2=%s" % (str(t2))) # Copy tensor to overwrite input/output buffer. buf_np[:] = t2 return Gst.FlowReturn.OK except Gst.MapError as e: Gst.error("Mapping error: %s" % e) return Gst.FlowReturn.ERROR