--- /dev/null
+package jp.nyatla.nyartoolkit.rpf.sample;\r
+\r
+import java.awt.*;\r
+import java.awt.event.MouseEvent;\r
+import java.awt.event.MouseListener;\r
+import java.awt.image.*;\r
+import java.io.File;\r
+import java.io.IOException;\r
+\r
+import javax.imageio.ImageIO;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
+import jp.nyatla.nyartoolkit.core.raster.NyARGrayscaleRaster;\r
+import jp.nyatla.nyartoolkit.core.raster.rgb.NyARRgbRaster;\r
+import jp.nyatla.nyartoolkit.core.types.NyARBufferType;\r
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;\r
+import jp.nyatla.nyartoolkit.core.types.NyARIntPoint2d;\r
+import jp.nyatla.nyartoolkit.core.types.NyARIntRect;\r
+import jp.nyatla.nyartoolkit.rpf.mklib.ARTKMarkerTable;\r
+import jp.nyatla.nyartoolkit.rpf.reality.nyartk.NyARReality;\r
+import jp.nyatla.nyartoolkit.rpf.reality.nyartk.NyARRealityTarget;\r
+import jp.nyatla.nyartoolkit.rpf.reality.nyartk.NyARRealityTargetList;\r
+import jp.nyatla.nyartoolkit.rpf.realitysource.nyartk.NyARRealitySource;\r
+import jp.nyatla.nyartoolkit.rpf.realitysource.nyartk.NyARRealitySource_JavaImage;\r
+import jp.nyatla.nyartoolkit.rpf.realitysource.nyartk.NyARRealitySource_Jmf;\r
+import jp.nyatla.nyartoolkit.rpf.tracker.nyartk.status.NyARRectTargetStatus;\r
+import jp.nyatla.nyartoolkit.rpf.tracker.nyartk.status.NyARTargetStatus;\r
+import jp.nyatla.nyartoolkit.jmf.utils.*;\r
+import jp.nyatla.nyartoolkit.utils.j2se.*;\r
+\r
+\r
+\r
+\r
+\r
+/**\r
+ * NyARRealityのテストプログラム。動作保証なし。\r
+ *\r
+ */\r
+\r
+public class Test_RealityTarget extends Frame implements MouseListener\r
+{\r
+ /**\r
+ * 出力ソース\r
+ * @author nyatla\r
+ */\r
+ class InputSource\r
+ {\r
+ public NyARRealitySource reality_in;\r
+ }\r
+\r
+ class ImageSource extends InputSource\r
+ {\r
+ public ImageSource(String i_filename) throws NyARException, IOException\r
+ {\r
+ BufferedImage _src_image;\r
+ _src_image = ImageIO.read(new File(i_filename));\r
+ NyARRealitySource_JavaImage ri=new NyARRealitySource_JavaImage(_src_image.getWidth(),_src_image.getHeight(),null,2,100);\r
+ ri.getBufferedImage().getGraphics().drawImage(_src_image,0,0,null);\r
+ this.reality_in=ri;\r
+ }\r
+ }\r
+\r
+ class LiveSource extends InputSource implements JmfCaptureListener\r
+ {\r
+ private JmfCaptureDevice _capture;\r
+ public LiveSource() throws NyARException\r
+ {\r
+ //キャプチャの準備\r
+ JmfCaptureDeviceList devlist=new JmfCaptureDeviceList();\r
+ this._capture=devlist.getDevice(0);\r
+ //JmfNyARRaster_RGBはYUVよりもRGBで高速に動作します。\r
+ if(!this._capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB,320, 240,15f)){\r
+ if(!this._capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_YUV,320, 240,15f)){\r
+ throw new NyARException("キャプチャフォーマットが見つかりません");\r
+ } \r
+ }\r
+ this._capture.setOnCapture(this);\r
+ this._capture.start();\r
+ this.reality_in=new NyARRealitySource_Jmf(this._capture.getCaptureFormat(),null,2,100);\r
+ return;\r
+ \r
+ }\r
+ \r
+ public void onUpdateBuffer(javax.media.Buffer i_buffer)\r
+ {\r
+ try {\r
+ //キャプチャしたバッファをラスタにセット\r
+ synchronized(this.reality_in){\r
+ ((NyARRealitySource_Jmf)(this.reality_in)).setImage(i_buffer);\r
+ }\r
+ //キャプチャしたイメージを表示用に加工\r
+ }catch(Exception e)\r
+ {\r
+ e.printStackTrace();\r
+ }\r
+\r
+ }\r
+\r
+ public void startCapture()\r
+ {\r
+ try {\r
+ this._capture.start();\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ }\r
+ \r
+ public void mouseClicked(MouseEvent e)\r
+ {\r
+ try {\r
+ int x=e.getX()-this.getInsets().left;\r
+ int y=e.getY()-this.getInsets().top;\r
+ System.out.println(x+":"+y);\r
+ synchronized(this._input_source.reality_in)\r
+ {\r
+ NyARBufferedImageRaster bmp= new NyARBufferedImageRaster(100,100,NyARBufferType.BYTE1D_R8G8B8_24);\r
+ for(int i=this._reality.refTargetList().getLength()-1;i>=0;i--)\r
+ {\r
+ NyARRealityTarget rt=this._reality.refTargetList().getItem(i);\r
+ if(rt._target_type!=NyARRealityTarget.RT_UNKNOWN && rt._target_type!=NyARRealityTarget.RT_KNOWN){\r
+ continue;\r
+ }\r
+ if(rt.isInnerVertexPoint2d(x, y))\r
+ {\r
+ if(e.getButton()==MouseEvent.BUTTON1){\r
+ //左ボタンはUNKNOWN→KNOWN\r
+ if(rt._target_type==NyARRealityTarget.RT_UNKNOWN){\r
+ ARTKMarkerTable.GetBestMatchTargetResult r=new ARTKMarkerTable.GetBestMatchTargetResult();\r
+ if(this._mklib.getBestMatchTarget(rt,this._input_source.reality_in,r)){\r
+ this._reality.changeTargetToKnown(rt,r.artk_direction,80);\r
+ }\r
+ //イメージピックアップの実験\r
+ NyARIntPoint2d[] iv=NyARIntPoint2d.createArray(4);\r
+ for(int i2=0;i2<4;i2++){\r
+ iv[i2].x=(int)rt.refTargetVertex()[i2].x;\r
+ iv[i2].y=(int)rt.refTargetVertex()[i2].y;\r
+ }\r
+ System.out.println(">>");\r
+ NyARRgbRaster rgb=new NyARRgbRaster(320,240,NyARBufferType.BYTE1D_R8G8B8_24);\r
+ //2d座標系\r
+ {\r
+ this._reality.getRgbPatt2d(this._input_source.reality_in,rt.refTargetVertex(),1,bmp);\r
+ this.getGraphics().drawImage(bmp.getBufferedImage(),this.getInsets().left,this.getInsets().top+240,null);\r
+ }\r
+ //3d(カメラ)\r
+ {\r
+ NyARDoublePoint3d[] p=NyARDoublePoint3d.createArray(4);\r
+ p[3].x=-40;p[3].y=-40;p[3].z=0;\r
+ p[2].x=40; p[2].y=-40;p[2].z=0;\r
+ p[1].x=40; p[1].y=40 ;p[1].z=0;\r
+ p[0].x=-40;p[0].y=40 ;p[0].z=0;\r
+ this._reality.getRgbPatt3d(this._input_source.reality_in,p, rt.refTransformMatrix(), 1, bmp);\r
+ this.getGraphics().drawImage(bmp.getBufferedImage(),this.getInsets().left+100,this.getInsets().top+240,null);\r
+ }\r
+ //3d(Target)\r
+ {\r
+ NyARDoublePoint3d[] p=NyARDoublePoint3d.createArray(4);\r
+ p[3].x=-40;p[3].y=-40;p[3].z=0;\r
+ p[2].x=40; p[2].y=-40;p[2].z=0;\r
+ p[1].x=40; p[1].y=40 ;p[1].z=0;\r
+ p[0].x=-80;p[0].y=40 ;p[0].z=0;\r
+ rt.getRgbPatt3d(this._input_source.reality_in,p,null, 1, bmp);\r
+ this.getGraphics().drawImage(bmp.getBufferedImage(),this.getInsets().left+200,this.getInsets().top+240,null);\r
+ }\r
+ //3d(Target)\r
+ {\r
+ rt.getRgbRectPatt3d(this._input_source.reality_in,-80,-80,80,80,1, bmp);\r
+ this.getGraphics().drawImage(bmp.getBufferedImage(),this.getInsets().left+300,this.getInsets().top+240,null);\r
+ }\r
+ break;\r
+ }\r
+ }else if(e.getButton()==MouseEvent.BUTTON3){\r
+ //右ボタンはUNKNOWN or KNOWN to dead\r
+ try {\r
+ this._reality.changeTargetToDead(rt);\r
+ break;\r
+ } catch (NyARException e1) {\r
+ // TODO Auto-generated catch block\r
+ e1.printStackTrace();\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ } catch (NyARException e1) {\r
+ // TODO Auto-generated catch block\r
+ e1.printStackTrace();\r
+ }\r
+ }\r
+ public void mouseEntered(MouseEvent e){}\r
+ public void mouseExited(MouseEvent e){}\r
+ public void mousePressed(MouseEvent e){}\r
+ public void mouseReleased(MouseEvent e){}\r
+ ARTKMarkerTable _mklib; \r
+ \r
+ \r
+ private NyARReality _reality;\r
+\r
+ \r
+ \r
+ NyARParam _param;\r
+ \r
+ private final static String SAMPLE_FILES = "../Data/320x240ABGR.png";\r
+ private final static String PARAM_FILE = "../Data/camera_para.dat";\r
+\r
+ private static final long serialVersionUID = -2110888320986446576L;\r
+\r
+\r
+ private int W = 320;\r
+ private int H = 240;\r
+ InputSource _input_source;\r
+ public Test_RealityTarget() throws NyARException, Exception\r
+ {\r
+ setTitle("NyARReality test");\r
+ Insets ins = this.getInsets();\r
+ this.setSize(1024 + ins.left + ins.right, 768 + ins.top + ins.bottom);\r
+ this._param=new NyARParam();\r
+ this._param.loadARParamFromFile(PARAM_FILE);\r
+ this._param.changeScreenSize(W,H);\r
+ this._reality=new NyARReality(this._param.getScreenSize(),10,1000,this._param.getPerspectiveProjectionMatrix(),null,10,10);\r
+// this._input_source=new LiveSource();\r
+ this._input_source=new ImageSource(SAMPLE_FILES);\r
+ addMouseListener(this);\r
+ this._mklib= new ARTKMarkerTable(10,16,16,25,25,4);\r
+ this._mklib.addMarkerFromARPattFile(PATT_HIRO,0,"HIRO",80,80);\r
+ return;\r
+ } \r
+\r
+ public void update()\r
+ {\r
+ try {\r
+ // マーカーを検出\r
+ Thread.sleep(30);\r
+ synchronized(this._input_source.reality_in){\r
+// Date d2 = new Date();\r
+// for (int i = 0; i < 1000; i++) {\r
+ this._reality.progress(this._input_source.reality_in); \r
+// }\r
+// Date d = new Date();\r
+// System.out.println(d.getTime() - d2.getTime());\r
+ }\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ BufferedImage _tmp_bf=new BufferedImage(320,240,BufferedImage.TYPE_INT_RGB);\r
+ private void draw(Graphics ig) throws NyARException\r
+ {\r
+ //ウインドウの情報\r
+ Insets ins = this.getInsets();\r
+\r
+ //ワーク画面\r
+ BufferedImage bmp=this._tmp_bf;\r
+ Graphics g=bmp.getGraphics();\r
+ NyARRasterImageIO.copy(this._input_source.reality_in.refRgbSource(),bmp);\r
+ \r
+ //Ignore,Coord,New\r
+\r
+ //表示\r
+ g.setColor(Color.black);\r
+ g.drawString("Unknown:"+this._reality.getNumberOfUnknown(),200,200);\r
+ g.drawString("Known:"+this._reality.getNumberOfKnown(),200,210);\r
+ g.drawString("Dead:"+this._reality.getNumberOfDead(),200,220);\r
+ NyARRealityTargetList tl=this._reality.refTargetList();\r
+ for(int i=tl.getLength()-1;i>=0;i--){\r
+ NyARRealityTarget t=tl.getItem(i);\r
+ switch(t.getTargetType())\r
+ {\r
+ case NyARRealityTarget.RT_KNOWN:\r
+ drawKnownRT(g,t);\r
+ break;\r
+ case NyARRealityTarget.RT_UNKNOWN: \r
+ drawUnKnownRT(g,t);\r
+ break;\r
+ default:\r
+ drawDeadRT(g,t);\r
+ break;\r
+ }\r
+ } \r
+ ig.drawImage(bmp,ins.left,ins.top,null);\r
+ \r
+\r
+ drawImage(ig,ins.left+320,ins.top,this._input_source.reality_in.refLastTrackSource().refEdgeRaster());\r
+ //\r
+\r
+ }\r
+\r
+ \r
+ private void drawImage(Graphics g,int x,int y,NyARGrayscaleRaster r) throws NyARException\r
+ {\r
+ BufferedImage _tmp_bf=new BufferedImage(r.getWidth(),r.getHeight(),BufferedImage.TYPE_INT_RGB);\r
+ NyARRasterImageIO.copy(r, _tmp_bf);\r
+ g.drawImage(_tmp_bf, x,y, null);\r
+ \r
+ }\r
+ //\r
+ //描画関数\r
+ //\r
+ private void drawKnownRT(Graphics g,NyARRealityTarget t)\r
+ {\r
+ g.setColor(Color.GREEN);\r
+ NyARIntPoint2d b=new NyARIntPoint2d();\r
+ t.getTargetCenter(b);\r
+ NyARIntRect r=t._ref_tracktarget._sample_area;\r
+ g.drawString("[K]("+t.grab_rate+")",b.x,b.y);\r
+ g.drawRect(r.x,r.y, r.w,r.h);\r
+ if(t._ref_tracktarget._st_type==NyARTargetStatus.ST_RECT){\r
+ g.drawString(">"+((NyARRectTargetStatus)(t._ref_tracktarget._ref_status)).detect_type,r.x,r.y+10);\r
+ }else{\r
+ }\r
+ }\r
+ private void drawUnKnownRT(Graphics g,NyARRealityTarget t)\r
+ {\r
+ g.setColor(Color.YELLOW);\r
+ NyARIntPoint2d b=new NyARIntPoint2d();\r
+ t.getTargetCenter(b);\r
+ NyARIntRect r=t._ref_tracktarget._sample_area;\r
+ g.drawString("[U]("+t.grab_rate+")",b.x,b.y);\r
+ g.drawRect(r.x,r.y, r.w,r.h);\r
+ }\r
+ private void drawDeadRT(Graphics g,NyARRealityTarget t)\r
+ {\r
+ g.setColor(Color.RED);\r
+ NyARIntRect r=t._ref_tracktarget._sample_area;\r
+ g.drawString("[D]("+t.grab_rate+")",r.x,r.y);\r
+ }\r
+ \r
+ private final static String PATT_HIRO = "../Data/patt.hiro";\r
+ \r
+\r
+\r
+ public void mainloop() throws Exception\r
+ {\r
+ for(;;){\r
+ //処理\r
+ this.update();\r
+ this.draw(this.getGraphics());\r
+ }\r
+ }\r
+\r
+ public static void main(String[] args)\r
+ {\r
+\r
+ try {\r
+ Test_RealityTarget mainwin = new Test_RealityTarget();\r
+ mainwin.setVisible(true);\r
+ mainwin.mainloop();\r
+ // mainwin.startImage();\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+}\r
+\r
--- /dev/null
+package jp.nyatla.nyartoolkit.rpf.sample;\r
+\r
+import java.awt.*;\r
+import java.awt.color.*;\r
+import java.awt.event.*;\r
+import java.awt.image.*;\r
+import java.io.*;\r
+import java.util.ArrayList;\r
+import java.util.Date;\r
+\r
+import javax.imageio.ImageIO;\r
+import javax.media.Buffer;\r
+import javax.media.format.VideoFormat;\r
+import javax.media.util.BufferToImage;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.labeling.rlelabeling.NyARLabeling_Rle;\r
+import jp.nyatla.nyartoolkit.core.labeling.rlelabeling.NyARRleLabelFragmentInfo;\r
+import jp.nyatla.nyartoolkit.core.labeling.rlelabeling.NyARRleLabelFragmentInfoPtrStack;\r
+import jp.nyatla.nyartoolkit.core.param.NyARCameraDistortionFactor;\r
+import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
+import jp.nyatla.nyartoolkit.core.raster.INyARRaster;\r
+import jp.nyatla.nyartoolkit.core.raster.NyARGrayscaleRaster;\r
+import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2gs.NyARRasterFilter_Rgb2Gs_RgbAve;\r
+import jp.nyatla.nyartoolkit.utils.j2se.NyARBufferedImageRaster;\r
+import jp.nyatla.nyartoolkit.utils.j2se.NyARRasterImageIO;\r
+import jp.nyatla.nyartoolkit.core.types.*;\r
+\r
+\r
+import jp.nyatla.nyartoolkit.core.raster.rgb.INyARRgbRaster;\r
+import jp.nyatla.nyartoolkit.core.raster.rgb.NyARRgbRaster_RGB;\r
+//import jp.nyatla.nyartoolkit.dev.hierarchicallabeling.tracking.AreaTargetSrcHolder.AreaSrcItem;\r
+import jp.nyatla.nyartoolkit.rpf.sampler.lrlabel.*;\r
+import jp.nyatla.nyartoolkit.rpf.tracker.nyartk.NyARTarget;\r
+import jp.nyatla.nyartoolkit.rpf.tracker.nyartk.NyARTracker;\r
+import jp.nyatla.nyartoolkit.rpf.tracker.nyartk.NyARTrackerSource_Reference;\r
+import jp.nyatla.nyartoolkit.rpf.tracker.nyartk.status.NyARContourTargetStatus;\r
+import jp.nyatla.nyartoolkit.rpf.tracker.nyartk.status.NyARRectTargetStatus;\r
+import jp.nyatla.nyartoolkit.rpf.tracker.nyartk.status.NyARTargetStatus;\r
+import jp.nyatla.nyartoolkit.rpf.utils.VecLinearCoordinatesOperator;\r
+import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureDevice;\r
+import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureDeviceList;\r
+import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureListener;\r
+import jp.nyatla.nyartoolkit.jmf.utils.JmfNyARRaster_RGB;\r
+\r
+\r
+\r
+\r
+\r
+\r
+/**\r
+ * Trackerの実験用プログラム。未保証。\r
+ *\r
+ */\r
+\r
+public class Test_TrackTerget extends Frame\r
+{\r
+ /**\r
+ * 出力ソース\r
+ * @author nyatla\r
+ */\r
+ interface InputSource\r
+ {\r
+ public void UpdateInput(NyARTrackerSource_Reference o_input) throws NyARException;\r
+ }\r
+\r
+ class ImageSource implements InputSource\r
+ {\r
+ private NyARBufferedImageRaster _src_image;\r
+ NyARGrayscaleRaster gs;\r
+ NyARRasterFilter_Rgb2Gs_RgbAve filter;\r
+\r
+ public ImageSource(String i_filename) throws IOException, NyARException\r
+ {\r
+ this._src_image=new NyARBufferedImageRaster(ImageIO.read(new File(i_filename)));\r
+ this.gs=new NyARGrayscaleRaster(this._src_image.getWidth(),this._src_image.getHeight());\r
+ this.filter=new NyARRasterFilter_Rgb2Gs_RgbAve(this._src_image.getBufferType());\r
+ }\r
+ public void UpdateInput(NyARTrackerSource_Reference o_input) throws NyARException\r
+ {\r
+ //GS値化\r
+ this.filter.doFilter(this._src_image,gs);\r
+ //samplerへ入力\r
+ o_input.wrapBuffer(gs);\r
+ \r
+ }\r
+ }\r
+ class MoveSource implements InputSource\r
+ {\r
+ private BufferedImage _src_image=new BufferedImage(320,240,BufferedImage.TYPE_INT_RGB);\r
+ private int sx,sy,x,y;\r
+ private int sx2,sy2,x2,y2;\r
+\r
+ public MoveSource()\r
+ {\r
+ sx=1;sy=1;x=10;y=10;\r
+ sx2=-2;sy2=1;x2=100;y2=10;\r
+ }\r
+ public void UpdateInput(NyARTrackerSource_Reference o_input) throws NyARException\r
+ {\r
+ Graphics s=_src_image.getGraphics();\r
+ s.setColor(Color.white);\r
+ s.fillRect(0,0,320,240);\r
+ s.setColor(Color.black);\r
+ //s.fillRect(x, y,50,50);\r
+ s.fillRect(x2, y2,50,50);\r
+ x+=sx;y+=sy;\r
+ if(x<0 || x>200){sx*=-1;}if(y<0 || y>200){sy*=-1;}\r
+ x2+=sx2;y2+=sy2;\r
+ if(x2<0 || x2>200){sx2*=-1;}if(y2<0 || y2>200){sy2*=-1;}\r
+ INyARRgbRaster ra =new NyARRgbRaster_RGB(320,240);\r
+ NyARRasterImageIO.copy(_src_image, ra);\r
+ //GS値化\r
+ NyARGrayscaleRaster gs=new NyARGrayscaleRaster(320,240);\r
+ NyARRasterFilter_Rgb2Gs_RgbAve filter=new NyARRasterFilter_Rgb2Gs_RgbAve(ra.getBufferType());\r
+ filter.doFilter(ra,gs);\r
+ //samplerへ入力\r
+ o_input.wrapBuffer(gs);\r
+ \r
+ }\r
+ }\r
+\r
+ class LiveSource implements InputSource,JmfCaptureListener\r
+ {\r
+ public LiveSource(int W,int H) throws NyARException\r
+ {\r
+ //キャプチャの準備\r
+ JmfCaptureDeviceList devlist=new JmfCaptureDeviceList();\r
+ this._capture=devlist.getDevice(0);\r
+ //JmfNyARRaster_RGBはYUVよりもRGBで高速に動作します。\r
+ if(!this._capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB,W, H,30f)){\r
+ if(!this._capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_YUV,W,H,30f)){\r
+ throw new NyARException("キャプチャフォーマットが見つかりません");\r
+ } \r
+ }\r
+ this._capture.setOnCapture(this);\r
+ this._raster = new JmfNyARRaster_RGB(this._capture.getCaptureFormat());\r
+ this._filter = new NyARRasterFilter_Rgb2Gs_RgbAve(_raster.getBufferType());\r
+ this._capture.start();\r
+ _bi=new NyARGrayscaleRaster(W, H);\r
+ return;\r
+ \r
+ }\r
+ public void UpdateInput(NyARTrackerSource_Reference o_input) throws NyARException\r
+ {\r
+ synchronized(this._raster){\r
+ this._filter.doFilter(this._raster,this._bi);\r
+ }\r
+ o_input.wrapBuffer(this._bi);\r
+ }\r
+ private JmfCaptureDevice _capture;\r
+ private JmfNyARRaster_RGB _raster;\r
+ private NyARGrayscaleRaster _bi;\r
+ private NyARRasterFilter_Rgb2Gs_RgbAve _filter;\r
+ \r
+ public void onUpdateBuffer(javax.media.Buffer i_buffer)\r
+ {\r
+ try {\r
+ //キャプチャしたバッファをラスタにセット\r
+ synchronized(this._raster){\r
+ this._raster.setBuffer(i_buffer);\r
+ }\r
+ //キャプチャしたイメージを表示用に加工\r
+ }catch(Exception e)\r
+ {\r
+ e.printStackTrace();\r
+ }\r
+\r
+ }\r
+\r
+ private void startCapture()\r
+ {\r
+ try {\r
+ this._capture.start();\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ }\r
+ \r
+ NyARTrackerSource_Reference tracksource;\r
+ \r
+ NyARTracker tracker;\r
+ \r
+ private final static String SAMPLE_FILES = "../Data/320x240ABGR.png";\r
+\r
+ private static final long serialVersionUID = -2110888320986446576L;\r
+\r
+\r
+ private int W = 320;\r
+ private int H = 240;\r
+ InputSource _input_source;\r
+ public Test_TrackTerget(NyARCameraDistortionFactor p) throws NyARException, Exception\r
+ {\r
+ setTitle("Reality Platform test");\r
+ Insets ins = this.getInsets();\r
+ this.setSize(1024 + ins.left + ins.right, 768 + ins.top + ins.bottom);\r
+ \r
+// this._input_source=new ImageSource(SAMPLE_FILES);\r
+// this._input_source=new MoveSource();\r
+ this._input_source=new LiveSource(W,H);\r
+ //create sampler\r
+ this.tracksource=new NyARTrackerSource_Reference(100,p,W, H, 2,false);\r
+ _tmp_bf=new BufferedImage(W, H,BufferedImage.TYPE_INT_RGB);\r
+ \r
+ //create tracker\r
+ this.tracker=new NyARTracker(10,1,10);\r
+\r
+ return;\r
+ }\r
+\r
+\r
+\r
+ \r
+ \r
+ public void draw(INyARRgbRaster i_raster)\r
+ {\r
+ \r
+ }\r
+ static long tick;\r
+ public void update()\r
+ {\r
+ try {\r
+ // マーカーを検出\r
+ long s=System.currentTimeMillis();\r
+ for (int i = 0; i < 1; i++) {\r
+ //tracker更新\r
+ this._input_source.UpdateInput(this.tracksource);\r
+ this.tracker.progress(this.tracksource);\r
+ }\r
+ System.out.println(System.currentTimeMillis() -s);\r
+\r
+ Thread.sleep(30);\r
+ \r
+ //tracker更新\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ BufferedImage _tmp_bf;\r
+ private void draw(Graphics ig) throws NyARException\r
+ {\r
+ //ウインドウの情報\r
+ Insets ins = this.getInsets();\r
+\r
+ //ワーク画面\r
+ BufferedImage bmp=this._tmp_bf;\r
+ NyARRasterImageIO.copy(this.tracksource.refBaseRaster(),bmp);\r
+ //Ignore,Coord,New\r
+ for(int i=this.tracker._targets.getLength()-1;i>=0;i--){\r
+ switch(this.tracker._targets.getItem(i)._st_type)\r
+ {\r
+ case NyARTargetStatus.ST_CONTURE:\r
+ drawContourTarget(this.tracker._targets.getItem(i),bmp,Color.blue);\r
+ break;\r
+ case NyARTargetStatus.ST_IGNORE:\r
+ drawIgnoreTarget(this.tracker._targets.getItem(i),bmp,Color.red);\r
+ break;\r
+ case NyARTargetStatus.ST_NEW:\r
+ drawNewTarget(this.tracker._targets.getItem(i),bmp,Color.green);\r
+ break;\r
+ case NyARTargetStatus.ST_RECT:\r
+ drawRectTarget(this.tracker._targets.getItem(i),bmp,Color.cyan);\r
+ break;\r
+ }\r
+ }\r
+ //表示\r
+ ig.drawImage(bmp,ins.left,ins.top,null);\r
+ drawImage(ig,ins.left+640,ins.top,this.tracksource.refEdgeRaster());\r
+ }\r
+ private void drawImage(Graphics g,int x,int y,NyARGrayscaleRaster r) throws NyARException\r
+ {\r
+ BufferedImage _tmp_bf=new BufferedImage(r.getWidth(),r.getHeight(),BufferedImage.TYPE_INT_RGB);\r
+ NyARRasterImageIO.copy(r, _tmp_bf);\r
+ g.drawImage(_tmp_bf, x,y, null);\r
+ }\r
+ //\r
+ //描画関数\r
+ //\r
+ /**\r
+ * RectTargetを表示します。\r
+ */\r
+ private void drawRectTarget(NyARTarget t,BufferedImage sink,Color c)\r
+ {\r
+ //サンプリング結果の表示\r
+ Graphics g=sink.getGraphics();\r
+ g.setColor(c);\r
+ NyARRectTargetStatus s=(NyARRectTargetStatus)t._ref_status;\r
+ g.drawString("RT:"+t._serial+"("+s.detect_type+")"+"-"+t._delay_tick,t._sample_area.x,t._sample_area.y);\r
+ g.drawRect((int)s.vertex[0].x-1,(int)s.vertex[0].y-1,2,2);\r
+ for(int i2=0;i2<4;i2++){\r
+// g.fillRect((int)st.vecpos[i2].x-1, (int)st.vecpos[i2].y-1,2,2);\r
+ g.drawLine(\r
+ (int)s.vertex[i2].x,\r
+ (int)s.vertex[i2].y,\r
+ (int)s.vertex[(i2+1)%4].x,\r
+ (int)s.vertex[(i2+1)%4].y);\r
+ }/*\r
+ g.setColor(Color.pink);\r
+ for(int i2=0;i2<4;i2++){\r
+ g.drawLine(\r
+ (int)s.estimate_vertex[i2].x,\r
+ (int)s.estimate_vertex[i2].y,\r
+ (int)s.estimate_vertex[(i2+1)%4].x,\r
+ (int)s.estimate_vertex[(i2+1)%4].y);\r
+ }*/\r
+ }\r
+\r
+ /**\r
+ * ContourTargetを表示します。\r
+ */\r
+ private void drawContourTarget(NyARTarget t,BufferedImage sink,Color c)\r
+ {\r
+ //サンプリング結果の表示\r
+ Graphics g=sink.getGraphics();\r
+ g.setColor(c);\r
+ g.drawString("CT",t._sample_area.x,t._sample_area.y);\r
+// g.drawRect(t._sample_area.x,t._sample_area.y,t._sample_area.w,t._sample_area.h);\r
+ NyARContourTargetStatus st=(NyARContourTargetStatus)t._ref_status;\r
+ VecLinearCoordinatesOperator vp=new VecLinearCoordinatesOperator();\r
+ vp.margeResembleCoords(st.vecpos);\r
+ for(int i2=0;i2<st.vecpos.length;i2++){\r
+// for(int i2=43;i2<44;i2++){\r
+// g.drawString(i2+":"+"-"+t._delay_tick,(int)st.vecpos.items[i2].x-1, (int)st.vecpos.items[i2].y-1);\r
+ g.fillRect((int)st.vecpos.items[i2].x, (int)st.vecpos.items[i2].y,1,1);\r
+ double co,si;\r
+ co=st.vecpos.items[i2].dx;\r
+ si=st.vecpos.items[i2].dy;\r
+ double p=Math.sqrt(co*co+si*si);\r
+ co/=p;\r
+ si/=p;\r
+ double ss=st.vecpos.items[i2].scalar*3;\r
+ g.drawLine(\r
+ (int)st.vecpos.items[i2].x,\r
+ (int)st.vecpos.items[i2].y,\r
+ (int)(co*ss)+(int)st.vecpos.items[i2].x,(int)(si*ss)+(int)st.vecpos.items[i2].y);\r
+ int xx=(int)st.vecpos.items[i2].x;\r
+ int yy=(int)st.vecpos.items[i2].y;\r
+// g.drawRect(xx/8*8,yy/8*8,16,16);\r
+ \r
+ }\r
+ }\r
+ \r
+ /**\r
+ * IgnoreTargetを表示します。\r
+ */\r
+ private void drawIgnoreTarget(NyARTarget t,BufferedImage sink,Color c)\r
+ {\r
+ //サンプリング結果の表示\r
+ Graphics g=sink.getGraphics();\r
+ g.setColor(c);\r
+ g.drawString("IG"+"-"+t._delay_tick,t._sample_area.x,t._sample_area.y);\r
+ g.drawRect(t._sample_area.x,t._sample_area.y,t._sample_area.w,t._sample_area.h);\r
+ }\r
+ \r
+ /**\r
+ * Newtargetを表示します。\r
+ */\r
+ private void drawNewTarget(NyARTarget t,BufferedImage sink,Color c)\r
+ {\r
+ //サンプリング結果の表示\r
+ Graphics g=sink.getGraphics();\r
+ g.setColor(c);\r
+ g.drawString("NW"+"-"+t._delay_tick,t._sample_area.x,t._sample_area.y);\r
+ g.drawRect(t._sample_area.x,t._sample_area.y,t._sample_area.w,t._sample_area.h);\r
+ }\r
+ \r
+\r
+ \r
+ \r
+\r
+\r
+ public void mainloop() throws Exception\r
+ {\r
+ for(;;){\r
+ //処理\r
+ this.update();\r
+ this.draw(this.getGraphics());\r
+ Thread.sleep(30);\r
+ }\r
+ }\r
+\r
+ public static void main(String[] args)\r
+ {\r
+\r
+ try {\r
+ Test_TrackTerget mainwin = new Test_TrackTerget(null);\r
+ mainwin.setVisible(true);\r
+ mainwin.mainloop();\r
+ // mainwin.startImage();\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+}\r