大佬教程收集整理的这篇文章主要介绍了c – 将opencv库与g链接起来,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
$g++ -Wall eye-tracking.cpp -o eyeTracking
$pkg-config --libs opencv
但在这里我再也不知道如何将输出链接到我的命令.
我通过输入以下命令尝试了我的逻辑:
$g++ -Wall eye-tracking.cpp -I `pkg-config --libs opencv` -o eyeTracking
当然它不起作用,我真的不明白我在做什么:P
有人可以向我解释一下怎么样?
/** * eye-tracking.cpp: * Eye detection and tracking with OpenCV * * This program tries to detect and tracking the user's eye with webcam. * At startup,the program performs face detection followed by eye detection * using OpenCV's built-in Haar cascade classifier. If the user's eye detected * successfully,an eye template is extracted. This template will be used in * the subsequent template matching for tracking the eye. */ #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/objdetect/objdetect.hpp> cv::CascadeClassifier face_cascade; cv::CascadeClassifier eye_cascade; /** * Function to detect human face and the eyes from an image. * * @param im The source image * @param tpl Will be filled with the eye template,if Detection success. * @param rect Will be filled with the bounding Box of the eye * @return zero=Failed,nonzero=success */ int detectEye(cv::Mat& im,cv::Mat& tpl,cv::rect& rect) { std::vector<cv::rect> faces,eyes; face_cascade.detectMultiScale(im,faces,1.1,2,0|CV_HAAR_SCALE_IMAGE,cv::Size(30,30)); for (int i = 0; i < faces.size(); i++) { cv::Mat face = im(faces[i]); eye_cascade.detectMultiScale(face,eyes,cv::Size(20,20)); if (eyes.size()) { rect = eyes[0] + cv::Point(faces[i].x,faces[i].y); tpl = im(rect); } } return eyes.size(); } /** * Perform template matching to search the user's eye in the given image. * * @param im The source image * @param tpl The eye template * @param rect The eye bounding Box,will be updated with the new LOCATIOn of the eye */ void trackEye(cv::Mat& im,cv::rect& rect) { cv::Size size(rect.width * 2,rect.height * 2); cv::rect window(rect + size - cv::Point(size.width/2,size.height/2)); window &= cv::rect(0,im.cols,im.rows); cv::Mat dst(window.width - tpl.rows + 1,window.height - tpl.cols + 1,CV_32FC1); cv::matchTemplate(im(window),tpl,dst,CV_TM_SQDIFF_NORMED); double minval,maxval; cv::Point minloc,maxloc; cv::minMaxLoc(dst,&minval,&maxval,&minloc,&maxloc); if (minval <= 0.2) { rect.x = window.x + minloc.x; rect.y = window.y + minloc.y; } else rect.x = rect.y = rect.width = rect.height = 0; } int main(int argc,char** argv) { // Load the cascade classifiers // Make sure you point the XML files to the right path,or // just copy the files from [OPENCV_DIR]/data/haarcascades directory face_cascade.load("haarcascade_frontalface_alt2.xml"); eye_cascade.load("haarcascade_eye.xml"); // Open webcam cv::VideoCapture cap(0); // check if everything is ok if (face_cascade.empty() || eye_cascade.empty() || !cap.isOpened()) return 1; // Set video to 320x240 cap.set(CV_CAP_PROP_FRAME_WIDTH,320); cap.set(CV_CAP_PROP_FRAME_HEIGHT,240); cv::Mat frame,eye_tpl; cv::rect eye_bb; while (cv::waitKey(15) != 'q') { cap >> frame; if (frame.empty()) break; // Flip the frame horizontally,Windows users might need this cv::flip(frame,frame,1); // Convert to grayscale and // adjust the image contrast using histogram equalization cv::Mat gray; cv::cvtColor(frame,gray,Cv_bGR2GRAY); if (eye_bb.width == 0 && eye_bb.height == 0) { // Detection stage // Try to detect the face and the eye of the user detectEye(gray,eye_tpl,eye_bb); } else { // Tracking stage with template matching trackEye(gray,eye_bb); // Draw bounding rectangle for the eye cv::rectangle(frame,eye_bb,CV_RGB(0,255,0)); } // Display video cv::imshow("video",framE); } return 0; }
以上是大佬教程为你收集整理的c – 将opencv库与g链接起来全部内容,希望文章能够帮你解决c – 将opencv库与g链接起来所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。