2010. 3. 3. 19:54
Computer Vision
http://www.hitl.washington.edu/artoolkit/
ARToolKit Patternmaker
Automatically create large numbers of target patterns for the ARToolKit, by the University of Utah.
ARToolKit-2.72.tgz 다운로드
http://www.openvrml.org/
DSVideoLib
A DirectShow wrapper supporting concurrent access to framebuffers from multiple threads. Useful for developing applications that require live video input from a variety of capture devices (frame grabbers, IEEE-1394 DV camcorders, USB webcams).
openvrml on macports
http://trac.macports.org/browser/trunk/dports/graphics/openvrml/Portfile
openvrml 설치
ARToolKit-2.72.1 설치 후 테스트
graphicsTest on the bin directory
-> This test confirms that your camera support ARToolKit graphics module with OpenGL.
videoTest on the bin directory
-> This test confirms that your camera supports ARToolKit video module and ARToolKit graphics module.
simpleTest on the bin directory
-> You need to notice that better the format is similar to ARToolKit tracking format, faster is the acquisition (RGB more efficient).
"hiro" 패턴을 쓰지 않으면, 아래와 같은 에러가 난다.
arGetTransMat() 안에서 다음과 같이 pattern의 transformation 값을 출력해 보면,
결과:
Feature List
* A simple framework for creating real-time augmented reality applications
* A multiplatform library (Windows, Linux, Mac OS X, SGI)
* Overlays 3D virtual objects on real markers ( based on computer vision algorithm)
* A multi platform video library with:
ARToolKit Patternmaker
Automatically create large numbers of target patterns for the ARToolKit, by the University of Utah.
ARToolKit-2.72.tgz 다운로드
http://www.openvrml.org/
DSVideoLib
A DirectShow wrapper supporting concurrent access to framebuffers from multiple threads. Useful for developing applications that require live video input from a variety of capture devices (frame grabbers, IEEE-1394 DV camcorders, USB webcams).
openvrml on macports
http://trac.macports.org/browser/trunk/dports/graphics/openvrml/Portfile
galaxy:~ lym$ port search openvrml
openvrml @0.17.12 (graphics, x11)
a cross-platform VRML and X3D browser and C++ runtime library
galaxy:~ lym$ port info openvrml
openvrml @0.17.12 (graphics, x11)
Variants: js_mozilla, mozilla_plugin, no_opengl, no_x11, player, universal,
xembed
OpenVRML is a free cross-platform runtime for VRML and X3D available under the
GNU Lesser General Public License. The OpenVRML distribution includes libraries
you can use to add VRML/X3D support to an application. On platforms where GTK+
is available, OpenVRML also provides a plug-in to render VRML/X3D worlds in Web
browsers.
Homepage: http://www.openvrml.org/
Build Dependencies: pkgconfig
Library Dependencies: boost, libpng, jpeg, fontconfig, mesa, libsdl
Platforms: darwin
Maintainers: raphael@ira.uka.de openmaintainer@macports.org
galaxy:~ lym$ port deps openvrml
openvrml has build dependencies on:
pkgconfig
openvrml has library dependencies on:
boost
libpng
jpeg
fontconfig
mesa
libsdl
galaxy:~ lym$ port variants openvrml
openvrml has the variants:
js_mozilla: Enable support for JavaScript in the Script node with Mozilla
no_opengl: Do not build the GL renderer
xembed: Build the XEmbed control
player: Build the GNOME openvrml-player
mozilla_plugin: Build the Mozilla plug-in
no_x11: Disable support for X11
universal: Build for multiple architectures
openvrml @0.17.12 (graphics, x11)
a cross-platform VRML and X3D browser and C++ runtime library
galaxy:~ lym$ port info openvrml
openvrml @0.17.12 (graphics, x11)
Variants: js_mozilla, mozilla_plugin, no_opengl, no_x11, player, universal,
xembed
OpenVRML is a free cross-platform runtime for VRML and X3D available under the
GNU Lesser General Public License. The OpenVRML distribution includes libraries
you can use to add VRML/X3D support to an application. On platforms where GTK+
is available, OpenVRML also provides a plug-in to render VRML/X3D worlds in Web
browsers.
Homepage: http://www.openvrml.org/
Build Dependencies: pkgconfig
Library Dependencies: boost, libpng, jpeg, fontconfig, mesa, libsdl
Platforms: darwin
Maintainers: raphael@ira.uka.de openmaintainer@macports.org
galaxy:~ lym$ port deps openvrml
openvrml has build dependencies on:
pkgconfig
openvrml has library dependencies on:
boost
libpng
jpeg
fontconfig
mesa
libsdl
galaxy:~ lym$ port variants openvrml
openvrml has the variants:
js_mozilla: Enable support for JavaScript in the Script node with Mozilla
no_opengl: Do not build the GL renderer
xembed: Build the XEmbed control
player: Build the GNOME openvrml-player
mozilla_plugin: Build the Mozilla plug-in
no_x11: Disable support for X11
universal: Build for multiple architectures
openvrml 설치
ARToolKit-2.72.1 설치 후 테스트
graphicsTest on the bin directory
-> This test confirms that your camera support ARToolKit graphics module with OpenGL.
videoTest on the bin directory
-> This test confirms that your camera supports ARToolKit video module and ARToolKit graphics module.
simpleTest on the bin directory
-> You need to notice that better the format is similar to ARToolKit tracking format, faster is the acquisition (RGB more efficient).
"hiro" 패턴을 쓰지 않으면, 아래와 같은 에러가 난다.
/Users/lym/ARToolKit/build/ARToolKit.build/Development/simpleTest.build/Objects-normal/i386/simpleTest ; exit;
galaxy:~ lym$ /Users/lym/ARToolKit/build/ARToolKit.build/Development/simpleTest.build/Objects-normal/i386/simpleTest ; exit;
Using default video config.
Opening sequence grabber 1 of 1.
vid->milliSecPerFrame: 200 forcing timer period to 100ms
Video cType is raw , size is 320x240.
Image size (x,y) = (320,240)
Camera parameter load error !!
logout
galaxy:~ lym$ /Users/lym/ARToolKit/build/ARToolKit.build/Development/simpleTest.build/Objects-normal/i386/simpleTest ; exit;
Using default video config.
Opening sequence grabber 1 of 1.
vid->milliSecPerFrame: 200 forcing timer period to 100ms
Video cType is raw , size is 320x240.
Image size (x,y) = (320,240)
Camera parameter load error !!
logout
Using default video config.
Opening sequence grabber 1 of 1.
vid->milliSecPerFrame: 200 forcing timer period to 100ms
Video cType is raw , size is 320x240.
Image size (x,y) = (320,240)
*** Camera Parameter ***
--------------------------------------
SIZE = 320, 240
Distortion factor = 159.250000 131.750000 104.800000 1.012757
350.47574 0.00000 158.25000 0.00000
0.00000 363.04709 120.75000 0.00000
0.00000 0.00000 1.00000 0.00000
--------------------------------------
Opening Data File Data/object_data2
About to load 2 Models
Read in No.1
Read in No.2
Objectfile num = 2
Opening sequence grabber 1 of 1.
vid->milliSecPerFrame: 200 forcing timer period to 100ms
Video cType is raw , size is 320x240.
Image size (x,y) = (320,240)
*** Camera Parameter ***
--------------------------------------
SIZE = 320, 240
Distortion factor = 159.250000 131.750000 104.800000 1.012757
350.47574 0.00000 158.25000 0.00000
0.00000 363.04709 120.75000 0.00000
0.00000 0.00000 1.00000 0.00000
--------------------------------------
Opening Data File Data/object_data2
About to load 2 Models
Read in No.1
Read in No.2
Objectfile num = 2
arGetTransMat() 안에서 다음과 같이 pattern의 transformation 값을 출력해 보면,
// http://www.hitl.washington.edu/artoolkit/documentation/tutorialcamera.htm
printf("camera transformation: %f %f %f\n",conv[0][3],conv[1][3],conv[2][3]);
printf("camera transformation: %f %f %f\n",conv[0][3],conv[1][3],conv[2][3]);
결과:
Feature List
* A simple framework for creating real-time augmented reality applications
* A multiplatform library (Windows, Linux, Mac OS X, SGI)
* Overlays 3D virtual objects on real markers ( based on computer vision algorithm)
* A multi platform video library with:
o multiple input sources (USB, Firewire, capture card) supported
o multiple format (RGB/YUV420P, YUV) supported
o multiple camera tracking supported
o GUI initializing interface
o multiple format (RGB/YUV420P, YUV) supported
o multiple camera tracking supported
o GUI initializing interface
* A fast and cheap 6D marker tracking (real-time planar detection)
* An extensible markers patterns approach (number of markers fct of efficency)
* An easy calibration routine
* A simple graphic library (based on GLUT)
* A fast rendering based on OpenGL
* A 3D VRML support
* A simple and modular API (in C)
* Other language supported (JAVA, Matlab)
* A complete set of samples and utilities
* A good solution for tangible interaction metaphor
* OpenSource with GPL license for non-commercial usage
framework
"ARToolKit is able to perform this camera tracking in real time, ensuring that the virtual objects always appear overlaid on the tracking markers."
how to
1. 매 비디오 프레임 마다 사각형 모양을 찾기
2. 검은색 사각형에 대한 카메라의 상대적 위치를 계산
3. 그 위치로부터 컴퓨터 그래픽 모델이 어떻게 그려질지를 계산
4. 실제 영상의 마커 위에 모델을 그림
limitations
1. 추적하는 마커가 영상 안에 보일 때에만 가상 물체를 합성할 수 있음
2. 이 때문에 가상 물체들의 크기나 이동이 제한됨
3. 마커의 패턴의 일부가 가려지는 경우 가상 물체를 합성할 수 없음
4. range(거리)의 제한: 마커의 모양이 클수록 멀리 떨어진 패턴까지 감지할 수 있으므로 추적할 수 있는 volume(범위)이 더 커짐
(이때 거리는 pattern complexity (패턴의 복잡도)에 따라 달라짐: 패턴이 단순할수록 한계 거리가 길어짐)
5. 추적 성능이 카메라에 대한 마커의 상대적인 orientation(방향)에 따라 달라짐
: 마커가 많이 기울어 수평에 가까워질수록 보이는 패턴의 부분이 줄어들기 때문에 recognition(인식)이 잘 되지 않음(신뢰도가 떨어짐)
6. 추적 성능이 lighting conditions (조명 상태)에 따라 달라짐
: 조명에 의해 종이 마커 위에 reflection and glare spots (반사)가 생기면 마커의 사각형을 찾기가 어려워짐
: 종이 대신 반사도가 적은 재료를 쓸 수 있음
ARToolKit Vision Algorithm
Development
Initialization
1. Initialize the video capture and read in the marker pattern files and camera parameters. -> init()
Main Loop
2. Grab a video input frame. -> arVideoGetImage()
3. Detect the markers and recognized patterns in the video input frame. -> arDetectMarker()
4. Calculate the camera transformation relative to the detected patterns. -> arGetTransMat)
5. Draw the virtual objects on the detected patterns. -> draw()
Shutdown
6. Close the video capture down. -> cleanup()
ref.
http://king8028.tistory.com/entry/ARToolkit-simpletestc-%EC%84%A4%EB%AA%8512
http://kougaku-navi.net/ARToolKit.html
ARToolKit video configuration
camera calibration
Default camera properties are contained in the camera parameter file camera_para.dat, that is read in each time an application is started.
The program calib_dist is used to measure the image center point and lens distortion, while calib_param produces the other camera properties. (Both of these programs can be found in the bin directory and their source is in the utils/calib_dist and utils/calib_cparam directories.)
ARToolKit gives the position of the marker in the camera coordinate system, and uses OpenGL matrix system for the position of the virtual object.
arVideoGetImage()
video.h
ARParam
param.h
arDetectMarker()
ar.h 헤더 파일의 설명:
double arGetTransMat()
ar.h 헤더 파일의 설명:
arUtilMatInv()
ar.h 헤더 파일의 설명:
* An extensible markers patterns approach (number of markers fct of efficency)
* An easy calibration routine
* A simple graphic library (based on GLUT)
* A fast rendering based on OpenGL
* A 3D VRML support
* A simple and modular API (in C)
* Other language supported (JAVA, Matlab)
* A complete set of samples and utilities
* A good solution for tangible interaction metaphor
* OpenSource with GPL license for non-commercial usage
framework
"ARToolKit is able to perform this camera tracking in real time, ensuring that the virtual objects always appear overlaid on the tracking markers."
how to
1. 매 비디오 프레임 마다 사각형 모양을 찾기
2. 검은색 사각형에 대한 카메라의 상대적 위치를 계산
3. 그 위치로부터 컴퓨터 그래픽 모델이 어떻게 그려질지를 계산
4. 실제 영상의 마커 위에 모델을 그림
limitations
1. 추적하는 마커가 영상 안에 보일 때에만 가상 물체를 합성할 수 있음
2. 이 때문에 가상 물체들의 크기나 이동이 제한됨
3. 마커의 패턴의 일부가 가려지는 경우 가상 물체를 합성할 수 없음
4. range(거리)의 제한: 마커의 모양이 클수록 멀리 떨어진 패턴까지 감지할 수 있으므로 추적할 수 있는 volume(범위)이 더 커짐
(이때 거리는 pattern complexity (패턴의 복잡도)에 따라 달라짐: 패턴이 단순할수록 한계 거리가 길어짐)
5. 추적 성능이 카메라에 대한 마커의 상대적인 orientation(방향)에 따라 달라짐
: 마커가 많이 기울어 수평에 가까워질수록 보이는 패턴의 부분이 줄어들기 때문에 recognition(인식)이 잘 되지 않음(신뢰도가 떨어짐)
6. 추적 성능이 lighting conditions (조명 상태)에 따라 달라짐
: 조명에 의해 종이 마커 위에 reflection and glare spots (반사)가 생기면 마커의 사각형을 찾기가 어려워짐
: 종이 대신 반사도가 적은 재료를 쓸 수 있음
ARToolKit Vision Algorithm
Development
Initialization
1. Initialize the video capture and read in the marker pattern files and camera parameters. -> init()
Main Loop
2. Grab a video input frame. -> arVideoGetImage()
3. Detect the markers and recognized patterns in the video input frame. -> arDetectMarker()
4. Calculate the camera transformation relative to the detected patterns. -> arGetTransMat)
5. Draw the virtual objects on the detected patterns. -> draw()
Shutdown
6. Close the video capture down. -> cleanup()
ref.
http://king8028.tistory.com/entry/ARToolkit-simpletestc-%EC%84%A4%EB%AA%8512
http://kougaku-navi.net/ARToolKit.html
ARToolKit video configuration
camera calibration
Default camera properties are contained in the camera parameter file camera_para.dat, that is read in each time an application is started.
The program calib_dist is used to measure the image center point and lens distortion, while calib_param produces the other camera properties. (Both of these programs can be found in the bin directory and their source is in the utils/calib_dist and utils/calib_cparam directories.)
ARToolKit gives the position of the marker in the camera coordinate system, and uses OpenGL matrix system for the position of the virtual object.
ARToolKit API Documentation
http://artoolkit.sourceforge.net/apidoc/
http://artoolkit.sourceforge.net/apidoc/
ARMarkerInfo | Main structure for detected marker |
ARMarkerInfo2 | Internal structure use for marker detection |
ARMat | Matrix structure |
ARMultiEachMarkerInfoT | Multi-marker structure |
ARMultiMarkerInfoT | Global multi-marker structure |
ARParam | Camera intrinsic parameters |
arPrevInfo | Structure for temporal continuity of tracking |
ARVec | Vector structure |
arVideoGetImage()
video.h
/**
* \brief get the video image.
*
* This function returns a buffer with a captured video image.
* The returned data consists of a tightly-packed array of
* pixels, beginning with the first component of the leftmost
* pixel of the topmost row, and continuing with the remaining
* components of that pixel, followed by the remaining pixels
* in the topmost row, followed by the leftmost pixel of the
* second row, and so on.
* The arrangement of components of the pixels in the buffer is
* determined by the configuration string passed in to the driver
* at the time the video stream was opened. If no pixel format
* was specified in the configuration string, then an operating-
* system dependent default, defined in <AR/config.h> is used.
* The memory occupied by the pixel data is owned by the video
* driver and should not be freed by your program.
* The pixels in the buffer remain valid until the next call to
* arVideoCapNext, or the next call to arVideoGetImage which
* returns a non-NULL pointer, or any call to arVideoCapStop or
* arVideoClose.
* \return A pointer to the pixel data of the captured video frame,
* or NULL if no new pixel data was available at the time of calling.
*/
AR_DLL_API ARUint8* arVideoGetImage(void);
* \brief get the video image.
*
* This function returns a buffer with a captured video image.
* The returned data consists of a tightly-packed array of
* pixels, beginning with the first component of the leftmost
* pixel of the topmost row, and continuing with the remaining
* components of that pixel, followed by the remaining pixels
* in the topmost row, followed by the leftmost pixel of the
* second row, and so on.
* The arrangement of components of the pixels in the buffer is
* determined by the configuration string passed in to the driver
* at the time the video stream was opened. If no pixel format
* was specified in the configuration string, then an operating-
* system dependent default, defined in <AR/config.h> is used.
* The memory occupied by the pixel data is owned by the video
* driver and should not be freed by your program.
* The pixels in the buffer remain valid until the next call to
* arVideoCapNext, or the next call to arVideoGetImage which
* returns a non-NULL pointer, or any call to arVideoCapStop or
* arVideoClose.
* \return A pointer to the pixel data of the captured video frame,
* or NULL if no new pixel data was available at the time of calling.
*/
AR_DLL_API ARUint8* arVideoGetImage(void);
ARParam
param.h
/** \struct ARParam
* \brief camera intrinsic parameters.
*
* This structure contains the main parameters for
* the intrinsic parameters of the camera
* representation. The camera used is a pinhole
* camera with standard parameters. User should
* consult a computer vision reference for more
* information. (e.g. Three-Dimensional Computer Vision
* (Artificial Intelligence) by Olivier Faugeras).
* \param xsize length of the image (in pixels).
* \param ysize height of the image (in pixels).
* \param mat perspective matrix (K).
* \param dist_factor radial distortions factor
* dist_factor[0]=x center of distortion
* dist_factor[1]=y center of distortion
* dist_factor[2]=distortion factor
* dist_factor[3]=scale factor
*/
typedef struct {
int xsize, ysize;
double mat[3][4];
double dist_factor[4];
} ARParam;
typedef struct {
int xsize, ysize;
double matL[3][4];
double matR[3][4];
double matL2R[3][4];
double dist_factorL[4];
double dist_factorR[4];
} ARSParam;
* \brief camera intrinsic parameters.
*
* This structure contains the main parameters for
* the intrinsic parameters of the camera
* representation. The camera used is a pinhole
* camera with standard parameters. User should
* consult a computer vision reference for more
* information. (e.g. Three-Dimensional Computer Vision
* (Artificial Intelligence) by Olivier Faugeras).
* \param xsize length of the image (in pixels).
* \param ysize height of the image (in pixels).
* \param mat perspective matrix (K).
* \param dist_factor radial distortions factor
* dist_factor[0]=x center of distortion
* dist_factor[1]=y center of distortion
* dist_factor[2]=distortion factor
* dist_factor[3]=scale factor
*/
typedef struct {
int xsize, ysize;
double mat[3][4];
double dist_factor[4];
} ARParam;
typedef struct {
int xsize, ysize;
double matL[3][4];
double matR[3][4];
double matL2R[3][4];
double dist_factorL[4];
double dist_factorR[4];
} ARSParam;
arDetectMarker()
ar.h 헤더 파일의 설명:
/**
* \brief main function to detect the square markers in the video input frame.
*
* This function proceeds to thresholding, labeling, contour extraction and line corner estimation
* (and maintains an history).
* It's one of the main function of the detection routine with arGetTransMat.
* \param dataPtr a pointer to the color image which is to be searched for square markers.
* The pixel format depend of your architecture. Generally ABGR, but the images
* are treated as a gray scale, so the order of BGR components does not matter.
* However the ordering of the alpha comp, A, is important.
* \param thresh specifies the threshold value (between 0-255) to be used to convert
* the input image into a binary image.
* \param marker_info a pointer to an array of ARMarkerInfo structures returned
* which contain all the information about the detected squares in the image
* \param marker_num the number of detected markers in the image.
* \return 0 when the function completes normally, -1 otherwise
*/
int arDetectMarker( ARUint8 *dataPtr, int thresh,
ARMarkerInfo **marker_info, int *marker_num );
* \brief main function to detect the square markers in the video input frame.
*
* This function proceeds to thresholding, labeling, contour extraction and line corner estimation
* (and maintains an history).
* It's one of the main function of the detection routine with arGetTransMat.
* \param dataPtr a pointer to the color image which is to be searched for square markers.
* The pixel format depend of your architecture. Generally ABGR, but the images
* are treated as a gray scale, so the order of BGR components does not matter.
* However the ordering of the alpha comp, A, is important.
* \param thresh specifies the threshold value (between 0-255) to be used to convert
* the input image into a binary image.
* \param marker_info a pointer to an array of ARMarkerInfo structures returned
* which contain all the information about the detected squares in the image
* \param marker_num the number of detected markers in the image.
* \return 0 when the function completes normally, -1 otherwise
*/
int arDetectMarker( ARUint8 *dataPtr, int thresh,
ARMarkerInfo **marker_info, int *marker_num );
You need to notice that arGetTransMat give the position of the marker in the camera coordinate system (not the reverse). If you want the position of the camera in the marker coordinate system you need to inverse this transformation (arMatrixInverse()).
XXXBK: not be sure of this function: this function must just convert 3x4
matrix to classical perspective openGL matrix. But in the code, you
used arParamDecompMat that seem decomposed K and R,t, aren't it ? why do
this decomposition since we want just intrinsic parameters ? and if not
what is arDecomp ?
double arGetTransMat()
ar.h 헤더 파일의 설명:
/**
* \brief compute camera position in function of detected markers.
*
* calculate the transformation between a detected marker and the real camera,
* i.e. the position and orientation of the camera relative to the tracking mark.
* \param marker_info the structure containing the parameters for the marker for
* which the camera position and orientation is to be found relative to.
* This structure is found using arDetectMarker.
* \param center the physical center of the marker. arGetTransMat assumes that the marker
* is in x-y plane, and z axis is pointing downwards from marker plane.
* So vertex positions can be represented in 2D coordinates by ignoring the
* z axis information. The marker vertices are specified in order of clockwise.
* \param width the size of the marker (in mm).
* \param conv the transformation matrix from the marker coordinates to camera coordinate frame,
* that is the relative position of real camera to the real marker
* \return always 0.
*/
double arGetTransMat( ARMarkerInfo *marker_info,
double center[2], double width, double conv[3][4] )
* \brief compute camera position in function of detected markers.
*
* calculate the transformation between a detected marker and the real camera,
* i.e. the position and orientation of the camera relative to the tracking mark.
* \param marker_info the structure containing the parameters for the marker for
* which the camera position and orientation is to be found relative to.
* This structure is found using arDetectMarker.
* \param center the physical center of the marker. arGetTransMat assumes that the marker
* is in x-y plane, and z axis is pointing downwards from marker plane.
* So vertex positions can be represented in 2D coordinates by ignoring the
* z axis information. The marker vertices are specified in order of clockwise.
* \param width the size of the marker (in mm).
* \param conv the transformation matrix from the marker coordinates to camera coordinate frame,
* that is the relative position of real camera to the real marker
* \return always 0.
*/
double arGetTransMat( ARMarkerInfo *marker_info,
double center[2], double width, double conv[3][4] )
arUtilMatInv()
ar.h 헤더 파일의 설명:
/**
* \brief Inverse a non-square matrix.
*
* Inverse a matrix in a non homogeneous format. The matrix
* need to be euclidian.
* \param s matrix input
* \param d resulted inverse matrix.
* \return 0 if the inversion success, -1 otherwise
* \remark input matrix can be also output matrix
*/
int arUtilMatInv( double s[3][4], double d[3][4] );
* \brief Inverse a non-square matrix.
*
* Inverse a matrix in a non homogeneous format. The matrix
* need to be euclidian.
* \param s matrix input
* \param d resulted inverse matrix.
* \return 0 if the inversion success, -1 otherwise
* \remark input matrix can be also output matrix
*/
int arUtilMatInv( double s[3][4], double d[3][4] );
'Computer Vision' 카테고리의 다른 글
opencv: video capturing from a camera (4) | 2010.03.13 |
---|---|
Leordeanu & Hebert, "Unsupervised learning for graph matching" (0) | 2010.03.04 |
Jonathan Mooser et al. "Tricodes: A Barcode-Like Fiducial Design for Augmented Reality Media" (0) | 2010.03.02 |
"Design Patterns for Augmented Reality Systems" (0) | 2010.03.02 |
virtual studio 구현: cross ratio test (0) | 2010.02.26 |