我试图做一个实时的人脸检测程序,以跟踪在一个房间内的摄像头。然而,当我这样做,它给我不超过4帧每秒(每267毫秒)。我知道使用OpenCV的其他人可以通过使用TBB/OpenMP获得<20 use。
我想得到至少10帧每秒。以下是我为加快这一进程已经采取的行动:
简而言之,我的问题是:为什么我的代码与其他代码相比如此缓慢?我的代码不使用OpenMP或TBB吗?我如何让我的代码使用它?在java中甚至可以使用OpenMP或TBB吗?
我正在我的2012年底的MacBook (核心i7,4Gb内存)上运行程序,安装了windows。
以下是我的当前代码:
public class FaceDetector {
CascadeClassifier faceDetector;
public FaceDetector(){
faceDetector = new CascadeClassifier(new File("haarcascade_frontalface_alt.xml").getPath());
}
/** Image will be overwritten by an image with detected faces on it **/
public Rect[] getFaces(Mat image){
MatOfRect faceDetections = new MatOfRect();
Mat mGray = image;
Imgproc.cvtColor(image, mGray, Imgproc.COLOR_RGBA2GRAY); // Convert to grayscale
faceDetector.detectMultiScale(image, faceDetections, 1.1, 2, 2,new Size(40, 40), new Size(400, 400));
for (Rect rect : faceDetections.toArray()) {
Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(0, 255, 0));
}
return faceDetections.toArray();
}
}提前感谢!
米兰·范迪杰克(阿凡斯应用科学大学学生)
发布于 2014-06-09 03:27:41
我不认为您的代码没有按原样使用OpenMP或TBB。要使用OpenMP,通常需要添加类似于“#语用omp.”之类的内容。在你的循环之前。
类似于:
//#pragma omp parallel for private(j)
for(j = 0; j < _eyesVec.size(); j++ )
{
cv::rectangle(faceROIColor, Rect(_eyesVec[j].x,_eyesVec[j].y,_eyesVec[j].width,_eyesVec[j].height),
cv::Scalar(0,255,0),2,8,0);
}您还必须确保使用已启用OpenMP的opencv二进制文件(使用WITH_OPENMP选项编译)。
https://stackoverflow.com/questions/23875462
复制相似问题