public MainWindow() { InitializeComponent(); CaptureDeviceList cl = new CaptureDeviceList(); m_cap = cl[0]; m_cap.SetCaptureListener(this); m_cap.PrepareCapture(cameraResX, cameraResY, 30); // 800x600 resolution, 30 fps NyARParam ap = new NyARParam(); ap.loadARParamFromFile(AR_CAMERA_FILE); ap.changeScreenSize(cameraResX, cameraResY); this.m_raster = new NyARRgbRaster(m_cap.video_width, m_cap.video_height, NyARBufferType.BYTE1D_R8G8B8_24, false); NyARCode code = new NyARCode(16, 16); // 16 pixels to detect within black box code.loadARPattFromFile(AR_CODE_FILE); this.m_ar = new NyARDetectMarker(ap, new NyARCode[] { code }, new double[] { 80.0 }, 1, NyARBufferType.BYTE1D_B8G8R8_24); this.m_ar.setContinueMode(false); this.Loaded += MainWindow_Loaded; }
public NyARCode createNyARCode() { NyARCode result = new NyARCode(this._code_size, this._code_size); result.loadARPattFromFile(this._root_path + "\\" + this._code_file); return(result); }
/** * ARToolkit準拠のパターンファイルからパターンコードを生成して、テーブルへ追加します。 * @param i_filename * @param i_id * このマーカを識別するユーザ定義のID値です。任意の値を指定できます。不要な場合は0を指定してください。 * @param i_name * ユーザ定義の名前です。任意の値を指定できます。不要な場合はnullを指定して下さい。 * @param i_width * マーカの高さ[通常mm単位] * @param i_height * マーカの幅[通常mm単位] * @return * @throws NyARException */ public bool addMarkerFromARPattFile(String i_filename, int i_id, String i_name, double i_width, double i_height) { MarkerTable.SerialTableRow d = this._table.prePush(); if (d == null) { return(false); } NyARCode c = new NyARCode(this._resolution_width, this._resolution_height); c.loadARPattFromFile(i_filename); d.setValue(c, i_id, i_name, i_width, i_height); return(true); }
public NyARWordsBingoCore(Label lbl, Game currentGame, PictureBox pbx) { //Instanciando o PictureBox com o recebido do Form pbxNyAR = pbx; lbNyAR = lbl; gmNyAR = currentGame; //Parâmetros da RA NyARParam ap = new NyARParam(); ap.loadARParamFromFile(AR_CAMERA_FILE); //Lendo arquivo .dat ap.changeScreenSize(640, 480); //Setando tamanho da câmera. //Lendo padrão do marcador NyARCode codeKanji = new NyARCode(16, 16); NyARCode codeA = new NyARCode(16, 16); NyARCode codeB = new NyARCode(16, 16); NyARCode codeC = new NyARCode(16, 16); NyARCode codeD = new NyARCode(16, 16); NyARCode codeE = new NyARCode(16, 16); NyARCode codeF = new NyARCode(16, 16); NyARCode codeG = new NyARCode(16, 16); NyARCode codeH = new NyARCode(16, 16); NyARCode codeI = new NyARCode(16, 16); NyARCode codeJ = new NyARCode(16, 16); NyARCode codeK = new NyARCode(16, 16); NyARCode codeL = new NyARCode(16, 16); NyARCode codeM = new NyARCode(16, 16); NyARCode codeN = new NyARCode(16, 16); NyARCode codeO = new NyARCode(16, 16); NyARCode codeP = new NyARCode(16, 16); NyARCode codeQ = new NyARCode(16, 16); NyARCode codeR = new NyARCode(16, 16); NyARCode codeS = new NyARCode(16, 16); NyARCode codeT = new NyARCode(16, 16); NyARCode codeU = new NyARCode(16, 16); NyARCode codeV = new NyARCode(16, 16); NyARCode codeW = new NyARCode(16, 16); NyARCode codeX = new NyARCode(16, 16); NyARCode codeY = new NyARCode(16, 16); NyARCode codeZ = new NyARCode(16, 16); NyARCode codeBall = new NyARCode(16, 16); NyARCode codeSword = new NyARCode(16, 16); NyARCode codeCar = new NyARCode(16, 16); NyARCode codeBrigadier = new NyARCode(16, 16); NyARCode codeFork = new NyARCode(16, 16); NyARCode codePen = new NyARCode(16, 16); NyARCode codeFish = new NyARCode(16, 16); //Carregando os arquivos dos marcadores no NyARCode codeKanji.loadARPattFromFile(AR_CODE_FILE_KANJI); codeA.loadARPattFromFile(AR_CODE_FILE_A); codeB.loadARPattFromFile(AR_CODE_FILE_B); codeC.loadARPattFromFile(AR_CODE_FILE_C); codeD.loadARPattFromFile(AR_CODE_FILE_D); codeE.loadARPattFromFile(AR_CODE_FILE_E); codeF.loadARPattFromFile(AR_CODE_FILE_F); codeG.loadARPattFromFile(AR_CODE_FILE_G); codeH.loadARPattFromFile(AR_CODE_FILE_H); codeI.loadARPattFromFile(AR_CODE_FILE_I); codeJ.loadARPattFromFile(AR_CODE_FILE_J); codeK.loadARPattFromFile(AR_CODE_FILE_K); codeL.loadARPattFromFile(AR_CODE_FILE_L); codeM.loadARPattFromFile(AR_CODE_FILE_M); codeN.loadARPattFromFile(AR_CODE_FILE_N); codeO.loadARPattFromFile(AR_CODE_FILE_O); codeP.loadARPattFromFile(AR_CODE_FILE_P); codeQ.loadARPattFromFile(AR_CODE_FILE_Q); codeR.loadARPattFromFile(AR_CODE_FILE_R); codeS.loadARPattFromFile(AR_CODE_FILE_S); codeT.loadARPattFromFile(AR_CODE_FILE_T); codeU.loadARPattFromFile(AR_CODE_FILE_U); codeV.loadARPattFromFile(AR_CODE_FILE_V); codeW.loadARPattFromFile(AR_CODE_FILE_W); codeX.loadARPattFromFile(AR_CODE_FILE_X); codeY.loadARPattFromFile(AR_CODE_FILE_Y); codeZ.loadARPattFromFile(AR_CODE_FILE_Z); codeBall.loadARPattFromFile(AR_CODE_FILE_BALL); codeSword.loadARPattFromFile(AR_CODE_FILE_SWORD); codeCar.loadARPattFromFile(AR_CODE_FILE_CAR); codeBrigadier.loadARPattFromFile(AR_CODE_FILE_BRIGADIER); codeFork.loadARPattFromFile(AR_CODE_FILE_FORK); codePen.loadARPattFromFile(AR_CODE_FILE_PEN); codeFish.loadARPattFromFile(AR_CODE_FILE_FISH); double[] WidthArray = { 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0 }; NyARCode[] arrayCodes = { codeKanji, codeA, codeB, codeC, codeD, codeE, codeF, codeG, codeH, codeI, codeJ, codeK, codeL, codeM, codeN, codeO, codeP, codeQ, codeR, codeS, codeT, codeU, codeV, codeW, codeX, codeY, codeZ }; double[] WidthArrayImages = { 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0 }; NyARCode[] arrayCodesImage = { codeBall, codeSword, codeCar, codeBrigadier, codeFork, codePen, codeFish }; //Seta propriedades da câmera try { Core.cap.SetCaptureListener(this); } catch (Exception e) { MessageBox.Show("Ocorreu um erro no estabelecimento da conexão com a câmera. Verifique se ela está instalada corretamente. Favor, reinicie a aplicação.", "Erro!"); Environment.Exit(0); } Core.cap.PrepareCapture(640, 480, 30); //Create a cluster - Instanciando o Raster, passando os parâmetros do vídeo encontrado no CaptureDevice Core.raster = Core.InstanceRaster(Core.cap.video_width, Core.cap.video_height); //Instanciando os detectores únicos this.ballMarkerDetector = new NyARSingleDetectMarker(ap, codeBall, 80.0, Core.raster.getBufferType()); this.ballMarkerDetector.setContinueMode(true); this.brigadierlMarkerDetector = new NyARSingleDetectMarker(ap, codeBrigadier, 80.0, Core.raster.getBufferType()); this.brigadierlMarkerDetector.setContinueMode(true); this.carMarkerDetector = new NyARSingleDetectMarker(ap, codeCar, 80.0, Core.raster.getBufferType()); this.carMarkerDetector.setContinueMode(true); this.forkMarkerDetector = new NyARSingleDetectMarker(ap, codeFork, 80.0, Core.raster.getBufferType()); this.forkMarkerDetector.setContinueMode(true); this.penMarkerDetector = new NyARSingleDetectMarker(ap, codePen, 80.0, Core.raster.getBufferType()); this.penMarkerDetector.setContinueMode(true); this.swordMarkerDetector = new NyARSingleDetectMarker(ap, codeSword, 80.0, Core.raster.getBufferType()); this.swordMarkerDetector.setContinueMode(true); this.fishMarkerDetector = new NyARSingleDetectMarker(ap, codeFish, 80.0, Core.raster.getBufferType()); this.fishMarkerDetector.setContinueMode(true); //Instanciando o detector de todas as letras this.markerDetectorLetters = new NyARDetectMarker(ap, arrayCodes, WidthArray, 27, Core.raster.getBufferType()); this.markerDetectorLetters.setContinueMode(true); //Instanciando o detector das imagens que representam a palavra na cartela this.markerDetectorImages = new NyARDetectMarker(ap, arrayCodesImage, WidthArrayImages, 7, Core.raster.getBufferType()); this.markerDetectorImages.setContinueMode(true); //Inicia a captura //Inicia a captura try { Core.cap.StartCapture(); } catch (Exception e) { MessageBox.Show("Ocorreu um erro no estabelecimento da conexão com a câmera. Verifique se ela está instalada corretamente."); Environment.Exit(0); } //Abaixo, são as funções que preparam todo o dispositivo e cenário para renderização 3D //Necessário descobrir mais detalhes do funcionamento. //Preparing the 3D device this._device = Core.PrepareD3dDevice(pbx); //Prepara o dispositivo em cima do PictureBox this._device.RenderState.ZBufferEnable = true; this._device.RenderState.Lighting = false; //Projection Camera Settings Matrix tmp = new Matrix(); NyARD3dUtil.toCameraFrustumRH(ap.getPerspectiveProjectionMatrix(), ap.getScreenSize(), 1, 10, 10000, ref tmp); this._device.Transform.Projection = tmp; // View conversion settings (set in the left-handed view matrix). //From 0,0,0, and facing Z +, Y-axis direction on this._device.Transform.View = Matrix.LookAtLH( new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f)); Viewport vp = new Viewport(); vp.X = 0; vp.Y = 0; vp.Height = ap.getScreenSize().h; vp.Width = ap.getScreenSize().w; vp.MaxZ = 1.0f; //Set viewport this._device.Viewport = vp; //Draw a color cube instance - Instância de um cubo colorido, padrão da biblioteca NyAR this._cube = new ColorCube(this._device, 40); //Create a background surface this._surface = new NyARSurface_XRGB32(this._device, 640, 480); //Carregando os meshs (objetos 3D) LoadMeshes(); }