2 2 2 OpenGL Linux Linux Video for Linux(Video4Linux, v4l ) API Video4Linux USB IEEE1394 API Linux Video for Linux 2(Video4Linux2, v4l2 ) OpenCV API U

Similar documents
TA TA TA abcdefgh abcdefgh C PC Wii bluetooth 2.2 Bluetooth USB Princeton PTM-UBT3S 1 1

2 2 2 OpenGL (R,G,B,A) 2.1 OpenGL (x y) width height pixels void glreadpixels(glint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum t

ARToolKit プログラムの仕組み 1: ヘッダファイルのインクルード 2: Main 関数 3: Main Loop 関数 4: マウス入力処理関数 5: キーボード入力処理関数 6: 終了処理関数 3: Main Loop 関数 1カメラ画像の取得 2カメラ画像の描画 3マーカの検出と認識

1 1. Program 1 OpenCV (OpenCV Sample001) 1 /* 2 - > - > - >VC++ 3 ( ) 4 C:\opencv\build\include 5 ( ) 6 C:\opencv\build\x86\vc10\lib 7 - > - > - > - >

Microsoft Word - 卒業論文 docx

2 2 GLUI 2 GLUI 2.1 GLUI GLUI OpenGL OpenGL glut OpenGL glut C++ Linux, Windows (Visual C++, gcc), Macintosh glut glut GUI glut GUI CG glmultmatrix()

2 2 2 OpenGL (R,G,B,A) 2.1 OpenGL (x y) width height pixels void glreadpixels(glint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum t

Tekutama AR ~ 拡張現実感によるオーバーレイ表示と動作 ~ 情報物理研究室 渡部 修平 1

2 Eclipse 2.1 Eclipse 1. Eclipse 2. 3 ( 4) E:Yworkspace OK 3 Eclipse 4 3. Eclipse 5 5 Eclipse Eclipse 2. 7 C 2

OpenCV IS Report No Report Medical Information System Labratry

スライド 1

#include <stdio.h> 2 #include <stdlib.h> 3 #include <GL/glut.h> 4 Program 1 (OpenGL GameSample001) 5 // 6 static bool KeyUpON = false; // 7 sta

第3章 OpenGL の基礎

OpenGL & GLUTの基本関数の説明

/*p7-1-1*/

第3章 OpenGL の基礎

3D グラフィックス処理の一般過程 1. 3D グラフィックス処理の一般過程

卒業研究報告書 題目 3DCG と Web カメラの合成を表現するプログラムの制作 指導教員 綿森道夫准教授 報告者 学籍番号 : 氏名 : 尾川景子 平成 23 年 2 月 8 日 高知工科大学電子 光システム工学科 1

Fair Curve and Surface Design System Using Tangent Control

WebGL OpenGL GLSL Kageyama (Kobe Univ.) Visualization / 57

2 2 OpenGL ( ) 2 OpenGL ( ) glclearcolor(glclampf red, GLclampf green, GLclampf blu

& Vol.5 No (Oct. 2015) TV 1,2,a) , Augmented TV TV AR Augmented Reality 3DCG TV Estimation of TV Screen Position and Ro

コンピュータグラフィックスS 演習資料

1) OOP 2) ( ) 3.2) printf Number3-2.cpp #include <stdio.h> class Number Number(); // ~Number(); // void setnumber(float n); float getnumber();

j x j j j + 1 l j l j = x j+1 x j, n x n x 1 = n 1 l j j=1 H j j + 1 l j l j E

manual.dvi

( ) 1 1: 1 #include <s t d i o. h> 2 #include <GL/ g l u t. h> 3 #include <math. h> 4 #include <s t d l i b. h> 5 #include <time. h>

$ ls -l $ ls -l -a $ ls -la $ ls -F $ ls <dirname> <dirname> $ cd <dirname> <dirname> $ cd $ pwd $ cat <filename> <filename> $ less <filename> <filena

Microsoft PowerPoint - info_eng3_05ppt.pptx

Complex Lab – Operating Systems - Graphical Console



double rx[natom], ry[natom], rz[natom]; 原子の座標 速度 力 ポテンシャルエ double vx[natom], vy[natom], vz[natom]; ネルギーを受ける配列を準備 double fx[natom], fy[natom], fz[natom

/* drawing function */ function_graph();// drawing graph glflush(); int main(int argc, char **argv ) glutinit( &argc, argv ); glutinitdisplaymode( GLU

opencv-linux Linux 1.1pre1 % tar zxvf opencv-1.1pre1.tar.gz % cd opencv %./configure --with-apps % make % su # make install 2.2 Windows Windows

comment.dvi

OpenGL Programming Course OpenGL Programming Course FAQ

新版明解C言語 実践編

27 MixedReality

演算増幅器

2 2 Gtk+ GUI (widget ) GUI Gtk+ GUI Gtk+ GUI 2.2 Gtk GUI sample1.c Web ( tani/class/mech enshu/) enshu2009gui1.tar.gz

ProVisionaire Control V3.0セットアップガイド

新・明解C言語 ポインタ完全攻略

新・明解C言語 実践編

2 2 OpenGL ( ) OpenGL ( ) glclearcolor(glclampf red, GLclampf green, GLclampf

r07.dvi

Condition DAQ condition condition 2 3 XML key value

ohp07.dvi

(300, 150) 120 getchar() HgBox(x, y, w, h) (x, y), w, h #include <stdio.h> #include <handy.h> int main(void) { int i; double w, h; } HgO

program.dvi

untitled

ex01.dvi

5104-toku3.indd

cpp4.dvi

1 level Level swtich ButtonPress ButtonRelease Expose Level

WinHPC ppt

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() malloc 2 #include <stdio.h> #include

double float

2 2 OpenGL OpenGL OpenGL(Open Graphics Library) Silicon Graphics (SGI) 3D OpenGL SGI HP, SUN,

大統一Debian勉強会 gdb+python拡張を使ったデバッグ手法

SystemC言語概論


準備 計算結果を可視化するために OpenGL を 利用する. 2

untitled

\\afs001-0m0005\project02\A32\M

¥Ñ¥Ã¥±¡¼¥¸ Rhpc ¤Î¾õ¶·

[ 1] 1 Hello World!! 1 #include <s t d i o. h> 2 3 int main ( ) { 4 5 p r i n t f ( H e l l o World!! \ n ) ; 6 7 return 0 ; 8 } 1:

P05.ppt

Transcription:

1 26 (2) 3DCG TA 2014 10 17 1 OpenGL USB (3DCG) OpenCV CG Augmented Reality ARToolKit 3DCG 1.1 http://www.cyber.t.u-tokyo.ac.jp/~tani/class/mech_enshu/ 1.2 TA 1.3 ( ) USB (2014/11/10( ),11( ),13( )) (2012/11/17( ), 18( )) Bluetooth USB (2) (2012/11/18( ))

2 2 2 OpenGL Linux Linux Video for Linux(Video4Linux, v4l ) API Video4Linux USB IEEE1394 API Linux Video for Linux 2(Video4Linux2, v4l2 ) OpenCV API USB (USB Video Class, UVC) USB 2.0 Linux Linux Video4Linux lsmod uvcvideo 51204 0 compat_ioctl32 5569 1 uvcvideo videodev 30785 1 uvcvideo v4l1_compat 17349 2 uvcvideo,videodev v4l2_common 20801 2 uvcvideo,videodev 2.1 OpenCV Video4Linux API OpenCV(Open Source Computer Vision Library) OpenCV OpenGL Video4Linux API OS OpenCV OS OS OpenCV OpenGL 3DCG 3DCG OpenCV OpenCV http://opencv.jp/ http://opencv.jp/sample/

2.1 3 OpenCV OpenCV IplImage OpenCV 640 480 3 RGB 8bit RGB OpenCV B G R B G R 3 1 nsize nchannels depth origin width height imagesize imagedata widthstep IplImage 1,2,3,4 1 = widthstep * height 1 IplImage cvloadimage IplImage* cvloadimage( const char* filename, int flags=cv_load_image_color ); filename flags / cvcreateimage RGB 8 24 depth 8 IPL DEPTH 8U channels 3

4 2 IplImage* cvcreateimage( CvSize size, int depth, int channels ); size depth IPL_DEPTH_8U - 8 IPL_DEPTH_8S - 8 IPL_DEPTH_16U - 16 IPL_DEPTH_16S - 16 IPL_DEPTH_32S - 32 IPL_DEPTH_32F - IPL_DEPTH_64F - channels 1, 2, 3, 4 cvreleaseimage void cvreleaseimage( IplImage** image ); image OpenGL R G B OpenCV OpenGL OpenCV OpenGL (GL BGR EXT GL BGRA ) OpenCV cvcvtcolor() CV BGR2RGB BGR RGB void cvcvtcolor( const CvArr* src, CvArr* dst, int code ); src 8 8u 16 16u 32f dst code CV_<src_color_space>2<dst_color_space>

2.1 5 OpenCV CvCapture cvcreatecameracapture() OpenCV 0 cvcreatecameracapture() NULL OpenCV cvcapturefromcam() cvcreatecameracapture() CvCapture* cvcreatecameracapture( int index ); index -1 cvcreatecameracapture() cvcreatefilecapture() CvCapture* cvcreatefilecapture( const char* filename ); filename cvsetcaptureproperty() int cvsetcaptureproperty( CvCapture* capture, int property_id, double value ); capture property_id ID

6 2 cvgetcaptureproperty() cvqueryframe() double cvgetcaptureproperty( CvCapture* capture, int property_id ); capture property_id ID ID CV CAP PROP POS MSEC CV CAP PROP POS FRAMES CV CAP PROP POS AVI RATIO CV CAP PROP FRAME WIDTH CV CAP PROP FRAME HEIGHT CV CAP PROP FPS CV CAP PROP FOURCC CV CAP PROP FRAME COUNT / 4 2 ID 1 CvCapture 1 cvqueryframe() AVI 1 IplImage IplImage NULL IplImage* cvqueryframe( CvCapture* capture ); capture

2.2 7 cvcreatecameracapture() cvcreatefilecapture() cvreleasecapture() void cvreleasecapture( CvCapture** capture ); capture 2.2 Window 1) 1 OpenGL OpenCV /* OpenGL */ #include <GL/glut.h> /* OpenCV */ #include <opencv/cv.h> #include <opencv/highgui.h>

8 2 IplImage *frame; /* Capture Imege from OpenCV */ CvCapture* capture = 0; /* Video Capture Structure */ int dev_index = 0; /* Capture Device ID */ void my_init(int argc, char **argv) { // Initialization Part - OpenCV // Connect to Capture Device capture = cvcreatecameracapture(dev_index); if (capture) { frame = cvqueryframe(capture); cap_width = cvgetcaptureproperty(capture, CV_CAP_PROP_FRAME_WIDTH); cap_height = cvgetcaptureproperty(capture, CV_CAP_PROP_FRAME_HEIGHT); else { fprintf(stderr, "Found No Camera\n"); exit(-1); // Flip Captured Image if (frame->origin==0) { cvflip(frame, frame, 0); // Convert Color Alignment BGR -> RGB cvcvtcolor(frame, frame, CV_BGR2RGB); win_width = cap_width; win_height = cap_height; int my_exit(int e) { /* Release Process - OpenCV */ if (capture) cvreleasecapture(&capture); exit(e);

2.2 9 idle cvqueryframe() OpenGL cvflip() BGR RGB cvcvtcolor() void idle(void) { if (capture) { frame = cvqueryframe(capture); if (frame->origin==0) { cvflip(frame, frame, 0 ); cvcvtcolor(frame, frame, CV_BGR2RGB); glpixelstorei( GL_UNPACK_ALIGNMENT, 1 ); glutpostredisplay(); IplImage cvcloneimage() IplImage* cvcloneimage( const IplImage* image ); image gldrawpixels() void gldrawpixels(glsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); void glrasterpos{234{sifd(type x, TYPE y, TYPE z, TYPE w);

10 2 void display(void) { glclear(gl_color_buffer_bit); glpixelstorei(gl_unpack_alignment, 1); glpixelzoom((gldouble)(win_width-2)/(gldouble)cap_width, (GLdouble)(win_height-2)/(GLdouble)cap_height); glrasterpos2i(-win_width/2+1, -win_height/2+1); gldrawpixels(cap_width, cap_height, GL_RGB, GL_UNSIGNED_BYTE, frame->imagedata); glflush(); glutswapbuffers(); 2.3 2 : sample-texture.c 2 3 glteximage2d() 2 gltexsubimage2d()

2.3 11 void gltexsubimage2d( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels ); idle gltexsubimage2d() void idle(void) { if (capture) { frame = cvqueryframe(capture); if (frame->origin==0) { cvflip(frame, frame, 0); cvcvtcolor(frame, frame, CV_BGR2RGB); glpixelstorei( GL_UNPACK_ALIGNMENT, 1 ); glbindtexture( GL_TEXTURE_2D, tex_index ); gltexsubimage2d( GL_TEXTURE_2D, 0, 0, 0, frame->width, frame->height, GL_RGB, GL_UNSIGNED_BYTE, frame->imagedata ); glutpostredisplay(); glvertex() gltexcoord() 0.0...1.0 OpenGL 2 2 640 480 1024 512 3 640 480 1024 512 gltexcoord() 0.625(=640/1024) 0.9375(=480/512)

12 2 void gltexcoord{1,2,3,4{s,i,d,f(type coords); void gltexcoord{1,2,3,4{s,i,d,fv(type *coords); 3 void display(void) { glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); glcolor3f(1.0, 1.0, 1.0); glenable(gl_texture_2d); glbindtexture( GL_TEXTURE_2D, tex_index ); glpushmatrix(); glbegin(gl_triangle_fan); gltexcoord2f(0.0, 0.0); glvertex3f(-cap_width/2, -cap_height/2, 0.0); gltexcoord2f((float)cap_width/tex_width, 0.0); glvertex3f(cap_width/2, -cap_height/2, 0.0); gltexcoord2f((float)cap_width/tex_width, (float)cap_height/tex_height); glvertex3f(cap_width/2, cap_height/2, 0.0); gltexcoord2f(0.0, (float)cap_height/tex_height); glvertex3f(-cap_width/2, cap_height/2, 0.0); glend(); glpopmatrix();

2.3 13 3 ( 2) 3 ( 4) 1 1. opencv-sample USB v4l2-sample 2. opencv-texture 2 3. opencv-divtex TODO 2.2 4. 4 5. opencv-dynamic 4 3

14 3 Augmented Reality 3 Augmented Reality 3.1 Augmented Reality VR VR (AR: AugmentedReality) (MR: Mixed Reality) (HMD: Head Mounted Display) VR CG 2 (Optical See-Through) (Video See-Through) VR VR VR VR VR 5 (Optical See-Through) HMD 6 (Video See-Through)

15 4 ARToolKit ARToolKit OpenCV OpenGL AR:Augmented Reality) ARToolKit HITL Human Interface Technology Lab ARToolKit Home Page (http://www.hitl.washington.edu/artoolkit/) AR ARToolKit ARToolKit SGI IRIX, PC Mac OS X PC Windows(95/98/NT/2000/XP) ARToolKit ( ) ARToolkit OS 3DCG ( ) OpenGL GLUT 7 ARToolKit 4.1 ARToolKit ARToolKit 1 6 2 5

16 4 ARToolKit 1. 2. 3. 4. 5. VR 6. 3 ARToolKit 4.2 ARToolKit ARToolKit (simpletest(simple.c)) 8 simpletest 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 4 ARToolKit main, init, mainloop, draw, cleanup 5

4.2 ARToolKit 17 main main() main argmainloop() main(int argc, char *argv[]) { init(); arvideocapstart(); argmainloop( NULL, keyevent, mainloop ); 1 arvideocapstart argmainloop rendering loop main program loop init() main ARToolKit ARToolKit ( XML ) Data/camera para.dat) /* open the video path */ if( arvideoopen( vconf ) < 0 ) exit(0); /* find the size of the window */ if( arvideoinqsize(&xsize, &ysize) < 0 ) exit(0); printf("image size (x,y) = (%d,%d)\n", xsize, ysize);

18 4 ARToolKit /* set the initial camera parameters */ if( arparamload(cparaname, 1, &wparam) < 0 ) { printf("camera parameter load error!!\n"); exit(0); arparamchangesize( &wparam, xsize, ysize, &cparam ); arinitcparam( &cparam ); arparamdisp( &cparam ); ( Data/patt.hiro) if( (patt_id=arloadpatt(patt_name)) < 0 ) { printf("pattern load error!!\n"); exit(0); patt id ID /* open the graphics window */ arginit( &cparam, 1.0, 0, 0, 0, 0 ); 2 mailloop() 3 2-5 arvideogetimage /* grab a video frame */ if( (dataptr = (ARUint8 *)arvideogetimage()) == NULL ) { arutilsleep(2); return;

4.2 ARToolKit 19 argdrawmode2d(); argdispimage( dataptr, 0,0 ); ardetectmarker marker num marker info ID marker info[j].id ID marker info[j].cf (0.0 1.0) if( ardetectmarker(dataptr, thresh, &marker_info, &marker_num) < 0 ) { cleanup(); exit(0); ); arvideocapnext(); ID (k==-1) SwapBuffers /* check for object visibility */ k = -1; for( j = 0; j < marker_num; j++ ) { if( patt_id == marker_info[j].id ) { if( k == -1 ) k = j; else if( marker_info[k].cf < marker_info[j].cf ) k = j; if( k == -1 ) { argswapbuffers(); return; argettransmat() i 3x4 patt trans

20 4 ARToolKit /* get the transformation between the marker and the real camera */ argettransmat(&marker_info[k], patt_center, patt_width, patt_trans); draw() 3D draw(); argswapbuffers(); draw() draw,, ARToolKit 3D argdrawmode3d() OpenGL argdraw3dcamera() 3D argdrawmode3d(); argdraw3dcamera( 0, 0 ); glcleardepth( 1.0 ); glclear(gl_depth_buffer_bit); glenable(gl_depth_test); gldepthfunc(gl_lequal); argconvglpara ARToolKit 3x4 OpenGL (4x4 ) OpenGL /* load the camera transformation matrix */ argconvglpara(patt_trans, gl_para); glmatrixmode(gl_modelview); glloadmatrixd( gl_para ); OpenGL 25.0mm glenable(gl_lighting); glenable(gl_light0); gllightfv(gl_light0, GL_POSITION, light_position); gllightfv(gl_light0, GL_AMBIENT, ambi); gllightfv(gl_light0, GL_DIFFUSE, lightzerocolor);

4.2 ARToolKit 21 glmaterialfv(gl_front, GL_SPECULAR, mat_flash); glmaterialfv(gl_front, GL_SHININESS, mat_flash_shiny); glmaterialfv(gl_front, GL_AMBIENT, mat_ambient); glmatrixmode(gl_modelview); gltranslatef( 0.0, 0.0, 25.0 ); glutsolidcube(50.0); OpenGL gldisable( GL_LIGHTING ); gldisable( GL_DEPTH_TEST ); cleanup() cleenup video path arvideocapstop(); arvideoclose(); argcleanup();

22 4 ARToolKit 4.3 ARToolKit OpenGL ARToolKit 3 OpenGL 9 ARToolKit argettransmat() patt trans(3x4 ) r 11 r 33 t x, t y, t z ARToolKit OpenGL 3 OpenGL patt trans = r 11 r 12 r 13 t x r 21 r 22 r 23 t y (1) r 31 r 32 r 33 t z argconvglpara() OpenGL gl para 4x4 argconvglpara(patt_trans, gl_para); glmatrixmode(gl_modelview); glloadmatrixd( gl_para ); r 11 r 12 r 13 t x gl para = r 21 r 22 r 23 t y r 31 r 32 r 33 t z (2) 0 0 0 1 OpenGL X c Y c Z c 1 r 11 r 12 r 13 t x X m = r 21 r 22 r 23 t y Y m r 31 r 32 r 33 t z Z m (3) 0 0 0 1 1 AR OpenGL

4.4 ARToolKit 23 double patt_width = 80.0 mm CG mm 50mm glutsolidcube(50.0) glmatrixmode(gl_modelview); gltranslatef( 0.0, 0.0, 25.0 ); glutsolidcube(50.0); 4.4 ARToolKit ARToolKit Linux ARToolKit $ cd ARToolkit $./Configure Configure 1 3 2 n make $ make ( )/ARToolkit/lib ( )/ARToolkit/bin ( )/ARToolkit/examples bin

24 4 ARToolKit 2 1. samplelite.c Hiro 2. 3. 4. ( ) http://www.hitl.washington.edu/artoolkit/documentation/devmulti.htm 10 11