Code: Select all
Y = 0.3×Y + 0.41×V - 41.28
V = 0.51×Y + 0.7×V + 30.143
U = -0.172×Y - 0.236×V + 161
Code: Select all
appears to be a GStreamer plugin, but it failed to initialize
Code: Select all
$ GST_DEBUG=4 gst-inspect-1.0 src/.libs/libredfilter.so
Code: Select all
...
0:00:00.134567821 17366 0x1cb2e00 WARN GST_PLUGIN_LOADING gstplugin.c:500:gst_plugin_register_func: plugin "/usr/local/lib/gstreamer-1.0/libredfilter.so" has invalid license "none", not loading
...
Code: Select all
$ gst-launch-1.0 -v -m fakesrc ! redfilter ! fakesink silent=TRUE
Leitung wird auf PAUSIERT gesetzt ...
...
new-state=(GstState)GST_STATE_PAUSED, pending-state=(GstState)GST_STATE_VOID_PENDING;
Leitung ist vorgelaufen …
Nachricht #24 wurde von Element »pipeline0« (async-done) erhalten: GstMessageAsyncDone, running-time=(guint64)18446744073709551615;
Leitung wird auf ABSPIELEN gesetzt ...
I'm plugged, therefore I'm in.
I'm plugged, therefore I'm in.
I'm plugged, therefore I'm in.
I'm plugged, therefore I'm in.
I'm plugged, therefore I'm in.
I'm plugged, therefore I'm in.
I'm plugged, therefore I'm in.
Nachricht #26 wurde von Element »pipeline0« (new-clock) erhalten: I'm plugged, therefore I'm in.
I'm plugged, therefore I'm in.
GstMessageNewClock, clock=(GstClock)"\(GstSystemClock\)\ GstSystemClock";
New clock: GstSystemClock
...
Helium-neon lasers emit at 632.8nm, which is a bright red.
Code: Select all
raspividyuv -t 0 -w 640 -h 480 -fps 90 -n -o - | gst-launch-1.0 -v fdsrc ! queue ! "video/x-raw, width=640, height=480, format=I420, framerate=90/1" ! rawvideoparse use-sink-caps=true ! videoconvert ! fbdevsink device="/dev/fb0"
Code: Select all
... ! fbdevsink device="/dev/fb0"
Code: Select all
... ! fpsdisplaysink text-overlay=false video-sink='fbdevsink device="/dev/fb0"'
Code: Select all
...
/GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 1205, dropped: 0, current: 52,22, average: 52,43
/GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 1232, dropped: 0, current: 52,41, average: 52,43
/GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 1259, dropped: 0, current: 52,82, average: 52,44
Code: Select all
@@ -236,8 +237,16 @@ gst_red_filter_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
filter = GST_REDFILTER (parent);
- if (filter->silent == FALSE)
+ if (filter->silent == FALSE) {
+ GstMapInfo info;
+
+ gst_buffer_map (buf, &info, GST_MAP_READWRITE);
+ g_print("buf(%d) ",info.size);
+ memset(info.data,64,640*100);
+ gst_buffer_unmap (buf, &info);
+
g_print ("I'm plugged, therefore I'm in.\n");
+ }
Code: Select all
...
640x480(I420) 11188888777
640x480(I420) 11199999888
640x480(I420) 11211110999
640x480(I420) 11222222110
640x480(I420) 11233333221
640x480(I420) 11244444332
640x480(I420) 11255555443
Code: Select all
$ raspividyuv -t 0 -md 7 -w 640 -h 480 -fps 90 -n -o - | GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0/ gst-launch-1.0 -v fdsrc ! queue ! "video/x-raw, width=640, height=480, format=I420, framerate=90/1" ! rawvideoparse use-sink-caps=true ! redfilter ! videoconvert ! fbdevsink device="/dev/fb0"
Code: Select all
$ gst-launch-1.0 videotestsrc ! video/x-raw,format=I420 ! redfilter ! autovideosink
Code: Select all
$ raspividyuv -t 0 -md 7 -w 640 -h 480 -fps 60 -n -o - | GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0/ gst-launch-1.0 -v fdsrc ! queue ! "video/x-raw, width=640, height=480, format=I420, framerate=30/1" ! rawvideoparse use-sink-caps=true ! redfilter ! videoconvert ! fpsdisplaysink text-overlay=false video-sink='fbdevsink device="/dev/fb0"'
No need for that, just learned (again) that raspivid encoding is I420 as well.
Code: Select all
$ raspivid -t 0 -md 6 -w 640 -h 360 -fps 30 -n -o - | GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0/ gst-launch-1.0 -v fdsrc ! h264parse ! omxh264dec ! redfilter ! videoconvert ! fpsdisplaysink text-overlay=false video-sink='fbdevsink device="/dev/fb0"'
Can you please try the redfilter (git clone my gitlab repo, build&install by "cd gst-template/redfilter; ./autogen.sh; make; sudo make install", and then use raspividyuv redfilter pipeline from previous posting)?SanDiegoPiGuy wrote: ↑Sun Jul 28, 2019 2:24 pmThanks all. I’m working with some dyes that fluoresce at 633 nm and wanted to be able to isolate that general “red” color from the image. It would be useful to blend the other colors, so I want to avoid a physical color filter.
Code: Select all
$ raspividyuv -t 0 -md 7 -w 640 -h 480 -fps 60 -n -o - | GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0/ gst-launch-1.0 -v fdsrc ! queue ! "video/x-raw, width=640, height=480, format=I420, framerate=31/1" ! rawvideoparse use-sink-caps=true ! redfilter ! videoconvert ! fpsdisplaysink text-overlay=false video-sink='fbdevsink device="/dev/fb0"'
Code: Select all
...
640x480(I420) 4064516064 14,27ms
640x480(I420) 4096774128 14,34ms
640x480(I420) 4129032192 14,29ms
/GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 129, dropped: 0, current: 31,00, average: 31,23
640x480(I420) 4161290256 14,30ms
640x480(I420) 4193548320 14,47ms
640x480(I420) 4225806384 14,24ms
...
Code: Select all
640x480(I420) 23500000000 14,26ms
640x480(I420) 23531250000 14,27ms
640x480(I420) 23562500000 14,27ms
/GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 755, dropped: 0, current: 31,98, average: 32,04
640x480(I420) 23593750000 14,21ms
640x480(I420) 23625000000 14,20ms
640x480(I420) 23656250000 14,23ms
...
Code: Select all
[email protected]:~/gst-template/redfilter $ raspividyuv -t 0 -md 7 -w 640 -h 480 -fps 54 -n -o - | GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0/ gst-launch-1.0 -v fdsrc ! queue ! "video/x-raw, width=640, height=480, format=I420, framerate=54/1" ! rawvideoparse use-sink-caps=true ! redfilter ! fakesink > out
Code: Select all
...
redfilter: 640x480(I420) buf->pts=4351851730ns 14,29ms real=4336337649ns
redfilter: 640x480(I420) buf->pts=4370370248ns 14,32ms real=4354555036ns
redfilter: 640x480(I420) buf->pts=4388888766ns 14,31ms real=4371308655ns
redfilter: 640x480(I420) buf->pts=4407407284ns 14,31ms real=4391392665ns
redfilter: 640x480(I420) buf->pts=4425925802ns 14,34ms real=4407780042ns
redfilter: 640x480(I420) buf->pts=4444444320ns 14,31ms real=4429087617ns
redfilter: 640x480(I420) buf->pts=4462962838ns 14,31ms real=4446170864ns
redfilter: 640x480(I420) buf->pts=4481481356ns 14,30ms real=4465258855ns
handling interrupt.
...
Hi HermannSW:HermannSW wrote: ↑Mon Aug 05, 2019 2:42 pmNo need for that, just learned (again) that raspivid encoding is I420 as well.
With raspivid use of h264parse and (hardware accelerated) omxh264dec are needed, besides that redfilter just works. With mode 7 minimal framerate 60fps gstreamer pipeline gets overloaded again. Using v2 mode 6 (1280x720) and scale to 640x480 (with GPU, options -w 640 -h 480) does overload gstreamer pipeline for framerate 30fps, but works for framerate 20fps. This is 30fps raspivid redfilter pipeline that works, the frame is just 50% of mode 6 (640x360) and a 25% smaller. This is the command that gives 30fps "real time" redfilter video display:Although omxh264dec is hardware accelerated, "... ! h264parse ! omxh264dec ! ..." introduces a small latency.Code: Select all
$ raspivid -t 0 -md 6 -w 640 -h 360 -fps 30 -n -o - | GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0/ gst-launch-1.0 -v fdsrc ! h264parse ! omxh264dec ! redfilter ! videoconvert ! fpsdisplaysink text-overlay=false video-sink='fbdevsink device="/dev/fb0"'
Summary:
Either framesize or framerate has to be reduced a bit for raspivid to achieve same performance as raspividyuv with redfilter.
In addition radpivid redfilter pipeline has higher latency than raspividyuv pipeline.
Therefore raspividyuv redfilter pipeline is preferable.
Can you please try the redfilter (git clone my gitlab repo, build&install by "cd gst-template/redfilter; ./autogen.sh; make; sudo make install", and then use raspividyuv redfilter pipeline from previous posting)?SanDiegoPiGuy wrote: ↑Sun Jul 28, 2019 2:24 pmThanks all. I’m working with some dyes that fluoresce at 633 nm and wanted to be able to isolate that general “red” color from the image. It would be useful to blend the other colors, so I want to avoid a physical color filter.
633nm wavelength corresponds to color #ff4200; does redfilter achieve what you are interested in?
Hi,
Average computation time per pixel is 14.3ms/(640*480)=46.6ns (or 65 clock cycles at 1.4GHz).
No, there's no simple way to achieve that.
Code: Select all
gdouble clamp(gdouble d) {
if (d<0.0) { d=0.0; }
else if (d>255.0) { d=255.0; }
return d;
}
gdouble YUV2R(gdouble y, gdouble v) { return clamp(1.164*(y-16)+1.596*(v-128));}
gdouble R2Y(gdouble r) { return 0.257*r+16;}
gdouble R2V(gdouble r) { return 0.439*r+128;}
gdouble R2U(gdouble r) { return 128-0.148*r;}
Thank you so much to have brought this up.
Code: Select all
$ raspividyuv -rgb -t 0 -md 7 -w 640 -h 480 -fps 100 -n -o - | GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0/ gst-launch-1.0 -v fdsrc ! queue ! "video/x-raw, width=640, height=480, format=RGB, framerate=100/1" ! rawvideoparse use-sink-caps=true ! redfilter ! fakesink > /dev/shm/out
Code: Select all
redfilter: 640x480(RGB) buf->pts=9570000000ns 1.37ms real=9550868926ns
redfilter: 640x480(RGB) buf->pts=9580000000ns 1.39ms real=9560937012ns
redfilter: 640x480(RGB) buf->pts=9590000000ns 1.36ms real=9570771400ns
redfilter: 640x480(RGB) buf->pts=9600000000ns 1.38ms real=9580576100ns
redfilter: 640x480(RGB) buf->pts=9610000000ns 1.37ms real=9590676687ns
redfilter: 640x480(RGB) buf->pts=9620000000ns 1.36ms real=9600544199ns
redfilter: 640x480(RGB) buf->pts=9630000000ns 1.36ms real=9610577389ns
redfilter: 640x480(RGB) buf->pts=9640000000ns 1.37ms real=9620691361ns
redfilter: 640x480(RGB) buf->pts=9650000000ns 1.36ms real=9630505957ns
redfilter: 640x480(RGB) buf->pts=9660000000ns 1.37ms real=9640425657ns
handling interrupt.
Code: Select all
} else if (strcmp(fmt,"RGB")==0) {
GstMapInfo info;
guint8 *p;
gst_buffer_map (buf, &info, GST_MAP_READWRITE);
assert(w*h*3 == info.size);
for(p=info.data+info.size; p>info.data; ) {
*--p=0; // b
*--p=0; // g
--p; // r
}
assert(p==info.data);
...
Code: Select all
$ raspividyuv -rgb -t 0 -md 7 -w 640 -h 480 -fps 70 -n -o - | GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0/ gst-launch-1.0 -v fdsrc ! queue ! "video/x-raw, width=640, height=480, format=RGB, framerate=70/1" ! rawvideoparse use-sink-caps=true ! redfilter ! videoconvert ! fbdevsink device=/dev/fb0
I noticed that the RPi is now overheating (see the top right red thermometer). We made more experiments with OpenCV and it looks like this is the direction we are going to take.HermannSW wrote: ↑Tue Aug 20, 2019 9:20 pmThank you so much to have brought this up.
I created redfilter sofar on the YUV input requirement from original poster.
But as we have seen doing redfilter for YUV data needs quite some transformations per pixel.
Yesterday I looked at raspividyuv doc and found option "--rgb, -rgb" that saves RGB formation instead of I420 (YUV).
I just commited making redfilter applicable to RGB format in addition to I420:
https://gitlab.freedesktop.org/HermannS ... 878edb42c5
This is how to execute command:Code: Select all
$ raspividyuv -rgb -t 0 -md 7 -w 640 -h 480 -fps 100 -n -o - | GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0/ gst-launch-1.0 -v fdsrc ! queue ! "video/x-raw, width=640, height=480, format=RGB, framerate=100/1" ! rawvideoparse use-sink-caps=true ! redfilter ! fakesink > /dev/shm/out
As you can see, raspividyou option -rgb tells to use RGB format, and in gstreamer pipeline now we see fomat="RGB". What you will notice as well is now a much higher framerate for raspividyuv as well as in gstreamer pipeline. Reason is that redfilter now can be done in 1.39ms per pixel, a more than 10× speedup! And that on "only" 1.2GHz Raspberry 3B compared to 1.4GHz Raspberry 3A+ before. 1.39ms is now less than 6 CPU cycles only per 640x480 frame pixel(!):Code: Select all
redfilter: 640x480(RGB) buf->pts=9570000000ns 1.37ms real=9550868926ns redfilter: 640x480(RGB) buf->pts=9580000000ns 1.39ms real=9560937012ns redfilter: 640x480(RGB) buf->pts=9590000000ns 1.36ms real=9570771400ns redfilter: 640x480(RGB) buf->pts=9600000000ns 1.38ms real=9580576100ns redfilter: 640x480(RGB) buf->pts=9610000000ns 1.37ms real=9590676687ns redfilter: 640x480(RGB) buf->pts=9620000000ns 1.36ms real=9600544199ns redfilter: 640x480(RGB) buf->pts=9630000000ns 1.36ms real=9610577389ns redfilter: 640x480(RGB) buf->pts=9640000000ns 1.37ms real=9620691361ns redfilter: 640x480(RGB) buf->pts=9650000000ns 1.36ms real=9630505957ns redfilter: 640x480(RGB) buf->pts=9660000000ns 1.37ms real=9640425657ns handling interrupt.
The code for redfilter with RGB format is nearly trivial:Code: Select all
} else if (strcmp(fmt,"RGB")==0) { GstMapInfo info; guint8 *p; gst_buffer_map (buf, &info, GST_MAP_READWRITE); assert(w*h*3 == info.size); for(p=info.data+info.size; p>info.data; ) { *--p=0; // b *--p=0; // g --p; // r } assert(p==info.data); ...
P.S:
Below you can see redfilter in action with output on fbdevsink.
Before it was 31fps that was possible with v2 camera and redfilter, now it is 70fps(!) with this command:Code: Select all
$ raspividyuv -rgb -t 0 -md 7 -w 640 -h 480 -fps 70 -n -o - | GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0/ gst-launch-1.0 -v fdsrc ! queue ! "video/x-raw, width=640, height=480, format=RGB, framerate=70/1" ! rawvideoparse use-sink-caps=true ! redfilter ! videoconvert ! fbdevsink device=/dev/fb0
(screenshot was taken with raspi2png)
P.P.S:
In this thread we have seen gstreamer pipelines dealing with YUV/I420 and RGB formats.
In this posting you can see how to deal with gstreamer gray8 format data by raspividyuv "--luma" option (eg. for robot control, when color is not needed):
https://www.raspberrypi.org/forums/view ... 5#p1522575
P.P.P.S:
In case a gstreamer plugin like redfilter is used for robot control only, it might be better to create an appsink instead of a plugin like redfilter where fakesink is needed afterwards for cleanup.
This thread discussed how to create an appsrc that takes raspiraw stream and sends it into gstreamer pipeline, just the other way around:
https://www.raspberrypi.org/forums/view ... p?t=197124
The thermal warning only happened because the Pi3B had no heatsinks, no fan and did lie flat on the desktop.
That is OK.We made more experiments with OpenCV and it looks like this is the direction we are going to take.