5 package jp.nyatla.nyartoolkit.sandbox.x2;
9 import javax.media.util.BufferToImage;
10 import javax.media.format.*;
12 import jp.nyatla.nyartoolkit.NyARException;
13 import jp.nyatla.nyartoolkit.jmf.utils.*;
14 import jp.nyatla.nyartoolkit.sandbox.quadx2.*;
16 import jp.nyatla.nyartoolkit.core.*;
20 import jp.nyatla.nyartoolkit.core.labeling.*;
21 import jp.nyatla.nyartoolkit.core.param.*;
22 import jp.nyatla.nyartoolkit.core.raster.*;
23 import jp.nyatla.nyartoolkit.core.rasterfilter.*;
24 import jp.nyatla.nyartoolkit.core2.rasterfilter.rgb2gs.*;
25 import jp.nyatla.nyartoolkit.core2.rasterfilter.gs2bin.*;
26 import jp.nyatla.utils.j2se.LabelingBufferdImage;
27 import jp.nyatla.nyartoolkit.core2.rasteranalyzer.threshold.*;
31 public class VisualTest extends Frame implements JmfCaptureListener
33 private final String camera_file = "../../Data/camera_para.dat";
35 private JmfNyARRaster_RGB _raster;
37 private JmfCaptureDevice capture;
39 public VisualTest() throws NyARException, NyARException
41 setBounds(0, 0, 640 + 64, 720 + 64);
43 JmfCaptureDeviceList list=new JmfCaptureDeviceList();
44 capture=list.getDevice(0);
45 capture.setCaptureFormat(320,240,30.0f);
46 capture.setOnCapture(this);
49 this._raster = new JmfNyARRaster_RGB(320, 240,capture.getCaptureFormat());
53 ap.loadARParamFromFile(camera_file);
54 ap.changeScreenSize(320, 240);
59 private NyARBinRaster _binraster1 = new NyARBinRaster(160,120);
61 private NyARGrayscaleRaster _gsraster1 = new NyARGrayscaleRaster(320, 240);
62 private INyARRasterThresholdAnalyzer _tha=new NyARRasterThresholdAnalyzer_DiffHistgram();
64 private LabelingBufferdImage _bimg = new LabelingBufferdImage(320, 240);
65 private LabelingBufferdImage _bimg2 = new LabelingBufferdImage(160, 120);
66 private NyARRasterFilter_ARTTh_Quad _tobin_filter=new NyARRasterFilter_ARTTh_Quad(100);
68 public void onUpdateBuffer(Buffer i_buffer)
72 // キャプチャしたバッファをラスタにセット
73 _raster.setBuffer(i_buffer);
75 Graphics g = getGraphics();
77 BufferToImage b2i = new BufferToImage((VideoFormat) i_buffer.getFormat());
78 Image img = b2i.createImage(i_buffer);
79 this.getGraphics().drawImage(img, 32, 32, this);
82 INyARRasterFilter_RgbToGs filter_rgb2gs = new NyARRasterFilter_RgbAve();
83 // INyARRasterFilter_RgbToGs filter_rgb2gs = new NyARRasterFilter_RgbMul();
85 filter_rgb2gs.doFilter(_raster, _gsraster1);
86 this._bimg.drawImage(this._gsraster1);
87 this.getGraphics().drawImage(this._bimg, 32 + 320, 32, 320 + 320 + 32, 240 + 32, 0, 240, 320, 0, this);
88 _tha.analyzeRaster(_gsraster1);
89 NyARRasterFilter_Threshold gs2bin=new NyARRasterFilter_Threshold(_tha.getThreshold());
93 _tobin_filter.doFilter(_raster, _binraster1);
94 this._bimg2.drawImage(_binraster1);
95 this.getGraphics().drawImage(this._bimg2, 32, 32 + 240, 320 + 32, 240 + 32 + 240, 0, 240, 320, 0, this);
98 NyARLabelingImage limage = new NyARLabelingImage(320, 240);
99 NyARLabeling_ARToolKit labeling = new NyARLabeling_ARToolKit();
100 labeling.attachDestination(limage);
101 labeling.labeling(_binraster1);
102 this._bimg.drawImage(this._gsraster1);
104 NyARSquareStack stack = new NyARSquareStack(100);
105 } catch (Exception e) {
111 private void startCapture()
115 } catch (Exception e) {
120 public static void main(String[] args)
123 VisualTest mainwin = new VisualTest();
124 mainwin.setVisible(true);
125 mainwin.startCapture();
126 } catch (Exception e) {