C++ Builder中使用OpenCV

C++ Builder中使用OpenCV  
<1> 转换DLL为 .lib 文件
建立如下批处理文件:
coff2omf -lib:ms  lib/cv.lib                 bcb/cv.lib
coff2omf -lib:ms lib/cvaux.lib              bcb/cvaux.lib
coff2omf -lib:ms  lib/cvcam.lib              bcb/cvcam.lib
coff2omf -lib:ms  lib/cvhaartraining.lib     bcb/cvhaartraining.lib
coff2omf -lib:ms  lib/cxcore.lib             bcb/cxcore.lib
coff2omf -lib:ms  lib/cxts.lib               bcb/cxts.lib
coff2omf -lib:ms  lib/highgui.lib            bcb/highgui.lib
coff2omf -lib:ms  lib/ml.lib                 bcb/ml.lib 

 

保存为.bat文件放在D:/Program Files/OpenCV/lib下运行

*.lib文件可以到http://tech.groups.yahoo.com/group/OpenCV/files/Borland%20C%2B%2B%20builder/下载
 <2> 在系统变量里面添加 OPENCV 为 X:/Program Files/OpenCV,
设置“工具”->“环境变量”->“库”,在“库路径”里面添加 $(OPENCV)/cbuilder;$(OPENCV)/bin

<3>新建一个控制台工程,不要VCL支持。然后选择“工程”->“添加到工程”,把刚才转换好的.lib文件添加到工程中即可。

在工程的设置里面在Directories/Conditonals 里面的Include Path 添加$(OPENCV)/cv/include;$(OPENCV)/cxcore/include;$(OPENCV)/otherlibs/highgui(otherlib中可能还有其他的头文件);$(OPENCV)/cvaux/include;$(OPENCV)/otherlibs/cvcam/include
在Library Path 里面添加 $(OPENCV)/lib
General Compilation的Calling Convention改为C

<4> 编辑你的代码,调试允许吧:

示例程序:
    读取 lena.jpg 图象并显示:
------------------------------------------------------------------------------
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

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

    cvWaitKey();
    cvDestroyWindow("Image:");
    cvReleaseImage(&img);
   
    return 0;
}

你可能感兴趣的:(C++,image,Path,include,library,compilation)