我正在使用opencv库和haarcascades进行一些眼动追踪,但我试图稍微调整一下代码,因为它将我的CPU接近200%。 关键是我想出了多少功率只需要从相机中取出帧并将其放在窗口中,我惊讶的是它将CPU降至50%,只有最简单的代码:
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
//GLOBAL VARIABLES
cv::String cascadePath = "./cascades/haarcascade_eye.xml";
cv::CascadeClassifier cascade;
cv::String windowTitle = "Auto Aim Eye Tracking";
int camNum = 0;
int main(int argc, const char * argv[]) {
cascade.load(cascadePath);
cv::Mat frame;
if (cascade.empty())
{
std::cout << "Error loading cascade\n";
return -1;
}
cv::namedWindow (windowTitle, CV_WINDOW_NORMAL);
cv::VideoCapture camera(0);
if (!camera.isOpened())
{
camera.open(1);
camNum=1;
if (!camera.isOpened())
{
camera.open(2);
camNum=2;
if (!camera.isOpened())
{
std::cout << "*** UNABLE TO OPEN ANY CAM ***\n*** Press ENTER to exit ***\n";
std::cin.get();
return -1;
}
}
}
while (true){
camera.read(frame);
imshow(windowTitle, frame);
if (cv::waitKey(30) >= 0)
break;
}
std::cout << "*** END OF PROGRAM ***\n*** Press ENTER to exit ***\n";
std::cin.get();
return 0;
}
我想知道是否存在任何其他方法可以使它变轻。
感谢。
P.S:我在MacBook Pro 2017上工作。