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.*;
15 import jp.nyatla.nyartoolkit.utils.j2se.LabelingBufferdImage;
17 import jp.nyatla.nyartoolkit.core.*;
21 import jp.nyatla.nyartoolkit.core.analyzer.raster.threshold.INyARRasterThresholdAnalyzer;
22 import jp.nyatla.nyartoolkit.core.labeling.*;
23 import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingImage;
24 import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabeling_ARToolKit;
25 import jp.nyatla.nyartoolkit.core.param.*;
26 import jp.nyatla.nyartoolkit.core.raster.*;
27 import jp.nyatla.nyartoolkit.core.rasteranalyzer.threshold.NyARRasterThresholdAnalyzer_DiffHistogram;
28 import jp.nyatla.nyartoolkit.core.rasterfilter.*;
29 import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2gs.INyARRasterFilter_Rgb2Gs;
30 import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareStack;
31 import jp.nyatla.nyartoolkit.core2.rasterfilter.rgb2gs.*;
32 import jp.nyatla.nyartoolkit.core2.rasterfilter.gs2bin.*;
33 import jp.nyatla.nyartoolkit.core2.rasteranalyzer.threshold.*;
37 public class VisualTest extends Frame implements JmfCaptureListener
39 private final String camera_file = "../../Data/camera_para.dat";
41 private JmfNyARRaster_RGB _raster;
43 private JmfCaptureDevice capture;
45 public VisualTest() throws NyARException, NyARException
47 setBounds(0, 0, 640 + 64, 720 + 64);
49 JmfCaptureDeviceList list=new JmfCaptureDeviceList();
50 capture=list.getDevice(0);
51 capture.setCaptureFormat(320,240,30.0f);
52 capture.setOnCapture(this);
55 this._raster = new JmfNyARRaster_RGB(320, 240,capture.getCaptureFormat());
59 ap.loadARParamFromFile(camera_file);
60 ap.changeScreenSize(320, 240);
65 private NyARBinRaster _binraster1 = new NyARBinRaster(160,120);
67 private NyARGrayscaleRaster _gsraster1 = new NyARGrayscaleRaster(320, 240);
68 private INyARRasterThresholdAnalyzer _tha=new NyARRasterThresholdAnalyzer_DiffHistogram();
70 private LabelingBufferdImage _bimg = new LabelingBufferdImage(320, 240);
71 private LabelingBufferdImage _bimg2 = new LabelingBufferdImage(160, 120);
72 private NyARRasterFilter_ARTTh_Quad _tobin_filter=new NyARRasterFilter_ARTTh_Quad(100);
74 public void onUpdateBuffer(Buffer i_buffer)
78 // キャプチャしたバッファをラスタにセット
79 _raster.setBuffer(i_buffer);
81 Graphics g = getGraphics();
83 BufferToImage b2i = new BufferToImage((VideoFormat) i_buffer.getFormat());
84 Image img = b2i.createImage(i_buffer);
85 this.getGraphics().drawImage(img, 32, 32, this);
88 INyARRasterFilter_Rgb2Gs filter_rgb2gs = new NyARRasterFilter_RgbAve();
89 // INyARRasterFilter_RgbToGs filter_rgb2gs = new NyARRasterFilter_RgbMul();
91 filter_rgb2gs.doFilter(_raster, _gsraster1);
92 this._bimg.drawImage(this._gsraster1);
93 this.getGraphics().drawImage(this._bimg, 32 + 320, 32, 320 + 320 + 32, 240 + 32, 0, 240, 320, 0, this);
94 _tha.analyzeRaster(_gsraster1);
95 NyARRasterFilter_Threshold gs2bin=new NyARRasterFilter_Threshold(_tha.getThreshold());
99 _tobin_filter.doFilter(_raster, _binraster1);
100 this._bimg2.drawImage(_binraster1);
101 this.getGraphics().drawImage(this._bimg2, 32, 32 + 240, 320 + 32, 240 + 32 + 240, 0, 240, 320, 0, this);
104 NyARLabelingImage limage = new NyARLabelingImage(320, 240);
105 NyARLabeling_ARToolKit labeling = new NyARLabeling_ARToolKit();
106 labeling.labeling(_binraster1,limage);
107 this._bimg.drawImage(this._gsraster1);
109 NyARSquareStack stack = new NyARSquareStack(100);
110 } catch (Exception e) {
116 private void startCapture()
120 } catch (Exception e) {
125 public static void main(String[] args)
128 VisualTest mainwin = new VisualTest();
129 mainwin.setVisible(true);
130 mainwin.startCapture();
131 } catch (Exception e) {