if self.contrast == True: conved = simpleContrast(conved) #copy to top left coner ch, cw = conved.shape image[0, :ch, :cw] = conved except Exception as e: logging.error(e) return Gst.FlowReturn.OK # Required for registering plugin dynamically # Explained: # http://lifestyletransfer.com/how-to-write-gstreamer-plugin-with-python/ GObject.type_register(GstUvConv2d) __gstelementfactory__ = (GstUvConv2d.GST_PLUGIN_NAME, Gst.Rank.NONE, GstUvConv2d) def simpleContrast(img: np.ndarray) -> np.ndarray: img_min = img.min() img_over = (img.max() - img_min) img_over = (255 / (img.max() - img_min)) if img_over != 0 else 255 return ((img - img_min) * img_over).astype("uint8") def histContrast(img: np.ndarray) -> np.ndarray: h, bin_edges = np.histogram(img, bins=256) cdf = np.cumsum(h)
raise AttributeError('Unknown property %s' % prop.name) def _do_set_model(self, model: TfObjectDetectionModel): # stop previous instance if self.model: self.model.shutdown() self.model = None self.model = model # start new instance if self.model: self.model.startup() def __exit__(self, exc_type, exc_val, exc_tb): Gst.info(f"Shutdown {self}") if self.model: self.model.shutdown() sGst.info(f"Destroyed {self}") # Required for registering plugin dynamically # Explained: http://lifestyletransfer.com/how-to-write-gstreamer-plugin-with-python/ GObject.type_register(GstTfDetectionPluginPy) __gstelementfactory__ = (GstTfDetectionPluginPy.GST_PLUGIN_NAME, Gst.Rank.NONE, GstTfDetectionPluginPy)
conved = simpleContrast(conved, 0.0) #copy to top left coner ch, cw = conved.shape image[0, :ch, :cw] = conved except Exception as e: logging.info(conved.shape) logging.error(e) return Gst.FlowReturn.OK # Required for registering plugin dynamically # Explained: # http://lifestyletransfer.com/how-to-write-gstreamer-plugin-with-python/ GObject.type_register(GstUvMxnetSharp) __gstelementfactory__ = (GstUvMxnetSharp.GST_PLUGIN_NAME, Gst.Rank.NONE, GstUvMxnetSharp) def adaptiveEqualization(img: np.ndarray, clip_limit: float = 0.03) -> np.ndarray: img_f = img_as_float(img) logging.info(img_f[0, :4]) return img_as_ubyte(exposure.equalize_adapthist(img_f, clip_limit)) def simpleContrast(img: np.ndarray, skipPart) -> np.ndarray: img_min = img.min() img_over = (img.max() - img_min) img_over = (255 / (img.max() - img_min)) if img_over != 0 else 255
def do_set_property(self, prop: GObject.GParamSpec, value): if prop.name == 'kernel': self.kernel_size = value elif prop.name == 'sigmaX': self.sigma_x = value elif prop.name == 'sigmaY': self.sigma_y = value else: raise AttributeError('unknown property %s' % prop.name) def do_transform_ip(self, buffer: Gst.Buffer) -> Gst.FlowReturn: try: # convert Gst.Buffer to np.ndarray image = gst_buffer_with_caps_to_ndarray(buffer, self.sinkpad.get_current_caps()) # apply gaussian blur to image image[:] = gaussian_blur(image, self.kernel_size, sigma=(self.sigma_x, self.sigma_y)) except Exception as e: logging.error(e) return Gst.FlowReturn.OK # Required for registering plugin dynamically # Explained: # http://lifestyletransfer.com/how-to-write-gstreamer-plugin-with-python/ GObject.type_register(GstGaussianBlur) __gstelementfactory__ = (GstGaussianBlur.GST_PLUGIN_NAME, Gst.Rank.NONE, GstGaussianBlur)
# stop previous instance if self._model: self._model.shutdown() self._model = None self._model = model # start new instance if self._model: self._model.startup() # Required for registering plugin dynamically # Explained: http://lifestyletransfer.com/how-to-write-gstreamer-plugin-with-python/ GObject.type_register(GstDeepSpeechPluginPy) __gstelementfactory__ = (GstDeepSpeechPluginPy.GST_PLUGIN_NAME, Gst.Rank.NONE, GstDeepSpeechPluginPy) # if self.counter >= self.num_frames or self.counter == 0: # if isinstance(self.frame, np.ndarray): # # n = self.frame.shape[0] # # k = audio.shape[0] * 2 # # from_index = np.clip(n - k, 0, n - 1) # # to_index = np.clip(from_index + k, from_index, n - 1) # # # print((to_index - from_index) // audio.shape[0], from_index, to_index) # # chunk = self.frame[from_index:to_index] # rms = np.sqrt(np.mean(audio) ** 2)
conved = simpleContrast(conved, 0.0) #copy to top left coner ch, cw = conved.shape image[0, :ch, :cw] = conved except Exception as e: logging.info(conved.shape) logging.error(e) return Gst.FlowReturn.OK # Required for registering plugin dynamically # Explained: # http://lifestyletransfer.com/how-to-write-gstreamer-plugin-with-python/ GObject.type_register(GstUvMxnetConv2d) __gstelementfactory__ = (GstUvMxnetConv2d.GST_PLUGIN_NAME, Gst.Rank.NONE, GstUvMxnetConv2d) def adaptiveEqualization(img: np.ndarray, clip_limit: float = 0.03) -> np.ndarray: img_f = img_as_float(img) logging.info(img_f[0, :4]) return img_as_ubyte(exposure.equalize_adapthist(img_f, clip_limit)) def simpleContrast(img: np.ndarray, skipPart) -> np.ndarray: img_min = img.min() img_over = (img.max() - img_min) img_over = (255 / (img.max() - img_min)) if img_over != 0 else 255
# Do drawing with map_gst_buffer(buffer, Gst.MapFlags.READ | Gst.MapFlags.WRITE) as mapped: self.model.draw(mapped, width, height, objects) except Exception as err: Gst.error(f"Error {self}: {err}") return Gst.FlowReturn.ERROR return Gst.FlowReturn.OK def do_get_property(self, prop: GObject.GParamSpec): if prop.name == 'model': return self.model else: raise AttributeError('unknown property %s' % prop.name) def do_set_property(self, prop: GObject.GParamSpec, value): if prop.name == 'model': self.model = value else: raise AttributeError('unknown property %s' % prop.name) # Required for registering plugin dynamically # Explained: http://lifestyletransfer.com/how-to-write-gstreamer-plugin-with-python/ GObject.type_register(GstDetectionOverlay) __gstelementfactory__ = (GstDetectionOverlay.GST_PLUGIN_NAME, Gst.Rank.NONE, GstDetectionOverlay)