Previous topic

Saving images

Next topic

Calibration

This Page

Bilateral Filter ChainΒΆ

Chains together a bunch of Bilateral smoothing filters (http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html) and runs them on a live video device.

Download: bilateral.py

#!/usr/bin/env python
import ecto
from ecto_opencv.highgui import VideoCapture, FPSDrawer, imshow, ImageSaver
from ecto_opencv.imgproc import BilateralFilter

video_cap = VideoCapture(video_device=0)

fps = FPSDrawer()

video_display = imshow('imshow',
                      name='video_cap', triggers=dict(save=ord('s')),
                      )

saver = ecto.If(cell=ImageSaver('saver', filename_format='bilateral_%05d.jpg',
                                   start=1))

bl_begin = None
bl_end = None

plasm = ecto.Plasm()
#Build up a chain of bilateral filters.
for i in range(1, 10):
    next = BilateralFilter(d= -1, sigmaColor=10, sigmaSpace=5)
    if bl_begin == None: # beginning case
        bl_begin = next
        bl_end = next
        continue
    plasm.connect(bl_end[:] >> next[:])
    bl_end = next

plasm.connect(video_cap['image'] >> fps['image'],
              fps['image'] >> bl_begin[:],
              bl_end[:] >> (video_display['image'], saver['image']),
              video_display['save'] >> saver['__test__'],
              )

if __name__ == '__main__':
    from ecto.opts import doit
    doit(plasm, description='Run a chain of bilateral smoothing filters on a video stream.')

Produces output cartoonish output:

../_images/bilateral.png

digraph G {
graph [rankdir=TB, ranksep=1]
edge [labelfontsize=8]
node [shape=plaintext]
0[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i_image" BGCOLOR="springgreen">image</TD>
</TR> <TR> <TD ROWSPAN="3" COLSPAN="1" BGCOLOR="khaki">imgproc::Filter_&lt;imgproc::BilateralFilter&gt;</TD> <TD PORT="p_d" BGCOLOR="lightblue">d</TD>
 </TR> <TR> <TD PORT="p_sigmaColor" BGCOLOR="lightblue">sigmaColor</TD> </TR>
<TR> <TD PORT="p_sigmaSpace" BGCOLOR="lightblue">sigmaSpace</TD> </TR>
 <TR>
<TD PORT="o_image" BGCOLOR="indianred1">image</TD>
</TR> </TABLE>>];
1[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i_image" BGCOLOR="springgreen">image</TD>
</TR> <TR> <TD ROWSPAN="3" COLSPAN="1" BGCOLOR="khaki">imgproc::Filter_&lt;imgproc::BilateralFilter&gt;</TD> <TD PORT="p_d" BGCOLOR="lightblue">d</TD>
 </TR> <TR> <TD PORT="p_sigmaColor" BGCOLOR="lightblue">sigmaColor</TD> </TR>
<TR> <TD PORT="p_sigmaSpace" BGCOLOR="lightblue">sigmaSpace</TD> </TR>
 <TR>
<TD PORT="o_image" BGCOLOR="indianred1">image</TD>
</TR> </TABLE>>];
2[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i_image" BGCOLOR="springgreen">image</TD>
</TR> <TR> <TD ROWSPAN="3" COLSPAN="1" BGCOLOR="khaki">imgproc::Filter_&lt;imgproc::BilateralFilter&gt;</TD> <TD PORT="p_d" BGCOLOR="lightblue">d</TD>
 </TR> <TR> <TD PORT="p_sigmaColor" BGCOLOR="lightblue">sigmaColor</TD> </TR>
<TR> <TD PORT="p_sigmaSpace" BGCOLOR="lightblue">sigmaSpace</TD> </TR>
 <TR>
<TD PORT="o_image" BGCOLOR="indianred1">image</TD>
</TR> </TABLE>>];
3[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i_image" BGCOLOR="springgreen">image</TD>
</TR> <TR> <TD ROWSPAN="3" COLSPAN="1" BGCOLOR="khaki">imgproc::Filter_&lt;imgproc::BilateralFilter&gt;</TD> <TD PORT="p_d" BGCOLOR="lightblue">d</TD>
 </TR> <TR> <TD PORT="p_sigmaColor" BGCOLOR="lightblue">sigmaColor</TD> </TR>
<TR> <TD PORT="p_sigmaSpace" BGCOLOR="lightblue">sigmaSpace</TD> </TR>
 <TR>
<TD PORT="o_image" BGCOLOR="indianred1">image</TD>
</TR> </TABLE>>];
4[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i_image" BGCOLOR="springgreen">image</TD>
</TR> <TR> <TD ROWSPAN="3" COLSPAN="1" BGCOLOR="khaki">imgproc::Filter_&lt;imgproc::BilateralFilter&gt;</TD> <TD PORT="p_d" BGCOLOR="lightblue">d</TD>
 </TR> <TR> <TD PORT="p_sigmaColor" BGCOLOR="lightblue">sigmaColor</TD> </TR>
<TR> <TD PORT="p_sigmaSpace" BGCOLOR="lightblue">sigmaSpace</TD> </TR>
 <TR>
<TD PORT="o_image" BGCOLOR="indianred1">image</TD>
</TR> </TABLE>>];
5[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i_image" BGCOLOR="springgreen">image</TD>
</TR> <TR> <TD ROWSPAN="3" COLSPAN="1" BGCOLOR="khaki">imgproc::Filter_&lt;imgproc::BilateralFilter&gt;</TD> <TD PORT="p_d" BGCOLOR="lightblue">d</TD>
 </TR> <TR> <TD PORT="p_sigmaColor" BGCOLOR="lightblue">sigmaColor</TD> </TR>
<TR> <TD PORT="p_sigmaSpace" BGCOLOR="lightblue">sigmaSpace</TD> </TR>
 <TR>
<TD PORT="o_image" BGCOLOR="indianred1">image</TD>
</TR> </TABLE>>];
6[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i_image" BGCOLOR="springgreen">image</TD>
</TR> <TR> <TD ROWSPAN="3" COLSPAN="1" BGCOLOR="khaki">imgproc::Filter_&lt;imgproc::BilateralFilter&gt;</TD> <TD PORT="p_d" BGCOLOR="lightblue">d</TD>
 </TR> <TR> <TD PORT="p_sigmaColor" BGCOLOR="lightblue">sigmaColor</TD> </TR>
<TR> <TD PORT="p_sigmaSpace" BGCOLOR="lightblue">sigmaSpace</TD> </TR>
 <TR>
<TD PORT="o_image" BGCOLOR="indianred1">image</TD>
</TR> </TABLE>>];
7[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i_image" BGCOLOR="springgreen">image</TD>
</TR> <TR> <TD ROWSPAN="3" COLSPAN="1" BGCOLOR="khaki">imgproc::Filter_&lt;imgproc::BilateralFilter&gt;</TD> <TD PORT="p_d" BGCOLOR="lightblue">d</TD>
 </TR> <TR> <TD PORT="p_sigmaColor" BGCOLOR="lightblue">sigmaColor</TD> </TR>
<TR> <TD PORT="p_sigmaSpace" BGCOLOR="lightblue">sigmaSpace</TD> </TR>
 <TR>
<TD PORT="o_image" BGCOLOR="indianred1">image</TD>
</TR> </TABLE>>];
8[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i_image" BGCOLOR="springgreen">image</TD>
</TR> <TR> <TD ROWSPAN="3" COLSPAN="1" BGCOLOR="khaki">imgproc::Filter_&lt;imgproc::BilateralFilter&gt;</TD> <TD PORT="p_d" BGCOLOR="lightblue">d</TD>
 </TR> <TR> <TD PORT="p_sigmaColor" BGCOLOR="lightblue">sigmaColor</TD> </TR>
<TR> <TD PORT="p_sigmaSpace" BGCOLOR="lightblue">sigmaSpace</TD> </TR>
 <TR>
<TD PORT="o_image" BGCOLOR="indianred1">image</TD>
</TR> </TABLE>>];
9[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">  <TR> <TD ROWSPAN="4" COLSPAN="2" BGCOLOR="khaki">ecto_opencv::VideoCapture</TD> <TD PORT="p_height" BGCOLOR="lightblue">height</TD>
 </TR> <TR> <TD PORT="p_video_device" BGCOLOR="lightblue">video_device</TD> </TR>
<TR> <TD PORT="p_video_file" BGCOLOR="lightblue">video_file</TD> </TR>
<TR> <TD PORT="p_width" BGCOLOR="lightblue">width</TD> </TR>
 <TR>
<TD PORT="o_frame_number" BGCOLOR="indianred1">frame_number</TD>
<TD PORT="o_image" BGCOLOR="indianred1">image</TD>
</TR> </TABLE>>];
10[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i_image" BGCOLOR="springgreen">image</TD>
</TR> <TR> <TD ROWSPAN="1" COLSPAN="1" BGCOLOR="khaki">ecto_opencv::FPSDrawer</TD>  </TR>  <TR>
<TD PORT="o_image" BGCOLOR="indianred1">image</TD>
</TR> </TABLE>>];
11[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i_image" BGCOLOR="springgreen">image</TD>
</TR> <TR> <TD ROWSPAN="5" COLSPAN="1" BGCOLOR="khaki">imshow</TD> <TD PORT="p_autoSize" BGCOLOR="lightblue">autoSize</TD>
 </TR> <TR> <TD PORT="p_maximize" BGCOLOR="lightblue">maximize</TD> </TR>
<TR> <TD PORT="p_name" BGCOLOR="lightblue">name</TD> </TR>
<TR> <TD PORT="p_triggers" BGCOLOR="lightblue">triggers</TD> </TR>
<TR> <TD PORT="p_waitKey" BGCOLOR="lightblue">waitKey</TD> </TR>
 <TR>
<TD PORT="o_save" BGCOLOR="indianred1">save</TD>
</TR> </TABLE>>];
12[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i___test__" BGCOLOR="springgreen">__test__</TD>
<TD PORT="i_filename" BGCOLOR="springgreen">filename</TD>
<TD PORT="i_image" BGCOLOR="springgreen">image</TD>
</TR> <TR> <TD ROWSPAN="1" COLSPAN="3" BGCOLOR="khaki">ecto::If</TD> <TD PORT="p_cell" BGCOLOR="lightblue">cell</TD>
 </TR>  <TR>
<TD PORT="o_filename" BGCOLOR="indianred1">filename</TD>
</TR> </TABLE>>];
0->1 [headport="i_image" tailport="o_image"];
1->2 [headport="i_image" tailport="o_image"];
2->3 [headport="i_image" tailport="o_image"];
3->4 [headport="i_image" tailport="o_image"];
4->5 [headport="i_image" tailport="o_image"];
5->6 [headport="i_image" tailport="o_image"];
6->7 [headport="i_image" tailport="o_image"];
7->8 [headport="i_image" tailport="o_image"];
9->10 [headport="i_image" tailport="o_image"];
10->0 [headport="i_image" tailport="o_image"];
8->11 [headport="i_image" tailport="o_image"];
8->12 [headport="i_image" tailport="o_image"];
11->12 [headport="i___test__" tailport="o_save"];
}