OpenCV/処理にかかった時間を表示する

Last-modified: 2006-12-14 (木) 20:21:30

スクリーンショット

20061212.JPG
filemain.cpp

//==============================================================================
//?C???N???[?h
//==============================================================================
#include "cv.h"
#include "highgui.h"
#include <stdio.h>

// ???C?u??????????
#pragma comment(lib,"cv.lib")
#pragma comment(lib,"cxcore.lib")
#pragma comment(lib,"cvaux.lib")
#pragma comment(lib,"highgui.lib")

//==============================================================================
//???C??
//==============================================================================
int main( int argc, char** argv )
{
    IplImage* frame;    //?L???v?`???p
    IplImage* image;    //?\ヲ?p
    CvCapture *capture;
    char* window_name = "Simple Capture";
    //????x?\ヲ?p
    CvFont dfont;
    char message[64] = "";
    
    //?t?H???g??????
    cvInitFont (&dfont, CV_FONT_HERSHEY_SIMPLEX , 1.0f, 1.0f, 0.0f, 2, CV_AA);
    
    capture = cvCaptureFromCAM(-1);

    //?J??????????????
    if(capture==NULL)	{
        printf("No Camera is Found.\n");
        return -1;
    }

    //?E?C???h?E???
    cvNamedWindow(window_name, 1);

    //????L???v?`????????A??????mage???`
    frame = cvQueryFrame(capture);
    image = cvCloneImage(frame);

    //?????[?v
    while(1)
    {
        double t = (double)cvGetTickCount();
        int c;

        //?L???v?`?????mage??R?s?[
        frame = cvQueryFrame(capture);
        cvCopy(frame, image);

        //?L?[??????
        c = cvWaitKey(10);
        if( (char)c == 27 ) {   //Ecs?L?[??I??
            break;
        }
               
        //?O??cvGetTickCount() ???s????????o??????Z?
        t = (double)cvGetTickCount() - t;
        sprintf(message, "%gms", t/((double)cvGetTickFrequency()*1000.) );

        //?e?L?X?g??\ヲ
        cvPutText(image, message, cvPoint(50, 50), &dfont, CV_RGB(255, 255, 255));
        
        //?????\ヲ
        cvShowImage(window_name, image);
    }

    //???
    cvDestroyWindow(window_name);
    cvReleaseImage(&image);

    return 0;
}