cxcore.lib cv.lib ml.lib cvaux.lib highgui.lib cvcam.lib
如果你不需要这么多lib,你可以只添加你需要的lib。
///
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
void mouseHandler(int event, int x, int y, int flags, void* param);
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);
}
// 载入图像
img=cvLoadImage(argv[1]);
if(!img){
printf("Could not load image file: %s\n",argv[1]);
exit(0);
}
// 获取图像数据
height = img->height;
width = img->width;
step = img->widthStep;
channels = img->nChannels;
data = (uchar *)img->imageData;
printf("Processing a %dx%d image with %d channels\n",height,width,channels);
// 创建窗口
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
//cvMoveWindow("mainWin", 100, 100);
cvResizeWindow("mainWin",200,200); // 新的宽/高值(象素点)
int mouseParam=5;
cvSetMouseCallback("mainWin",mouseHandler,&mouseParam);
// 显示图像
cvShowImage("mainWin", img );
// wait for a key
cvWaitKey(0);
// 反色图像
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];
// 显示图像
cvShowImage("mainWin", img );
char key;
while(1){
key=cvWaitKey(0);
if(key==27) break;
else printf("%c\n",key);
}
cvDestroyWindow("mainWin");
// release the image
cvReleaseImage(&img );
return 0;
}
void mouseHandler(int event, int x, int y, int flags, void* param)
{
switch(event){
case CV_EVENT_LBUTTONDOWN:
if(flags & CV_EVENT_FLAG_CTRLKEY)
printf("Left button down with CTRL pressed\n");
break;
case CV_EVENT_LBUTTONUP:
printf("Left button up\n");
break;
}
}
helloKey
最新推荐文章于 2022-02-25 21:57:21 发布