Tool/software: Linux
Hello, all.
I'm using am57xx-evm now, and I have some problem concerning CPU loading and delay in capturing videos from two web cameras.
I wrote a simple demo program to read videos from two cameras through two USB channels (I have put the micro-USB in host mode), and combine them together to show on a display through HDMI. However, the CPU loading is high. If I read videos from two cameras, my program takes up CPU loading of 80-90%, while the weston takes up the CPU loading of 30-50%. If I read videos from only one camera, it seems that my CPU loading doesn't make much difference, they are almost the same. From my sense, if I just read videos from only one camera, the CPU loading will drop much, maybe at least 30%, which is not the case.
Besides, the delay in capturing videos is also large. Roughly, it is almost 1s, which is unstandable.
How can I decrease the CPU loading and reduce the delay?
Thanks.
Li Qi
The following is my simple demo code for capturing
## For capturing 2 cameras
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <string>
#include <unistd.h>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
int device_id[2];
if(argc != 3)
{
printf("Wrong arguments.\n");
exit(-1);
}
else
{
device_id[0] = argv[1][0] - '0';
device_id[1] = argv[2][0] - '0';
}
string winName = "Window | Press Esc to exit the program";
namedWindow(winName, WINDOW_NORMAL);
moveWindow(winName, 0, 0);
setWindowProperty(winName, WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
VideoCapture capLeft(device_id[0]);
VideoCapture capRight(device_id[1]);
if(!capLeft.set(CV_CAP_PROP_FRAME_WIDTH,960))
printf("capLeft set width failed.\n");
if(!capLeft.set(CV_CAP_PROP_FRAME_HEIGHT,720))
printf("capLeft set height failed.\n");
if(!capRight.set(CV_CAP_PROP_FRAME_WIDTH,960))
printf("capRight set width failed.\n");
if(!capRight.set(CV_CAP_PROP_FRAME_HEIGHT,720))
printf("capRight set height failed.\n");
bool firstTime = true;
while(1)
{
Mat leftFrame, rightFrame, comFrame;
capLeft>>leftFrame;
capRight>>rightFrame;
int cols = leftFrame.cols;
int rows = leftFrame.rows;
if(firstTime)
{
printf("image size is %d %d.\n", cols, rows);
firstTime = false;
}
comFrame = Mat(rows, cols * 2, leftFrame.type());
leftFrame.copyTo(comFrame.colRange(0,cols));
rightFrame.copyTo(comFrame.colRange(cols,cols*2));
imshow(winName,comFrame);
char key = waitKey(10);
if(key == 27)
break;
usleep(10000); // 10 ms
comFrame.release();
}
}
## For capturing 1 camera
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <string>
#include <unistd.h>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
int device_id;
if(argc > 2)
{
printf("Wrong arguments.\n");
exit(-1);
}
else if(argc == 2)
{
device_id = argv[1][0] - '0';
}
else
{
device_id = 1;
}
string winName = "Window | Press Esc to exit the program";
namedWindow(winName, WINDOW_NORMAL);
moveWindow(winName, 0, 0);
setWindowProperty(winName, WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
VideoCapture cap(device_id);
// if(!cap.is)
if(!cap.set(CV_CAP_PROP_FRAME_WIDTH,960))
printf("set width failed.\n");
if(!cap.set(CV_CAP_PROP_FRAME_HEIGHT,720))
printf("set height failed.\n");
double time1,time2;
bool firstTime = true;
while(1)
{
time1 = (double)getTickCount();
Mat frame;
cap>>frame;
time2 = (double)getTickCount();
//printf("elapsed time in capture is: %f ms.\n",(time2 - time1)*1000/getTickFrequency());
time1 = (double)getTickCount();
int cols = frame.cols;
int rows = frame.rows;
if(firstTime)
{
printf("cols: %d, rows: %d.\n",cols,rows);
firstTime = false;
}
imshow(winName,frame);
time2 = (double)getTickCount();
//printf("Time elapsed in capture and imshow is %.3f ms.\n",(time2 - time1) * 1000.0 / getTickFrequency());
time1 = (double)getTickCount();
char key = waitKey(10);
if(key == 27)
break;
//usleep(5000); // 10 ms
//frame.release();
time2 = (double)getTickCount();
//printf("Time elapsed in watkey and release is %.3f ms.\n",(time2 - time1) * 1000.0 / getTickFrequency());
}
}