1ãå设已ç»å®è£
äºMinGWï¼å®è£
ç®å½ï¼C:/MinGWï¼å°C:/MinGW/binæ·»å å°ç³»ç»ç¯å¢åéä¸ãå¦æé²ä¸è½½å®è£
MinGW麻ç¦ï¼å¯ä»¥ç´æ¥ä¸è½½ä¸ä¸ªDev-CPPæ许Code::Blockså¼åç¯å¢ï¼è¿ä¸¤ä¸ªIDEä¸é½æ¯èªå¸¦MinGWçã
2ãä¸è½½eclipse-cpp-helios-SR2-win32.zip
3ãå®è£
opencvï¼å设å®è£
ç®å½ä¸ºï¼C:/OpenCV
4ã解åeclipse-cpp-helios-SR2-win32.zipï¼å¯å¨eclipse.exe
æ°å»ºC++项ç®->å¯æ§è¡ç¨åº->Hello World C++ Project
5ãæ·»å 头æ件ååºæ件
å³é®é¡¹ç®éæ©âå±æ§â->C/C++ Build->Settingsã
Tool Settings æ ç¾é¡µï¼GCC C++ Compiler->Includesä¸æ·»å OpenCVç头æ件ç®å½ï¼MinGW C++ Linker->Librariesä¸æ·»å OpenCVçåºæ件ç®å½ä»¥åç¸åºçåºæ件å称ï¼æ³¨æï¼è¿éçåºæ件ä¸å åç¼åï¼
6ãé
ç½®å®æ以åï¼å¯ä»¥ä½¿ç¨ä¸é¢ä»£ç è¿è¡æµè¯ï¼
////////////////////////////////////////////////////////////////////////
//
// hello-world.cpp
//
// 该ç¨åºä»æ件ä¸è¯»å
¥ä¸å¹
å¾åï¼å°ä¹åè²ï¼ç¶åæ¾ç¤ºåºæ¥.
//
////////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int main(int argc, char *argv[])
{
IplImage* img = 0;
int height,width,step,channels;
uchar *data;
int i,j,k;
if(argc<2){
printf("Usage: main <image-file-name>/n/7");
exit(0);
}
// load an image
img=cvLoadImage(argv[1]);
if(!img){
printf("Could not load image file: %s/n",argv[1]);
exit(0);
}
// get the image data
height = img->height;
width = img->width;
step = img->widthStep;
channels = img->nChannels;
data = (uchar *)img->imageData;
printf("Processing a %d*%d image with %d channels/n",height,width,channels);
// create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
// invert the image
// ç¸å½äº cvNot(image);
for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)
data[i*step+j*channels+k]=255-data[i*step+j*channels+k];
// show the image
cvShowImage("mainWin", img );
// wait for a key
cvWaitKey(0);
// release the image
//cvReleaseImage(&img );
return 0;
}
温馨提示:内容为网友见解,仅供参考