from fulguro import *
from fulguro.flgrrtcapture import *
size_x = 640
size_y = 480
cam0 = FLGR_RtCapture2D("/dev/video0")
cam0.set_palette("YV12")
cam0.set_size(size_x,size_y)
imin = FLGR_Data2D(size_y,size_x,1,FLGR_UINT8)
immir = FLGR_Data2D(imin)
imtmp1 = FLGR_Data2D(imin)
imtmp2 = FLGR_Data2D(imin)
imout = FLGR_Data2D(imin)
nhb = FLGR_Data2D(9,9,imin.spp,imin.type,FLGR_RECT,FLGR_8_CONNEX)
nhb2 = FLGR_Data2D(1,9,imin.spp,imin.type,FLGR_RECT,FLGR_8_CONNEX)
nhb3 = FLGR_Data2D(9,9,imin.spp,imin.type,FLGR_RECT,FLGR_8_CONNEX)
nhb4 = FLGR_Data2D(9,1,imin.spp,imin.type,FLGR_RECT,FLGR_8_CONNEX)
scr0 = flgr2d_rtview_create(immir, 1, 2)
for i in range(1000):
flgr2d_rtcapture_gray_image(imin, cam0)
flgr2d_copy(immir,imin)
flgr2d_open_tophat(imtmp1,immir,nhb)
flgr2d_close_tophat(imtmp2,immir,nhb)
flgr2d_arith_inf(imout,imtmp1,imtmp2)
flgr2d_replace(imout,imout,'>=',20,255,0)
flgr2d_close(imtmp1,imout,nhb2)
flgr2d_open(imout,imtmp1,nhb2)
flgr2d_dilate(imtmp1,imout,nhb3)
flgr2d_dilate(imout,imtmp1,nhb3)
flgr2d_dilate(imtmp1,imout,nhb3)
flgr2d_erode(imout,imtmp1,nhb3)
flgr2d_erode(imtmp1,imout,nhb3)
flgr2d_erode(imout,imtmp1,nhb3)
flgr2d_open(imtmp1,imout,nhb4)
flgr2d_replace(imout,imtmp1,'==',255,immir,0)
flgr2d_rtview_refresh(scr0, immir, 0, 0)
flgr2d_rtview_refresh(scr0, imout, 0, 1)