GUI命令
窗口管理
cvNamedWindow("win1", CV_WINDOW_AUTOSIZE);
cvMoveWindow("win1", 100, 100); // 以屏幕左上角为起点的偏移量
IplImage* img=0;
img=cvLoadImage(fileName);
if(!img) printf("Could not load image file: %s/n",fileName);
cvShowImage("win1",img);
可显示彩色或灰度的字节/浮点图像。 彩色图像数据认定为BGR顺序.
cvDestroyWindow("win1");
cvResizeWindow("win1",100,100); // 新的宽/高值(象素点)
输入设备
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;
}
}
// x,y: 针对左上角的像点坐标
// event: CV_EVENT_LBUTTONDOWN, CV_EVENT_RBUTTONDOWN, CV_EVENT_MBUTTONDOWN,
// CV_EVENT_LBUTTONUP, CV_EVENT_RBUTTONUP, CV_EVENT_MBUTTONUP,
// CV_EVENT_LBUTTONDBLCLK, CV_EVENT_RBUTTONDBLCLK, CV_EVENT_MBUTTONDBLCLK,
// CV_EVENT_MOUSEMOVE:
// flags: CV_EVENT_FLAG_CTRLKEY, CV_EVENT_FLAG_SHIFTKEY, CV_EVENT_FLAG_ALTKEY,
// CV_EVENT_FLAG_LBUTTON, CV_EVENT_FLAG_RBUTTON, CV_EVENT_FLAG_MBUTTON
mouseParam=5;
cvSetMouseCallback("win1",mouseHandler,&mouseParam);
int key;
key=cvWaitKey(10); // 输入等待10ms
int key;
key=cvWaitKey(0); // 无限等待键盘输入
while(1){
key=cvWaitKey(10);
if(key==27) break;
switch(key){
case 'h':
...
break;
case 'i':
...
break;
}
}
void trackbarHandler(int pos)
{
printf("Trackbar position: %d/n",pos);
}
int trackbarVal=25;
int maxVal=100;
cvCreateTrackbar("bar1", "win1", &trackbarVal ,maxVal , trackbarHandler);
int pos = cvGetTrackbarPos("bar1","win1");
cvSetTrackbarPos("bar1", "win1", 25);