Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <opencv2/ocl/ocl.hpp>
- #include <opencv2/highgui/highgui.hpp>
- #include <QDateTime>
- #include <QDebug>
- int main()
- {
- cv::ocl::OclCascadeClassifier detector;
- detector.load("/usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml");
- cv::VideoCapture capture(0);
- cv::Mat frame;
- std::vector<cv::Rect> faces;
- cv::ocl::oclMat oclFrame;
- int counter = 0;
- double uploadTime = 0;
- double detectTime = 0;
- int N = 500;
- while (counter < N && capture.read(frame))
- {
- QDateTime beforeUpload = QDateTime::currentDateTime();
- oclFrame.upload(frame);
- QDateTime afterUpload = QDateTime::currentDateTime();
- detector.detectMultiScale(oclFrame, faces);
- QDateTime afteDetect = QDateTime::currentDateTime();
- uploadTime += beforeUpload.msecsTo(afterUpload);
- detectTime += afterUpload.msecsTo(afteDetect);
- for (const auto &r : faces)
- cv::rectangle(frame, r, cv::Scalar(0, 255, 0));
- cv::imshow("test", frame);
- cv::waitKey(1);
- counter++;
- }
- uploadTime /= N;
- detectTime /= N;
- qDebug() << "uploadTime:" << uploadTime;
- qDebug() << "detectTime:" << detectTime;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement