啟動命令:roslaunch face_tracker_pkg start_tracking.launch
核心檢測**:
/*
* this code will track the faces using ros
*///ros headers
#include #include #include #include //open-cv headers
#include #include #include "opencv2/objdetect.hpp"
//centroid message headers
#include //opencv window name
static const std::string opencv_window = "raw_image_window";
static const std::string opencv_window_1 = "face_detector";
using namespace std;
using namespace cv;
class face_detector
catch(int e)
// subscribe to input video feed and publish output video feed
image_sub_ = it_.subscribe(input_image_topic, 1,
&face_detector::imagecb, this);
image_pub_ = it_.advertise(output_image_topic, 1);
face_centroid_pub = nh_.advertise("/face_centroid",10);
} ~face_detector()
void imagecb(const sensor_msgs::imageconstptr& msg)
catch (cv_bridge::exception& e)
string cascadename = haar_file_face;
cascadeclassifier cascade;
if( !cascade.load( cascadename ) )
if (display_original_image == 1)
detectanddraw( cv_ptr->image, cascade );
image_pub_.publish(cv_ptr->toimagemsg());
waitkey(30); }
void detectanddraw( mat& img, cascadeclassifier& cascade)
; mat gray, smallimg;
cvtcolor( img, gray, color_bgr2gray );
double fx = 1 / scale ;
//縮小或者放大函式至某乙個大小
resize( gray, smallimg, size(), fx, fx, inter_linear );
//直方圖均衡化,,用於提高影象的質量
equalizehist( smallimg, smallimg );
//統計**執行時間
t = (double)cvgettickcount();
//人臉檢測
cascade.detectmultiscale( smallimg, faces,
1.1, 15, 0
|cascade_scale_image,
size(30, 30) );
t = (double)cvgettickcount() - t;
for ( size_t i = 0; i < faces.size(); i++ )
else
rectangle( img, cvpoint(cvround(r.x*scale), cvround(r.y*scale)),
cvpoint(cvround((r.x + r.width-1)*scale), cvround((r.y + r.height-1)*scale)),
color, 3, 8, 0);
}//adding lines and left | right sections 新增行和左| 正確的部分
point pt1, pt2,pt3,pt4,pt5,pt6;
//center line
pt1.x = screenmaxx / 2;
pt1.y = 0;
pt2.x = screenmaxx / 2;
pt2.y = 480;
//left center threshold
pt3.x = (screenmaxx / 2) - center_offset;
pt3.y = 0;
pt4.x = (screenmaxx / 2) - center_offset;
pt4.y = 480;
//right center threshold
pt5.x = (screenmaxx / 2) + center_offset;
pt5.y = 0;
pt6.x = (screenmaxx / 2) + center_offset;
pt6.y = 480;
line(img, pt1, pt2, scalar(0, 0, 255),0.2);
line(img, pt3, pt4, scalar(0, 255, 0),0.2);
line(img, pt5, pt6, scalar(0, 255, 0),0.2);
puttext(img, "left", cvpoint(50,240), font_hershey_******x, 1, cvscalar(255,0,0), 2, cv_aa);
puttext(img, "center", cvpoint(280,240), font_hershey_******x, 1, cvscalar(0,0,255), 2, cv_aa);
puttext(img, "right", cvpoint(480,240), font_hershey_******x, 1, cvscalar(255,0,0), 2, cv_aa);
if (display_tracking_image == 1)}
};int main(int argc, char** ar**)
人臉識別 通過opencv進行人臉識別
opencv人臉識別主要有3種演算法 具體步驟 一 人臉的訓練,需要將訓練中人臉扣出 正臉 轉化灰度圖 直方圖均衡化 訓練 二 經過同樣步驟處理,然後 每個檔案裡有幾張訓練 使用官方提供的模型構建特徵提取器 predictor dlib.shape predictor predictor path ...
基於ROS使用OpenCV進行人臉識別
攝像頭 1個 usb資料線 1個 這裡需要使用usb cam軟體包 cd catkin ws src git clone cd catkin ws catkin make 注意 下面的程式執行前,需要啟動usb cam節點。roslaunch usb cam usb cam test.launch ...
使用opencv進行人臉識別
最近由於大作業需要,使用了opencv進行人臉識別。一般來說,識別分為兩部,即人臉檢測 人臉識別,opencv提供了乙個人臉檢測的sample,有乙個比較成熟的訓練人臉正面訓練檔案,這是我所知的乙個很成熟的人臉識別工具,而且已用於一些前沿3d愛情動作遊戲中,這裡主要是對其提供的sample作了一定的...