Open Bardia-Khodadadeh opened 1 year ago
Hello
Please look at https://github.com/TheImagingSource/tiscamera/blob/master/examples/c/06-softwaretrigger.c
I hope, this helps.
@TIS-Stefan Thanks for the answer how can get the frames of camera as a Mat so i can use them later on? like saving the Mats or process them using opencv
Hello
The code in https://github.com/TheImagingSource/Linux-tiscamera-Programming-Samples/tree/master/python/python-common creates a numpy array from the GstBuffer. The __on_new_buffer() is the callback from the appsink, which is called, when a new frame comes in. You may use the tis.py class from the link above.
def __on_new_buffer(self, appsink):
sample = appsink.get_property('last-sample')
if sample and self.ImageCallback is not None:
buf = sample.get_buffer()
data = buf.extract_dup(0, buf.get_size())
caps = sample.get_caps()
self.img_mat = self.__convert_to_numpy(data, caps)
self.ImageCallback(self, *self.ImageCallbackData)
return Gst.FlowReturn.OK
def __convert_to_numpy(self, data, caps):
''' Convert a GStreamer sample to a numpy array
Sample code from https://gist.github.com/cbenhagen/76b24573fa63e7492fb6#file-gst-appsink-opencv-py-L34
The result is in self.img_mat.
:return:
'''
s = caps.get_structure(0)
fmt = s.get_value('format')
if (fmt == "BGRx"):
dtype = numpy.uint8
bpp = 4
elif (fmt == "GRAY8"):
dtype = numpy.uint8
bpp = 1
elif (fmt == "GRAY16_LE"):
dtype = numpy.uint16
bpp = 1
else:
raise RuntimeError(f"Unknown format in conversion to numpy array: {fmt}")
img_mat = numpy.ndarray(
(s.get_value('height'),
s.get_value('width'),
bpp),
buffer=data,
dtype=dtype)
return img_mat
I would like to point you to the other samples at https://github.com/TheImagingSource/Linux-tiscamera-Programming-Samples/tree/master/python, because they may do what you want.
Stefan
Hi there i want cpp code with similar functionality to this c# code below
private void IC_SoftWareTrigger() { TIS.Imaging.VCDButtonProperty SoftTrigger = (TIS.Imaging.VCDButtonProperty)icImagingControl1.VCDPropertyItems.FindInterface(TIS.Imaging.VCDIDs.VCDID_TriggerMode + ":{FDB4003C-552C-4FAA-B87B-42E888D54147}:" + TIS.Imaging.VCDIDs.VCDInterface_Button); if (SoftTrigger != null) { SoftTrigger.Push(); } }