5 package jp.nyatla.nyartoolkit.sandbox.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.rgb2gs.*;
24 import jp.nyatla.nyartoolkit.core2.rasterfilter.gs2bin.*;
25 import jp.nyatla.utils.j2se.LabelingBufferdImage;
26 import jp.nyatla.nyartoolkit.core.types.*;
27 import jp.nyatla.nyartoolkit.core2.rasteranalyzer.threshold.*;
31 public class SingleQrTest extends Frame implements JmfCaptureListener
33 private final String camera_file = "../../Data/camera_para.dat";
35 private JmfNyARRaster_RGB _raster;
37 private JmfCameraCapture capture;
39 public SingleQrTest() throws NyARException, NyARException
41 setBounds(0, 0, 640 + 64, 720 + 64);
43 capture = new JmfCameraCapture(320, 240, 30f, JmfCameraCapture.PIXEL_FORMAT_RGB);
44 capture.setCaptureListener(this);
47 this._raster = new JmfNyARRaster_RGB(320, 240);
51 ap.loadARParamFromFile(camera_file);
52 ap.changeScreenSize(320, 240);
57 private NyARBinRaster _binraster1 = new NyARBinRaster(320, 240);
59 private NyARGrayscaleRaster _gsraster1 = new NyARGrayscaleRaster(320, 240);
60 private INyARRasterThresholdAnalyzer _tha=new NyARRasterThresholdAnalyzer_DiffHistgram();
62 private LabelingBufferdImage _bimg = new LabelingBufferdImage(320, 240);
65 public void onUpdateBuffer(Buffer i_buffer)
69 // キャプチャしたバッファをラスタにセット
70 _raster.setBuffer(i_buffer);
72 Graphics g = getGraphics();
74 BufferToImage b2i = new BufferToImage((VideoFormat) i_buffer.getFormat());
75 Image img = b2i.createImage(i_buffer);
76 this.getGraphics().drawImage(img, 32, 32, this);
79 INyARRasterFilter_RgbToGs filter_rgb2gs = new NyARRasterFilter_RgbAve();
80 // INyARRasterFilter_RgbToGs filter_rgb2gs = new NyARRasterFilter_RgbMul();
82 filter_rgb2gs.doFilter(_raster, _gsraster1);
83 this._bimg.drawImage(this._gsraster1);
84 this.getGraphics().drawImage(this._bimg, 32 + 320, 32, 320 + 320 + 32, 240 + 32, 0, 240, 320, 0, this);
85 _tha.analyzeRaster(_gsraster1);
86 NyARRasterFilter_Threshold gs2bin=new NyARRasterFilter_Threshold(_tha.getThreshold());
90 gs2bin.doFilter(_gsraster1, _binraster1);
91 this._bimg.drawImage(_binraster1);
92 this.getGraphics().drawImage(this._bimg, 32, 32 + 240, 320 + 32, 240 + 32 + 240, 0, 240, 320, 0, this);
95 NyARLabelingImage limage = new NyARLabelingImage(320, 240);
96 NyARLabeling_ARToolKit labeling = new NyARLabeling_ARToolKit();
97 labeling.attachDestination(limage);
98 labeling.labeling(_binraster1);
99 this._bimg.drawImage(this._gsraster1);
101 NyARSquareStack stack = new NyARSquareStack(100);
102 NyARQrCodeDetector detect = new NyARQrCodeDetector(ap.getDistortionFactor(), new NyARIntSize(320,240));
103 // detect.bimg=this._bimg;
105 detect.detectMarker(_binraster1, stack);
106 for (int i = 0; i < stack.getLength(); i++) {
107 NyARSquare[] square_ptr = (NyARSquare[]) stack.getArray();
108 int d=square_ptr[i].direction;
111 for(int i2=0;i2<4;i2++){
112 xp[i2]=square_ptr[i].imvertex[(i2+d)%4].x;
113 yp[i2]=square_ptr[i].imvertex[(i2+d)%4].y;
115 Graphics g2=this._bimg.getGraphics();
116 g2.setColor(Color.RED);
117 g2.drawPolygon(xp, yp,3);
118 g2.setColor(Color.CYAN);
119 g2.drawRect(square_ptr[i].imvertex[d].x, square_ptr[i].imvertex[d].y,5,5);
121 this.getGraphics().drawImage(this._bimg, 32 + 320, 32 + 240, 320 + 32 + 320, 240 + 32 + 240, 0, 240, 320, 0, this);
124 // threshold.debugDrawHistgramMap(_workraster, _workraster2);
125 // this._bimg2.setImage(this._workraster2);
126 // this.getGraphics().drawImage(this._bimg2, 32+320, 32+240,320+32+320,240+32+240,0,240,320,0, this);
129 // NyARRasterThresholdAnalyzer_SlidePTile threshold=new NyARRasterThresholdAnalyzer_SlidePTile(15);
130 // threshold.analyzeRaster(_gsraster1);
131 // filter_gs2bin=new NyARRasterFilter_AreaAverage();
132 // filter_gs2bin.doFilter(_gsraster1, _binraster1);
133 // this._bimg.drawImage(_binraster1);
135 // NyARRasterDetector_QrCodeEdge detector=new NyARRasterDetector_QrCodeEdge(10000);
136 // detector.analyzeRaster(_binraster1);
138 // this._bimg.overlayData(detector.geResult());
140 // this.getGraphics().drawImage(this._bimg, 32, 32+480,320+32,480+32+240,0,240,320,0, this);
144 * threshold2.debugDrawHistgramMap(_workraster, _workraster2); this._bimg2.drawImage(this._workraster2); this.getGraphics().drawImage(this._bimg2,
145 * 32+320, 32+480,320+32+320,480+32+240,0,240,320,0, this);
148 // this.getGraphics().drawImage(this._bimg, 32, 32, this);
150 } catch (Exception e) {
156 private void startCapture()
160 } catch (Exception e) {
165 public static void main(String[] args)
168 SingleQrTest mainwin = new SingleQrTest();
169 mainwin.setVisible(true);
170 mainwin.startCapture();
171 } catch (Exception e) {