ARToolkit官方文件閱讀筆記[3]: 開發第一個應用

原文
Developing your First Application, Part 1

筆記

這篇文件主要的重點是在說明所謂的"ARToolKit Step Functions" ,也就是運行ARToolkit的過程中會經歷的6大步驟,這些步驟在原文件中已經被整理成一個清楚的表格。

ARToolKit Step
Functions
1. Initialize the application
init
2. Grab a video input frame
arVideoGetImage (called in mainLoop)
3. Detect the markers
arDetectMarker (called in mainLoop)
4. Calculate camera transformation
arGetTransMat (called in mainLoop)
5. Draw the virtual objects
draw (called in mainLoop)
6. Close the video capture down
cleanup

不過這六大步驟中沒有包含全部被實際使用到的ARToolkit函式,所以為了更進一步地了解建構一個AR應用究竟需要用到哪些ARToolkit函式,所以我再把每個步驟內所使用到的function抓出來加到表格中。

ARToolKit Step
Functions
1. Initialize the application
由init() 作初使化工作,init內包括的function :
arVideoOpen(vconf)[說明: 開啟video設置檔]

vconfarVideoInqSize(&xsize, &ysize)[說明: 不懂用途]

arParamLoad(cparaname, 1, &wparam)[說明: dat檔和ARParam]

arParamChangeSize( &wparam, xsize, ysize, &cparam )[說明: 需要因應攝影機,計算一下參數的變化]

arInitCparam( &cparam ) [說明: 設定為讀進來的參數]

arParamDisp( &cparam )[說明: 不懂用途]

arLoadPatt(patt_name)[說明: 讀取pattern定義patt.hiro]

argInit( &cparam, 1.0, 0, 0, 0, 0 )[說明: 開啟圖形視窗,第二個參數是一倍大小]
2. Grab a video input frame
由mainLoop() 執行程式迴圈,mainLoop內包括的function :
arVideoGetImage (called in mainLoop)[說明: 取得影像資料]

arUtilSleep(2) [說明: 停頓時間]

argDrawMode2D() [說明: 猜測應該是開啟繪圖模式]

argDispImage( dataPtr, 0,0 )[說明: 把影像畫上去]
3. Detect the markers
由mainLoop() 執行程式迴圈,mainLoop內包括的function :
arDetectMarker(dataPtr, thresh, &marker_info, &marker_num)[說明: 在影像中找出pattern的資料,marker的資料,marker的數量]

arVideoCapNext()[說明: 上一個frame的影像已經處理完畢,抓取下一個影像]

argSwapBuffers()[說明: 猜測是把上一個影像的buffer換成新的]

4. Calculate camera transformation
由mainLoop() 執行程式迴圈,mainLoop內包括的function :
arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans)[說明: 取得真實攝影機和marker之間的方位和方向的轉換,存到patt_trans裡面]

draw()[說明: 把虛擬的3d物件畫上去,參考下一步驟]
argSwapBuffers()[說明:再來一次
5. Draw the virtual objects
由draw() 執行實際的繪圖內容,draw內包括的function :
argDrawMode3D()[說明:猜測應該是開啟3d繪圖模式]

argDraw3dCamera( 0, 0 )[說明:設置攝影機位置]

glClearDepth( 1.0 )[說明:OpenGL指令,略]
glClear(GL_DEPTH_BUFFER_BIT)[說明:OpenGL指令,略]
glEnable(GL_DEPTH_TEST)[說明:OpenGL指令,略]
glDepthFunc(GL_LEQUAL)[說明:OpenGL指令,略]

argConvGlpara(patt_trans, gl_para)[說明:把ARToolkit運算出來的結果,轉換成OpenGL的座標格式,從3x4 matrix轉成16個值得陣列]

glMatrixMode(GL_MODELVIEW)[說明:OpenGL指令,略]
glLoadMatrixd( gl_para )[說明:OpenGL指令,把轉換玩的結果丟給OpenGL]

glEnable(GL_LIGHTING)[說明:底下開始一連串的OpenGL指令,作用是開始畫出3D方塊物件,不一一列舉
6. Close the video capture down
偵測到esc按鈕的時候cleanup()會被呼叫:
arVideoCapStop()[說明:停止擷取]

arVideoClose()[說明:關閉影像]

argCleanup()[說明:清出video的使用權



留言

這個網誌中的熱門文章

如何把3dmax的physique轉成skin

3dmax的biped如何使用CMU的免費motion capture資源

Flex 3 Tree 元件的資料更新Bug