1 22 (2) TA: 2010 12 13 1 OpenGL Wii Wii OpenGL USB (3DCG) 1.1 http://www.cyber.t.u-tokyo.ac.jp/~kuni/enshu2010/ URL USB
2 2 1.2 TA 16 15 TA TA mireport@cyber.t.u-tokyo.ac.jp 20101213 abcdefgh abcdefgh 2 2.1 13C PC Wii bluetooth 2.2 Bluetooth USB Princeton PTM-UBT3S 1 1 USB 2.3 Wii 1 1 2.4 Bluetooth USB USB 2.5 Wii CWiid http://www.cyber.t.u-tokyo.ac.jp/ kuni/enshu2010/cwiid-0.5.03.tgz CWiid
2.5 Wii 3 tar xvzf cwiid-0.5.03.tgz./configure make sudo make install CWiid 00:00:00:00:00:00 Wii Bluetooth cd cwiid-0.5.03/wmgui./wmgui 00:00:00:00:00:00 wmgui File Connect 1 Connect Connect Settings Acc Data Wii
4 3 2 3 Wii Wii Bluetooth Wii 3.1 Wii Wii Wii Wii Wii Fit Wii Wii 3 IC Bluetooth IC CMOS Bluetooth 3 3.2 CWiid CWiid http://abstrakraft.org/cwiid/ Linux C Wii Wiimote) API Wii API Wiimote GTK GUI Download
3.2 CWiid 5 3 Wii http://www.nintendo.co.jp/wii/features/wii remote.html CMOS Wii wiimote command state 1 ON 0 OFF command WIIMOTE CMD RUMBLE WIIMOTE CMD LED LED wiimote_command(wiimote, command, int state); void set_report_mode(void) { uint8_t rpt_mode; rpt_mode = WIIMOTE_RPT_STATUS WIIMOTE_RPT_BTN; rpt_mode = WIIMOTE_RPT_ACC; wiimote_command(wiimote, WIIMOTE_CMD_RPT_MODE, rpt_mode); Wii Wii unionwiimote mesgmesg array mesg arraytype acc zero, acc one zeropoint 1Gpoint
6 3 void wiimote_callback(int id, int mesg_count, union wiimote_mesg *mesg_array[]) { int i; for (i=0; i < mesg_count; i++) { switch (mesg_array[i]->type) { case WIIMOTE_MESG_ACC: wiimote_acc(&mesg_array[i]->acc_mesg); break; case WIIMOTE_MESG_BTN: wiimote_btn(&mesg_array[i]->btn_mesg); break; default: break; Wii mesg > x, mesg > y, mesg > z void wiimote_acc(struct wiimote_acc_mesg *mesg) { printf("x: %d, y: %d, z: %d\t", mesg->x, mesg->y, mesg->z); double a_x, a_y, a_z; a_x = ((double)mesg->x - acc_zero.x) / (acc_one.x - acc_zero.x); a_y = ((double)mesg->y - acc_zero.y) / (acc_one.y - acc_zero.y); a_z = ((double)mesg->z - acc_zero.z) / (acc_one.z - acc_zero.z); Wii
3.2 CWiid 7 void wiimote_btn(struct wiimote_btn_mesg *mesg){ if(mesg->buttons & WIIMOTE_BTN_UP){ WIIMOTE BTN UP WIIMOTE BTN DOWN WIIMOTE BTN RIGHT WIIMOTE BTN LEFT WIIMOTE BTN PLUS WIIMOTE BTN MINUS WIIMOTE BTN A A WIIMOTE BTN B B WIIMOTE BTN HOME HOME WIIMOTE BTN 1 1 WIIMOTE BTN 2 2 Wii Wii 4 Wii http://wiibrew.org/images/9/9e/wiimote axis2.png Yaw, Pitch, Roll Yaw, Pitch, Roll 5 CWiid CWiid Makefile cwiid-0.5.03/wiimote wiimote
8 3 5 Yaw,Pitch,Roll http://sorceryforce.com/programing/mdx/direct3d/stepup/quaternion.html CC = g++ COMMON =. PACKAGE_VERSION = 0.5.03 WIIMOTE_DIR =../../cwiid-0.5.03/wiimote ( RM = rm -f TARGET = sample OBJS = sample.o CFLAGS = -Wall -I${WIIMOTE_DIR \ #-DCWIID_VERSION=\"${PACKAGE_VERSION\" LDFLAGS = -L${WIIMOTE_DIR LDLIBS = -lglut -lgl -lglu -lwiimote.c.o: ${CC -c ${CFLAGS $< ${TARGET: ${OBJS ${CC -o ${TARGET ${OBJS ${LDLIBS ${LDFLAGS clean: ${RM ${TARGET *.o *
3.2 CWiid 9 1 1. kadai.tar.gz kadai1 sample.c Bluetooth 00:00:00:00:00:00 Bluetooth Wii./sample 00:00:00:00:00:00 a Wii A B b 1! 2 Wii LED 1 2 r R] Wii c WireCube 2. kadai2 sample.c Wii Teapot a b B c d 3. kadai3 sample.c Wii.disp flag a b Wii c d
10 3 6 Wii 7 Teapot Wii 8 Wii
11 4 USB OpenGL Linux Linux Video for Linux(Video4Linux, v4l ) API Video4Linux USB IEEE1394 API Linux Video for Linux 2(Video4Linux2, v4l2 ) API USB (USB Video Class, UVC) USB 2.0 Linux Linux Video4Linux lsmod lsmod grep video ) uvcvideo 51204 0 compat_ioctl32 5569 1 uvcvideo videodev 30785 1 uvcvideo v4l1_compat 17349 2 uvcvideo,videodev v4l2_common 20801 2 uvcvideo,videodev 4.1 OpenCV Video4Linux API OpenCV(Open Source Computer Vision Library) OpenCV OpenGL Video4Linux API OS OpenCV OS OS OpenCV OpenGL 3DCG 3DCG OpenCV
12 4 OpenCV http://opencv.jp/ http://opencv.jp/sample/ 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.1 13 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>
14 4 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
4.1 15 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
16 4 cvcreatecameracapture() cvcreatefilecapture() cvreleasecapture() void cvreleasecapture( CvCapture** capture ); capture 4.2 Window 9) 9 OpenGL OpenCV /* OpenGL */ #include <GL/glut.h> /* OpenCV */ #include <opencv/cv.h> #include <opencv/highgui.h>
4.2 17 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);
18 4 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);
4.3 19 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(); 4.3 10 : sample-texture.c 10 3 glteximage2d() 2 gltexsubimage2d()
20 4 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 11 640 480 1024 512 gltexcoord() 0.625(=640/1024) 0.9375(=480/512)
4.3 21 void gltexcoord{1,2,3,4{s,i,d,f(type coords); void gltexcoord{1,2,3,4{s,i,d,fv(type *coords); 11 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();
22 A 3 ( 10) 3 ( 12) 2 1. opencv-sample.tar.gz USB 2. opencv-texture.tar.gz 10 3. opencv-divtex.tar.gz TODO 2.3 4. 12 1 5. opencv-dynamic.tar.gz 12 3 A Wii 2007.12, Vol.110, No.1069, pp.6-7 2007