显示图片
1IplImage* img = cvLoadImage("~/temp.jpeg", 1); 2//create a window to display the image 3cvNamedWindow("picture", 1); 4//show the image in the window 5cvShowImage("picture", img); 6//wait for the user to hit a key 7cvWaitKey(0); 8//delete the image and window 9cvReleaseImage(&img); 10cvDestroyWindow("picture");
打开摄像头
1cvNamedWindow("CameraFrame", CV_WINDOW_AUTOSIZE); 2cv::VideoCapture cap(0); 3 4if (!cap.open(0)) { 5 return -1; 6} 7 8bool stop = false; 9cv::Mat frame; 10 11while(!stop) { 12 cap >> frame; 13 if (!frame.data) { 14 stop = true; 15 continue; 16 } 17 18 imshow("CameraFrame", frame); 19 cvWaitKey(30); 20}
时间/日期
1struct timeval tv; 2struct timezone tz; 3 4// current time since 1900 5gettimeofday(&tv, &tz); 6 7// second 8printf("tv_sec:%ld\n",tv.tv_sec); 9// usecond 10printf("tv_usec:%ld\n",tv.tv_usec); 11 12printf("tz_minuteswest:%d\n",tz.tz_minuteswest); 13printf("tz_dsttime:%d\n",tz.tz_dsttime); 14 15struct tm *p; 16p = localtime(&tv.tv_sec); 17 18// data && time 19printf("time_now:%d/%d/%d %dh-%dm-%ds %ld\n", 20 1900+p->tm_year, 21 1+p->tm_mon, 22 p->tm_mday, 23 p->tm_hour, 24 p->tm_min, 25 p->tm_sec, 26 tv.tv_usec);
时间差/微妙级别
1static int getCurrentMicroSecond() { 2 struct timeval current; 3 double timer; 4 5 gettimeofday(¤t, NULL); 6 timer = 1000000 * current.tv_sec + current.tv_usec; 7 8 return timer; 9}