2024年3月21日 星期四

BK Week05

 # Week05

## OpenCV 安裝

1. 下載 OpenCV-2.1.0-win32-vs2008.exe

2. 小心1: Add OpenCV to . . . PATH

3. 小心2: 要安裝在預設的 C:\OpenCV2.1 目錄裡

4. 安裝完成後, CodeBlocks 要重開

5.設定 Setting-Compiler 要加入3個設定

    a. search 目錄 Compiler 的 include 目錄裡 加 C:\OpenCV2.1\include

    b. search 目錄 Linker 的 lib 目錄 加 C:\OpenCV\lib

    c. 加入 Linker 的 3個檔名 cv210 cxcore210 highgui210


## week05-1_opencv.cpp

0. 找一個圖片, 將圖片存為 C:\image.jpg 

1. File-New-Empty File 空白檔案,  week05-1_opencv.cpp

2. 加上下面的程式碼

    #include <opencv/highgui.h>

    int main()

    {///Intel performence library

        IplImage * img = cvLoadImage("c:/image.jpg");

        cvShowImage("week05", img);

        cvWaitKey(0);

    }




## week05-2_opencv_webcam.cpp

1. 沒有攝影機, 所以沒有執行畫面

2. 加入新的幾行程式碼, 變成下面這樣

##week05-3_opencv_many_webcam.cpp

## 課本範例

1. jsyeh.org/3dcg10 下載 data win32

2. wiondows.zip  => 下載\wiondows\Texture.exe

3. data.zip => 下載\windows\data\一堆圖檔

4. 執行 Texture.exe

5. 改 glTexCoord2f (tx, ty); 貼圖座標, 


## week05_opencv_cvLoadImage
1. File-New-project, GLUT專案, week05_opencv_cvLoadImage

2. 貼上11行 GLUT 程式

3. 加上3行 OpenCV 的程式




##week05_opencv_opengl_myTexture

1. moodle 老師有貼一行網址, 點進去之後複製18行程式碼

2. File-New-project, GLUT專案, week05_opencv_opengl_myTexture

3. 貼上18行程式碼 + 11行程式碼

4. 加上橘色的部分
    int main(){
        ......
        myTexture("c:/image.jpg");
        glutMainLoop();
    }

5. 讓圖片印在茶壺上


##week05_opencv_opengl_myTexture_glTexCoord2f

1. File-New-project, GLUT專案, week05_opencv_opengl_myTexture_glTexCoord2f

2. 貼上 week05_opencv_opengl_myTexture

3. 加入橘色部分
    void display()
    {
        glBegin(GL_POLYGON);
            glTexCoord2f(0,0); glVertex2f(-1,-1);
            glTexCoord2f(0,1); glVertex2f(-1,+1);
            glTexCoord2f(1,1); glVertex2f(+1,+1);
            glTexCoord2f(1,0); glVertex2f(+1,-1);
        glEnd()
    }

##week05_rotating_earth

0. google: earth map 找圖片, 滿版的地圖, 存在 c:earth.jpg

1. File-New-project, GLUT專案, week05_rotating_earth

2. 把 week05_opencv_opengl_myTexture 拿來用

3.前面先加入下面這行
    GLUquadric * quad = NULL; ///todo: 要有一顆指標

4. 加入橘色部分
    float angle = 0;
    void display()
    {
        glEnable(GL_DEPTH_TEST);
        glPushMatrix();
            glRotatef(90, 1, 0, 0);
            glRotatef(angle++, 0, 0, 1);
            gluSphere(quad, 1, 30, 30);
        glPopMatrix();
    }
    int main(int argc, char*argv[])
    {
        glutIdleFunc(display);
        quad = gluNewQuadric();///todo: 把這顆指標做好
        gluQuadricTexture(quad, 1);///todo: 做好地球貼圖
    }



沒有留言:

張貼留言