5 package jp.nyatla.nyartoolkit.toys.qrcode;
9 import javax.media.util.BufferToImage;
10 import javax.media.format.*;
12 import jp.nyatla.nyartoolkit.NyARException;
13 import jp.nyatla.nyartoolkit.jmf.utils.*;
15 import jp.nyatla.nyartoolkit.core.*;
19 import jp.nyatla.nyartoolkit.core.labeling.*;
20 import jp.nyatla.nyartoolkit.core.param.*;
21 import jp.nyatla.nyartoolkit.core.raster.*;
22 import jp.nyatla.nyartoolkit.core.rasterfilter.*;
23 import jp.nyatla.nyartoolkit.core2.rasterfilter.gs2bin.*;
24 import jp.nyatla.nyartoolkit.core2.rasterfilter.rgb2gs.*;
25 import jp.nyatla.utils.j2se.LabelingBufferdImage;
26 import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;
27 import jp.nyatla.nyartoolkit.core.types.*;
32 public class SingleQrTest extends Frame implements JmfCaptureListener
34 private final String camera_file = "../../Data/camera_para.dat";
36 private JmfNyARRaster_RGB _raster;
38 private JmfCameraCapture capture;
40 public SingleQrTest() throws NyARException, NyARException
42 setBounds(0, 0, 640 + 64, 720 + 64);
44 capture = new JmfCameraCapture(320, 240, 30f, JmfCameraCapture.PIXEL_FORMAT_RGB);
45 capture.setCaptureListener(this);
48 this._raster = new JmfNyARRaster_RGB(320, 240);
52 ap.loadARParamFromFile(camera_file);
53 ap.changeScreenSize(320, 240);
60 private NyARBinRaster _binraster1 = new NyARBinRaster(320, 240);
62 private NyARGrayscaleRaster _gsraster1 = new NyARGrayscaleRaster(320, 240);
65 private LabelingBufferdImage _bimg = new LabelingBufferdImage(320, 240);
68 public void onUpdateBuffer(Buffer i_buffer)
70 NyARRasterFilter_QrAreaAverage gs2bin=new NyARRasterFilter_QrAreaAverage();
73 // キャプチャしたバッファをラスタにセット
74 _raster.setBuffer(i_buffer);
76 Graphics g = getGraphics();
78 BufferToImage b2i = new BufferToImage((VideoFormat) i_buffer.getFormat());
79 Image img = b2i.createImage(i_buffer);
80 this.getGraphics().drawImage(img, 32, 32, this);
83 INyARRasterFilter_RgbToGs filter_rgb2gs = new NyARRasterFilter_RgbAve();
84 // INyARRasterFilter_RgbToGs filter_rgb2gs = new NyARRasterFilter_RgbMul();
86 filter_rgb2gs.doFilter(_raster, _gsraster1);
87 this._bimg.drawImage(this._gsraster1);
88 this.getGraphics().drawImage(this._bimg, 32 + 320, 32, 320 + 320 + 32, 240 + 32, 0, 240, 320, 0, this);
92 gs2bin.doFilter(_gsraster1, _binraster1);
93 this._bimg.drawImage(_binraster1);
94 this.getGraphics().drawImage(this._bimg, 32, 32 + 240, 320 + 32, 240 + 32 + 240, 0, 240, 320, 0, this);
97 NyARLabelingImage limage = new NyARLabelingImage(320, 240);
98 NyARLabeling_ARToolKit labeling = new NyARLabeling_ARToolKit();
99 labeling.attachDestination(limage);
100 labeling.labeling(_binraster1);
101 this._bimg.drawImage(this._gsraster1);
103 NyARSquareStack stack = new NyARSquareStack(100);
104 NyARQrCodeDetector detect = new NyARQrCodeDetector(ap.getDistortionFactor(), new NyARIntSize(320,240));
105 // detect.bimg=this._bimg;
107 detect.detectMarker(_binraster1, stack);
108 for (int i = 0; i < stack.getLength(); i++) {
109 NyARSquare[] square_ptr = (NyARSquare[]) stack.getArray();
110 int d=square_ptr[i].direction;
113 for(int i2=0;i2<4;i2++){
114 xp[i2]=square_ptr[i].imvertex[(i2+d)%4].x;
115 yp[i2]=square_ptr[i].imvertex[(i2+d)%4].y;
117 Graphics g2=this._bimg.getGraphics();
118 g2.setColor(Color.RED);
119 g2.drawPolygon(xp, yp,3);
120 g2.setColor(Color.CYAN);
121 g2.drawRect(square_ptr[i].imvertex[d].x, square_ptr[i].imvertex[d].y,5,5);
123 this.getGraphics().drawImage(this._bimg, 32 + 320, 32 + 240, 320 + 32 + 320, 240 + 32 + 240, 0, 240, 320, 0, this);
126 // threshold.debugDrawHistgramMap(_workraster, _workraster2);
127 // this._bimg2.setImage(this._workraster2);
128 // this.getGraphics().drawImage(this._bimg2, 32+320, 32+240,320+32+320,240+32+240,0,240,320,0, this);
131 // NyARRasterThresholdAnalyzer_SlidePTile threshold=new NyARRasterThresholdAnalyzer_SlidePTile(15);
132 // threshold.analyzeRaster(_gsraster1);
133 // filter_gs2bin=new NyARRasterFilter_AreaAverage();
134 // filter_gs2bin.doFilter(_gsraster1, _binraster1);
135 // this._bimg.drawImage(_binraster1);
137 // NyARRasterDetector_QrCodeEdge detector=new NyARRasterDetector_QrCodeEdge(10000);
138 // detector.analyzeRaster(_binraster1);
140 // this._bimg.overlayData(detector.geResult());
142 // this.getGraphics().drawImage(this._bimg, 32, 32+480,320+32,480+32+240,0,240,320,0, this);
146 * threshold2.debugDrawHistgramMap(_workraster, _workraster2); this._bimg2.drawImage(this._workraster2); this.getGraphics().drawImage(this._bimg2,
147 * 32+320, 32+480,320+32+320,480+32+240,0,240,320,0, this);
150 // this.getGraphics().drawImage(this._bimg, 32, 32, this);
152 } catch (Exception e) {
158 private INyARLabeling labelingFactory(int i_idx)
161 // case 0:{NyARLabeling_ARToolKit l=new NyARLabeling_ARToolKit();l.setThresh(4);return l;}
162 // case 1:{return new NyLineLabeling();}
168 private void startCapture()
172 } catch (Exception e) {
177 public static void main(String[] args)
180 SingleQrTest mainwin = new SingleQrTest();
181 mainwin.setVisible(true);
182 mainwin.startCapture();
183 } catch (Exception e) {