OpenCV C++常用機能紹介
1727 ワード
画像を表示
カメラを開く
時刻/日付
時間差/微妙レベル
転載先:https://www.cnblogs.com/alanfang/p/11290876.html
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
",tv.tv_sec);
// usecond
printf("tv_usec:%ld
",tv.tv_usec);
printf("tz_minuteswest:%d
",tz.tz_minuteswest);
printf("tz_dsttime:%d
",tz.tz_dsttime);
struct tm *p;
p = localtime(&tv.tv_sec);
// data && time
printf("time_now:%d/%d/%d %dh-%dm-%ds %ld
",
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;
}
転載先:https://www.cnblogs.com/alanfang/p/11290876.html