首页 > 代码库 > OpenCV Windows7 VC6.0安装以及HelloWorld
OpenCV Windows7 VC6.0安装以及HelloWorld
anna在实验室配置OpenCV的时候,按照中文网站的介绍,很顺利的就完成了。可是回到家情况就大不一样!!总是在链接的时候报错,不是少这个lib就是少那个lib大哭最后查明是anna马虎,忘了将C:\Program Files\OpenCV\lib加入Library files!下面是详细的配置过程:
1.安装OpenCV
2.检查C:\Program Files\OpenCV\bin是否已经被加入到环境变量PATH,如果没有,请加入。加入后需要注销当前Windows用户(或重启)后重新登陆才生效。
3.配置VC
全局设置:
菜单Tools->Options->Directories:先设置lib路径,选择Library files,在下方填入路径:
C:\Program Files\OpenCV\lib 《《------这一行字比较不醒目,但是很重要滴!!不要忘记哦
然后选择include files,在下方填入路径:
C:\Program Files\OpenCV\cxcore\include
C:\Program Files\OpenCV\cv\include
C:\Program Files\OpenCV\cvaux\include
C:\Program Files\OpenCV\ml\include
C:\Program Files\OpenCV\otherlibs\highgui
C:\Program Files\OpenCV\otherlibs\cvcam\include
然后选择source files,在下方填入路径:
C:\Program Files\OpenCV\cv\src
C:\Program Files\OpenCV\cxcore\src
C:\Program Files\OpenCV\cvaux\src
C:\Program Files\OpenCV\otherlibs\highgui
C:\Program Files\OpenCV\otherlibs\cvcam\src\windows
最后点击“ok”,完成设置。
项目设置:
每创建一个将要使用OpenCV的VC Project,都需要给它指定需要的lib。菜单:Project->Settings,然后将Setting for选为All Configurations,然后选择右边的link标签,在Object/library modules附加上
cxcore.lib cv.lib ml.lib cvaux.lib highgui.lib cvcam.lib
点击OK,就大功告成啦
HelloWorld
该实例来自OpenCV自带Simple drawing.c经删除后整理
#ifdef _CH_#pragma package <opencv>#endif#ifndef _EiC#include "cv.h"#include "highgui.h"#include <stdlib.h>#include <stdio.h>#endif#define NUMBER 100#define DELAY 5char wndname[] = "Drawing Demo";CvScalar random_color(CvRNG* rng){ int icolor = cvRandInt(rng); return CV_RGB(icolor&255, (icolor>>8)&255, (icolor>>16)&255);}int main( int argc, char** argv ){ int line_type = CV_AA; // change it to 8 to see non-antialiased graphics int i; CvPoint pt1; double angle; CvSize sz; CvPoint ptt[6]; CvPoint* pt[2]; int arr[2]; CvFont font; CvRNG rng; int width = 1000, height = 700; int width3 = width*3, height3 = height*3; CvSize text_size; int ymin = 0; // Load the source image IplImage* image = cvCreateImage( cvSize(width,height), 8, 3 ); IplImage* image2; // Create a window cvNamedWindow(wndname, 1 ); cvZero( image ); cvShowImage(wndname,image); rng = cvRNG((unsigned)-1); pt[0] = &(ptt[0]); pt[1] = &(ptt[3]); arr[0] = 3; arr[1] = 3; cvInitFont( &font, CV_FONT_HERSHEY_COMPLEX, 3, 3, 0.0, 5, line_type ); cvGetTextSize( "OpenCV forever!", &font, &text_size, &ymin ); pt1.x = (width - text_size.width)/2; pt1.y = (height + text_size.height)/2; image2 = cvCloneImage(image); for( i = 0; i < 255; i++ ) { cvSubS( image2, cvScalarAll(i), image, 0 ); cvPutText( image, "OpenCV forever!", pt1, &font, CV_RGB(255,i,i)); cvShowImage(wndname,image); cvWaitKey(DELAY); } // Wait for a key stroke; the same function arranges events processing cvWaitKey(0); cvReleaseImage(&image); cvReleaseImage(&image2); cvDestroyWindow(wndname); return 0;}#ifdef _EiCmain(1,"drawing.c");#endif