OpenCV C++常用功能介绍
显示图片
IplImage* img = cvLoadImage("~/temp.jpeg", 1); //create a window to display the image cvNamedWindow("picture", 1); //show the image in the window cvShowImage("picture", img); //wait for the user to hit a key cvWaitKey(0); //delete the image and window cvReleaseImage(&img); cvDestroyWindow("picture");
打开摄像头
cvNamedWindow("CameraFrame", CV_WINDOW_AUTOSIZE); cv::VideoCapture cap(0); if (!cap.open(0)) { return -1; } bool stop = false; cv::Mat frame; while(!stop) { cap >> frame; if (!frame.data) { stop = true; continue; } imshow("CameraFrame", frame); cvWaitKey(30); }
时间/日期
struct timeval tv; struct timezone tz; // current time since 1900 gettimeofday(&tv, &tz); // second printf("tv_sec:%ld\n",tv.tv_sec); // usecond printf("tv_usec:%ld\n",tv.tv_usec); printf("tz_minuteswest:%d\n",tz.tz_minuteswest); printf("tz_dsttime:%d\n",tz.tz_dsttime); struct tm *p; p = localtime(&tv.tv_sec); // data && time printf("time_now:%d/%d/%d %dh-%dm-%ds %ld\n", 1900+p->tm_year, 1+p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, tv.tv_usec);
时间差/微妙级别
static int getCurrentMicroSecond() { struct timeval current; double timer; gettimeofday(¤t, NULL); timer = 1000000 * current.tv_sec + current.tv_usec; return timer; }