First step with OpenCV (corrected)
Load an image, Lena is here.
I made this exercise a few weeks ago, but I had a mistake, and the obtained data were not correct, the first test gave me around 140 milliseconds to load and display an image.To much time if we think that in one second of video, we could have till 30 images per second or even more; one image each 33 miliseconds.
Note: This comparative it is not real, the video has a different compression such as I-Frames (real images) and P-frames( predictive frames)
There are a more things to do as looking for libjpeg-turbo, change the Raspbian to Linaro
But the first thing to do is to correct the code, and separate each time in their different process: Load the image, display the image
This is the new code.
#include <cv.h>
#include <highgui.h>
#include "../00_include/tools.h"
using namespace cv;
int main (int argc, char** argv)
{
Mat imagen;
double flag,flagCarga,flagDisplay, tiempo;
char resultadoCarga[25];
char resultadoDisplay[25];
char resultado[25];
Size imgSize;
//flag of time
flag =(double)getTickCount();
imagen=imread(argv[1],CV_LOAD_IMAGE_UNCHANGED);
//calculate the time
sprintf(resultadoCarga,"Load %2.f",getTick(flag));
namedWindow("FOTO",CV_WINDOW_AUTOSIZE);
//Fetch the size
imgSize = imagen.size();
sprintf(resultado,"Size width=%d height=%d",imgSize.width,imgSize.height);
//New flag of time
flag = (double)getTickCount();
imshow("FOTO",imagen);
//calculate the time
sprintf(resultadoDisplay,"Display %2.f",getTick(flag));
printf("%s\n",resultadoDisplay);
//put the data on the image
putText(imagen,resultadoCarga, Point(10,20),FONT_HERSHEY_SIMPLEX,0.5,BLUE,1);
putText(imagen,resultadoDisplay,Point(10,35),FONT_HERSHEY_SIMPLEX,0.5,BLUE,1);
putText(imagen,resultado,Point(10,50),FONT_HERSHEY_SIMPLEX,0.5,BLUE,1);
#include <highgui.h>
#include "../00_include/tools.h"
using namespace cv;
int main (int argc, char** argv)
{
Mat imagen;
double flag,flagCarga,flagDisplay, tiempo;
char resultadoCarga[25];
char resultadoDisplay[25];
char resultado[25];
Size imgSize;
//flag of time
flag =(double)getTickCount();
imagen=imread(argv[1],CV_LOAD_IMAGE_UNCHANGED);
//calculate the time
sprintf(resultadoCarga,"Load %2.f",getTick(flag));
namedWindow("FOTO",CV_WINDOW_AUTOSIZE);
//Fetch the size
imgSize = imagen.size();
sprintf(resultado,"Size width=%d height=%d",imgSize.width,imgSize.height);
//New flag of time
flag = (double)getTickCount();
imshow("FOTO",imagen);
//calculate the time
sprintf(resultadoDisplay,"Display %2.f",getTick(flag));
printf("%s\n",resultadoDisplay);
//put the data on the image
putText(imagen,resultadoCarga, Point(10,20),FONT_HERSHEY_SIMPLEX,0.5,BLUE,1);
putText(imagen,resultadoDisplay,Point(10,35),FONT_HERSHEY_SIMPLEX,0.5,BLUE,1);
putText(imagen,resultado,Point(10,50),FONT_HERSHEY_SIMPLEX,0.5,BLUE,1);
//Save the image
imwrite("out.jpg",imagen);
waitKey();
}
Well, with the correct software we have this values on the photo.
imwrite("out.jpg",imagen);
waitKey();
}
Well, with the correct software we have this values on the photo.
The values are:
.- Load 41 milliseconds
.- Display: 5 milliseconds
Well this values are no too bad, but it is not computer vision, we did not anything with the image as could be check the blobs, detect a face, and eye, some color, detect objects, etc.
Aprender sin reflexionar es malgastar la energía. Confucio (551 AC-478 AC).
We can see that we have 41 miliseconds to charge an image, so we would check with libjpeg-turbo, and we will see if the load time get reduced, try to use and SATA HD.
.- Display: 5 milliseconds
Well this values are no too bad, but it is not computer vision, we did not anything with the image as could be check the blobs, detect a face, and eye, some color, detect objects, etc.
Aprender sin reflexionar es malgastar la energía. Confucio (551 AC-478 AC).
Learning without thinking is labor lost. Confucius (551BC - 478 BC)
We can see that we have 41 miliseconds to charge an image, so we would check with libjpeg-turbo, and we will see if the load time get reduced, try to use and SATA HD.
The display time was 5 milliseconds, if its computer vision, we do not need see the image, just the cubieboard has to "see" it and process.
This exercise does not give us to much information cause is not related with computer vision.
I will have better information wen have time to make the exercises about computer vision as detect contours, geometry, detect faces, eyes, blobs (contiguous pixels with similar color), etc.
But one important thing is to try Linaro, but I can not do it at this moment, I have to wait a couple of weeks
There is a very interesting information that I learned at the Cubieboard community
getTick(flag)
double getTick(double flag){
/*
This functions return the time in milliseconds
since the "flag" moment till now
*/
//Get the frequency
double frecuencia = getTickFrequency() / 1000 ;
double t = (double)getTickCount();
return((double)t - flag)/frecuencia;
}
//Get the frequency
double frecuencia = getTickFrequency() / 1000 ;
double t = (double)getTickCount();
return((double)t - flag)/frecuencia;
}
No comments:
Post a Comment