test_face_detect.cpp
Go to the documentation of this file.
00001 #include <opencv/cv.h>
00002 #include <opencv2/highgui/highgui.hpp>
00003 #include <boost/math/distributions/binomial.hpp>
00004 
00005 #include <hrl_head_registration/skin_color_util.h>
00006 
00007 using namespace std;
00008 using namespace boost::math;
00009 
00010 int main(int argc, char **argv)
00011 {
00012     cv::Mat img_in = cv::imread("in.jpg", 1);
00013     cv::Mat img_label(img_in.size(), CV_32F);
00014     cv::Mat img_label2(img_in.size(), CV_32F, cv::Scalar(0));
00015     cv::Mat img_label3(img_in.size(), CV_32F, cv::Scalar(0));
00016     double max_skin_prob = 0, skin_like, skin_prob, nskin_prob;
00017     vector<double> skin_likes;
00018     for(int i=0;i<img_in.rows;i++) {
00019         for(int j=0;j<img_in.cols;j++) {
00020             skin_prob = gaussian_mix_skin(img_in.at<cv::Vec3b>(i,j)[2], 
00021                                           img_in.at<cv::Vec3b>(i,j)[1], 
00022                                           img_in.at<cv::Vec3b>(i,j)[0]);
00023             nskin_prob = gaussian_mix_nskin(img_in.at<cv::Vec3b>(i,j)[2], 
00024                                             img_in.at<cv::Vec3b>(i,j)[1], 
00025                                             img_in.at<cv::Vec3b>(i,j)[0]);
00026             skin_like = skin_prob / nskin_prob;
00027             if(skin_like > max_skin_prob)
00028                 max_skin_prob = skin_like;
00029             img_label.at<float>(i,j) = skin_like;
00030             if(skin_like > atof(argv[1]))
00031                 img_label2.at<float>(i,j) = 255;
00032             skin_likes.push_back(skin_like);
00033         }
00034     }
00035     sort(skin_likes.begin(), skin_likes.end());
00036     double skin_like_thresh = skin_likes[(int) (atof(argv[2]) * skin_likes.size())];
00037     for(int i=0;i<img_in.rows;i++) 
00038         for(int j=0;j<img_in.cols;j++) 
00039             if(img_label.at<float>(i,j) > skin_like_thresh)
00040                 img_label3.at<float>(i,j) = 255;
00041 
00042     img_label /= max_skin_prob / 255;
00043     cv::imwrite("out.jpg", img_label);
00044     cv::imwrite("out2.jpg", img_label2);
00045     cv::imwrite("out3.jpg", img_label3);
00046 }


hrl_head_registration
Author(s): Kelsey Hawkins
autogenerated on Wed Nov 27 2013 11:45:27