我在 BeagleBone Black + Opencv Object Counter 中面临性能问题。我正在使用 BackgroundSubtractorMOG2 进行背景减法和轮廓检测。下面是代码:
cv::Mat frame;
cv::Mat resizedFrame;
cv::Mat back;
cv::Mat fore;
bool objStart = false;
bool objEnd = false;
bool start = true;
cv::Point startLine(0, 50); // this is the start of the line where I take decision
cv::Point endLine(1000, 50); // this is the end of the line
cv::VideoCapture cap("/home/moonzai/Videos/test.avi");
cv::BackgroundSubtractorMOG2 bg;
bg.set("nmixtures", 3);
vector<vector<cv::Point> > contours;
for(;;)
{
cap >> resizedFrame;
cv::resize(resizedFrame, frame, cv::Size(320, 240), 0, 0, cv::INTER_LINEAR); // I wrote this line when there were only 1 frame per second processing, I resized the frame to 320 X 240
if(start)
{
bg.operator ()(frame,fore);
bg.getBackgroundImage(back);
cv::erode(fore,fore,cv::Mat());
cv::dilate(fore,fore,cv::Mat());
cv::findContours(fore,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
vector<cv::Rect> boundRect( contours.size() );
cv::Rect mainRect;
for( unsigned int i = 0; i < contours.size(); i++ )
{
boundRect[i] = boundingRect( cv::Mat(contours[i]) );
if(mainRect.area() < boundRect[i].area())
{
mainRect = boundRect[i];
}
}
if(LineIntersectsRect(startLine, endLine, mainRect)) // this function actually returns boolean, if rectangle is touching the line
{
objStart = true;
}
else
{
if(objStart)
{
objEnd = true;
}
}
if(objEnd && objStart)
{
counter ++;
cout << "Object: " << counter << endl;
objEnd = false;
objStart = false;
}
}
usleep(1000 * 33);
}
这段代码在我的台式机上运行完美。但是当我在安装了 Ubuntu 13.04 linux 的 BeagleBone Black 上运行这段代码时,这个发行版根本没有 GUI,我在终端上工作,它给我 80% 的 CPU 使用率,每秒处理 2 帧。内存使用率非常低,大约 8%,我没有得到我想要的性能。所以如果我做错了什么,请指导我。
我的问题的目的是,是否有任何与编码相关的问题,或者 BackgroundSubtractorMOG2 资源匮乏,所以我必须使用另一种方式。如果还有其他方法,那么请指导我那是什么方法?
提前致谢...