2022年4月19日 星期二

一定是大拇指的啦

  step 0 :下載模型

0.0  jsyeh.org/3dcg10 下載  data.zip  , windows.zip

0.1 data.zip =>下載/windows/data

     windows.zip => 下載/windows/Texture.exe

step1 : Texture.exe解釋


1.1 右邊程式碼星星對照左邊貼圖位置

1.2 座標採逆時針方式寫順序


step 2 : 下載OpenCV

2.1 moodle 下載 opencv 2.1.0 win32 vs2008

2.2 安裝時 Add PATH 選第2個 



2.3 目錄不要改

2.4 CodeBlock要重開 ( PATH安裝完後便會修改PATH的設定)


step 3 : 開啟、設定

3.1 開啟CodeBlock    File-New-EmptyFile  命名為week09_opencv.cpp

3.2 輸入程式碼

#include <opencv/highgui.h>///使用外掛highgui

int main()

{

    IplImage *img = cvLoadImage("檔名.jpg");///檔名依照圖片名稱

    cvShowImage("week09",img);

    cvWaitKey(0);

}

3.3設定 Include 、 Lib 、 Linker

3.3.1 Setting-Compiler  -> Search directories-Compiler -> Add 輸入 C:OpenCV2.1\include ->OK



3.3.2 Setting-Compiler  -> Search directories-Linker -> Add 輸入 C:OpenCV2.1\lib ->OK



3.3.3 Setting-Compiler  -> Linker setting -> Add 輸入 cv210 、 cxcore210 、 highgui210 ->OK


3.4 執行結果 (若是不行就關掉重開)



step 4 : 結合openCV 和 openGL 程式碼

4.1 剪貼 openGL 的茶壺程式碼

#include <GL/glut.h>

void display()

{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glutSolidTeapot(0.3);

    glutSwapBuffers();

}

int main(int argc , char**argv)

{

    glutInit( &argc , argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week09 Texture");

    glutDisplayFunc(display);

    glutMainLoop();

}

4.2 貼上openCV 的程式碼

#include <opencv/highgui.h>///使用外掛highgui

int main()

{

    IplImage *img = cvLoadImage("檔名.jpg");///檔名依照圖片名稱

    cvShowImage("week09",img);

    cvWaitKey(0);

}

4.3 結合 openCV 和 openGL 程式碼

#include <GL/glut.h>

#include <opencv/highgui.h>///使用外掛highgui

void myTexture()///要改成void

{

    IplImage *img = cvLoadImage("檔名.jpg");///檔名依照圖片名稱

    cvShowImage("opencv",img);///改檔名opencv做區分

    cvWaitKey(0);

}

void display()

{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glutSolidTeapot(0.3);

    glutSwapBuffers();

}

int main(int argc , char**argv)

{

    glutInit( &argc , argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week09 Texture");

    glutDisplayFunc(display);

    myTexture();///新增

    glutMainLoop();

}

4.4 執行結果



step 5 : 兩張圖結合一起

5.1 到https://gist.github.com/jsyeh/5ed01210559721ec71b659b3ffed2dd7 複製程式碼

5.2 圖片須放在freeglut/bin

5.3 取代原先openCV的程式碼

#include <opencv/highgui.h> ///使用 OpenCV 2.1 比較簡單, 只要用 High GUI 即可

#include <GL/glut.h>

#include <opencv/cv.h>

int myTexture(char * filename)

{

    IplImage * img = cvLoadImage(filename); ///OpenCV讀圖

    cvCvtColor(img,img, CV_BGR2RGB); ///OpenCV轉色彩 (需要cv.h)

    glEnable(GL_TEXTURE_2D); ///1. 開啟貼圖功能

    GLuint id; ///準備一個 unsigned int 整數, 叫 貼圖ID

    glGenTextures(1, &id); /// 產生Generate 貼圖ID

    glBindTexture(GL_TEXTURE_2D, id); ///綁定bind 貼圖ID

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); /// 貼圖參數, 超過包裝的範圖T, 就重覆貼圖

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); /// 貼圖參數, 超過包裝的範圖S, 就重覆貼圖

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); /// 貼圖參數, 放大時的內插, 用最近點

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); /// 貼圖參數, 縮小時的內插, 用最近點

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->imageData);

    return id;

}

void display()

{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glutSolidTeapot(0.3);

    glutSwapBuffers();


}

int main(int argc , char**argv)

{

    glutInit( &argc , argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week09 Texture");

    glutDisplayFunc(display);

    myTexture("1.jpg");///輸入圖片名稱 在freeglut/bin

    glutMainLoop();


}

5.4 顯示結果








沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

一.     一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam,                 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...