Getting started with OpenCV

首先,你得設置編譯環境(針對Visual C++),包括:

1.添加含“頭文件”的文件夾位置,
<OPENCV_INSTALL>/cv/inlcude
<OPENCV_INSTALL>/cxcore/include
<OPENCV_INSTALL>/cvaux/include
<OPENCV_INSTALL>/otherlibs/cvcam/include
<OPENCV_INSTALL>/otherlibs/highgui

2.添加庫文件所在的文件夾位置,
<OPENCV_INSTALL>/lib

3.和含有源文件的文件夾位置。
<OPENCV_INSTALL>/cv/src
<OPENCV_INSTALL>/cxcore/src
<OPENCV_INSTALL>/cvaux/src
<OPENCV_INSTALL>/otherlibs/highgui
<OPENCV_INSTALL>/otherlibs/cvcam/src/windows

*<OPENCV_INSTALL>即是OpenCV的安裝位置。

然後建立一個工程,添加如下代碼:

#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

int main(int argc, char **argv)
{
    IplImage *img = cvLoadImage("Image.bmp");
    cvNamedWindow("Image:", 1);
    cvShowImage("Image:", img);

    cvWaitKey();
    cvDestroyWindow("Image:");
    cvReleaseImage(&img);

    return 0;
}

當然別忘了添加編譯所需的.lib文件(cxcore.lib cv.lib highgui.lib cvaux.lib),不然鏈接器會顯示無法鏈接函數。然後編譯,運行。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章