Go to the documentation of this file.00001
00002 #include <ros/ros.h>
00003
00004 #include <geometry_msgs/PointStamped.h>
00005 #include <opencv/cv.h>
00006 #include <opencv2/imgproc/imgproc.hpp>
00007 #include <opencv2/highgui/highgui.hpp>
00008 #include <sensor_msgs/image_encodings.h>
00009
00010 #include <hrl_head_registration/head_registration.h>
00011
00012 #define USE_COLOR_MODEL
00013
00014 char *orig_filename, *face_filename;
00015
00016 ros::Subscriber pc_sub;
00017 PCRGB::Ptr cur_pc;
00018
00019 void subPCCallback(const PCRGB::Ptr& pc_msg);
00020 static void mouseClickCallback(int event, int x, int y, int flags, void* data);
00021
00022 void subPCCallback(const PCRGB::Ptr& pc_msg)
00023 {
00024 cv::Mat image(480, 640, CV_8UC3);
00025
00026 uint8_t r, g, b;
00027 for(uint32_t i=0;i<pc_msg->size();i++) {
00028 if(PT_IS_NOT_NAN(pc_msg, i)) {
00029 extractRGB(pc_msg->points[i].rgb, r, g, b);
00030 image.at<cv::Vec3b>(i/640, i%640)[2] = r;
00031 image.at<cv::Vec3b>(i/640, i%640)[1] = g;
00032 image.at<cv::Vec3b>(i/640, i%640)[0] = b;
00033 }
00034 }
00035 cv::imshow("Capture PC", image);
00036 cv::waitKey(3);
00037 cur_pc = pc_msg;
00038 }
00039
00040 void mouseClickCallback(int event, int x, int y, int flags, void* param)
00041 {
00042 if(event == CV_EVENT_LBUTTONDOWN) {
00043
00044
00045
00046
00047
00048
00049 savePCBag(orig_filename, cur_pc);
00050
00051 PCRGB::Ptr skin_pc(new PCRGB());
00052
00053 #ifdef USE_COLOR_MODEL
00054 extractFaceColorModel(cur_pc, skin_pc, x, y);
00055 #else
00056 extractFace(cur_pc, skin_pc, x, y);
00057 #endif
00058 skin_pc->header.frame_id = "/openni_rgb_optical_frame";
00059 savePCBag(face_filename, skin_pc);
00060
00061 ros::shutdown();
00062 }
00063 }
00064
00065 int main(int argc, char **argv)
00066 {
00067 ros::init(argc, argv, "clickable_display");
00068
00069
00070 orig_filename = argv[1];
00071 face_filename = argv[2];
00072
00073 ros::NodeHandle nh;
00074 cv::namedWindow("Capture PC", 1);
00075 cv::setMouseCallback("Capture PC", &mouseClickCallback);
00076 pc_sub = nh.subscribe("/kinect_head/rgb/points", 1, &subPCCallback);
00077
00078 ros::spin();
00079 }