Hi all,
I am trying to compute the processing time of CPU implementation to compare it with GPU implementation
I started by using Clock_t instruction available from the time library
I used the instruction system sleep to create a pause of 10 seconds
However what I obtain as result is less than 4 ms
here is my program,
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <time.h>
int main ()
{
clock_t start, stop;
double elapsed;
start = clock();
system("sleep 10");
stop = clock();
elapsed = ((double)stop - start) / CLOCKS_PER_SEC;
FILE *f = fopen("result.txt", "w");
fprintf(f," %.0f \n %.0f \n %.0f \n %.2f \n %f \n %f",(float)start,(float)stop, (float)(stop - start),(float)CLOCKS_PER_SEC, (float)(stop - start)/CLOCKS_PER_SEC,elapsed);
return EXIT_SUCCESS;
}
the whole program is the simple frame difference, when I use the chronometer I obtain 30 s for full HD video, but the clock_t instruction gives me approximately the half
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/opencv.hpp"
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
//using namespace cv;
using namespace std;
int main()
{
clock_t cpu_startTime, cpu_endTime;
float fps; // FPS average
unsigned int frameCount = 0;
double cpu_ElapseTime=0;
cpu_startTime = clock();
cv::VideoCapture input("/home/ubuntu/MyExamples/MD0/cam2Wildtrack.MP4");
cv::Mat img, img_prev0, img_prev, frame, frameDelta, thresh, gray_img;
input.read(img);
img.copyTo(img_prev0);
cv::cvtColor(img_prev0, img_prev, CV_BGR2GRAY);
cv::GaussianBlur(img_prev, img_prev, cv::Size(9, 9), 0);
while(input.read(frame))
{
frameCount++;
cv::cvtColor(frame, gray_img, CV_BGR2GRAY);
cv::GaussianBlur(gray_img, gray_img, cv::Size(9, 9), 0);
cv::absdiff(img_prev, gray_img, frameDelta);
gray_img.copyTo(img_prev);
cv::threshold(frameDelta, thresh, 25, 255, cv::THRESH_BINARY);
cv::imshow("Camera", thresh);
if (frameCount==1999)
{
cpu_endTime = clock();
cpu_ElapseTime = ((cpu_endTime - cpu_startTime)/(float)CLOCKS_PER_SEC);
fps=float(frameCount)/(cpu_ElapseTime);
FILE *f = fopen("result.txt", "w");
fprintf(f, "frame per second: %3.2f fps \n elapsed time: %3.2f s", fps, cpu_ElapseTime);
break;
}
char c=cv::waitKey(1);
if(c == 27)
{
//exit if ESC is pressed
break;
}
}
}
Any help is very appreciated
Thanks in advance
Kamal