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(&current, NULL);
    timer = 1000000 * current.tv_sec + current.tv_usec;
    
    return timer;
}

  

 

原文链接: https://www.cnblogs.com/alanfang/p/11290876.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    OpenCV C++常用功能介绍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/300196

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月15日 下午9:12
下一篇 2023年2月15日 下午9:13

相关推荐