/// <summary> /// detect facial features using the given image and face coordinates /// </summary> /// <param name="img">image object containing the face</param> /// <param name="face_tx">The top left x coordinate of the detected face within the image object</param> /// <param name="face_ty">The top left y coordinate of the detected face within the image object</param> /// <param name="face_bx">The bottom right x coordinate of the detected face within the image object</param> /// <param name="face_by">The bottom right y coordinate of the detected face within the image object</param> void classHumunculus::analyseFace(classimage *img, int face_tx, int face_ty, int face_bx, int face_by) { int x,y,c,xx,yy,w,h; int lateral_symetry,lefteye_x,righteye_x,lefteye_y,righteye_y,mouth_y,mouth_width; //dimensions of the face within the original image w = face_bx - face_tx; h = face_by - face_ty; //dump the face region into a separate image of fixed dimensions for (x=0;x<FACE_IMAGE_SIZE;x++) { xx = face_tx + ((x * w)/ FACE_IMAGE_SIZE); for (y=0;y<FACE_IMAGE_SIZE;y++) { yy = face_ty + ((y * h) / FACE_IMAGE_SIZE); for (c=0;c<3;c++) face->image[x][y][c] = img->image[xx][yy][c]; } } //face->updateIntegralImage(); //detect the positions of features within the face image detectFeatures(lateral_symetry, lefteye_x, righteye_x, lefteye_y, righteye_y, mouth_y, mouth_width); detectKeypoints(lateral_symetry, lefteye_x, righteye_x, lefteye_y, righteye_y, mouth_y, mouth_width); }
bool SURF_OCL::detect(InputArray _img, InputArray _mask, UMat& keypoints) { if( !setImage(_img, _mask) ) return false; return detectKeypoints(keypoints); }
void KinectFushionApp::compute_features(PointCloudRgbPtr cloud, PointCloudRgbPtr keypoints, LocalDescriptorsPtr local_descriptors) { // Estimate surface normals float surface_radius = 0.03; SurfaceNormalsPtr normals = estimateSurfaceNormals (cloud, surface_radius); // Detect keypoints float min_scale = 0.005f; int nr_octaves = 5; int nr_scales = 8; float min_contrast = 0.1f; keypoints = detectKeypoints (cloud, normals, min_scale, nr_octaves, nr_scales, min_contrast); PCL_INFO("Detected %zu keypoints\n", keypoints->size ()); // Compute local descriptors double feature_radius = 0.06; assert (normals && keypoints); local_descriptors = computeLocalDescriptors (cloud, normals, keypoints, feature_radius); PCL_INFO("Computed local descriptors\n"); // Compute global descriptor // GlobalDescriptorsPtr global_descriptor; // global_descriptor = computeGlobalDescriptor (cloud, normals); // PCL_INFO ("Computed global descriptor\n"); }
ICCVTutorial<FeatureType>::ICCVTutorial(boost::shared_ptr<pcl::Keypoint<pcl::PointXYZRGB, pcl::PointXYZI> >keypoint_detector, typename pcl::Feature<pcl::PointXYZRGB, FeatureType>::Ptr feature_extractor, boost::shared_ptr<pcl::PCLSurfaceBase<pcl::PointXYZRGBNormal> > surface_reconstructor, typename pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr source, typename pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr target) : source_keypoints_ (new pcl::PointCloud<pcl::PointXYZI> ()) , target_keypoints_ (new pcl::PointCloud<pcl::PointXYZI> ()) , keypoint_detector_ (keypoint_detector) , feature_extractor_ (feature_extractor) , surface_reconstructor_ (surface_reconstructor) , source_ (source) , target_ (target) , source_segmented_ (new pcl::PointCloud<pcl::PointXYZRGB>) , target_segmented_ (new pcl::PointCloud<pcl::PointXYZRGB>) , source_transformed_ (new pcl::PointCloud<pcl::PointXYZRGB>) , source_registered_ (new pcl::PointCloud<pcl::PointXYZRGB>) , source_features_ (new pcl::PointCloud<FeatureType>) , target_features_ (new pcl::PointCloud<FeatureType>) , correspondences_ (new pcl::Correspondences) , show_source2target_ (false) , show_target2source_ (false) , show_correspondences (false) { // visualizer_.registerKeyboardCallback(&ICCVTutorial::keyboard_callback, *this, 0); segmentation (source_, source_segmented_); segmentation (target_, target_segmented_); detectKeypoints (source_segmented_, source_keypoints_); detectKeypoints (target_segmented_, target_keypoints_); extractDescriptors (source_segmented_, source_keypoints_, source_features_); extractDescriptors (target_segmented_, target_keypoints_, target_features_); findCorrespondences (source_features_, target_features_, source2target_); findCorrespondences (target_features_, source_features_, target2source_); filterCorrespondences (); determineInitialTransformation (); determineFinalTransformation (); // reconstructSurface (); }
bool SURF_OCL::detectAndCompute(InputArray _img, InputArray _mask, UMat& keypoints, OutputArray _descriptors, bool useProvidedKeypoints ) { if( !setImage(_img, _mask) ) return false; if( !useProvidedKeypoints && !detectKeypoints(keypoints) ) return false; return computeDescriptors(keypoints, _descriptors); }
template <typename PointInT, typename PointOutT> inline void pcl::Keypoint<PointInT, PointOutT>::compute (PointCloudOut &output) { if (!initCompute ()) { PCL_ERROR ("[pcl::%s::compute] initCompute failed!\n", getClassName ().c_str ()); return; } // Perform the actual computation detectKeypoints (output); deinitCompute (); // Reset the surface if (input_ == surface_) surface_.reset (); }
void GpuSurfDetectorInternal::detectKeypoints() { detectKeypoints(m_config.threshold); }
bool SpatialAverageSpotter::train(string dirPath) { int count=0; vector<vector<tuple<int,Point2f> > > features; featureAverages.resize(codebook->size()); for (int i =0; i<codebook->size(); i++) featureAverages[i]=Mat(BASE_SIZE,BASE_SIZE,CV_32F,Scalar(0)); DIR *dir; struct dirent *ent; if ((dir = opendir (dirPath.c_str())) != NULL) { /* print all the files and directories within directory */ // Mat img; while ((ent = readdir (dir)) != NULL) { string fileName(ent->d_name); // cout << "examining " << fileName << endl; if (fileName[0] == '.' || fileName[fileName.size()-1]!='G') continue; Mat img = imread(dirPath+fileName, CV_LOAD_IMAGE_GRAYSCALE); // resize(img,img,Size(0,0),2,2); threshold(img,img,120.0,255,THRESH_BINARY); // windowWidth += img.cols; // windowHeight += img.rows; // int avg=0; // for (int x=0; x<img.cols; x++) // for (int y=0; y<img.rows; y++) // avg += (int)img.at<unsigned char>(y,x); //// cout << "avg="<<avg<<"/"<<img.cols*img.rows<<" = "<<avg/(img.cols*img.rows)<<endl; // avg /= img.cols*img.rows; resize(img,img,Size(PRE_BASE_SIZE,PRE_BASE_SIZE*((0.0+img.rows)/img.cols))); copyMakeBorder( img, img, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_CONSTANT, 255 ); assert(img.cols > 1 && img.rows > 1); adjustedTrainingImages.push_back(img.clone()); Point2f centerOfMass = findCenterOfMass(img); int offsetx=(img.cols/2)-centerOfMass.x; int offsety=(img.rows/2)-centerOfMass.y; translateImg(img,offsetx,offsety); vector<KeyPoint> keypoints; Mat desc; detectKeypoints( img,keypoints, desc); Mat out; cvtColor(img,out,CV_GRAY2RGB); circle(out,centerOfMass,1,Scalar(0,0,255)); features.resize(count+1); //double scaling = BASE_SIZE/img for (int r=0; r<desc.rows; r++) { int f = codebook->quantize(desc.row(r)); Point2f offsetPoint(keypoints[r].pt.x - centerOfMass.x, keypoints[r].pt.y - centerOfMass.y); features[count].push_back(make_tuple(f,offsetPoint));//we're ignoring the keypoint scale.. // circle(out,keypoints[r].pt,keypoints[r].size,Scalar(colorTable[f])); Rect rec(keypoints[r].pt.x-(keypoints[r].size/2),keypoints[r].pt.y-(keypoints[r].size/2),keypoints[r].size,keypoints[r].size); rectangle(out,rec,Scalar(colorTable[f])); } guassColorIn(features[count]); imshow("learning keypoints",out); cout << "image "<<count<<endl; waitKey(5); count++; // img.release(); } closedir (dir); } else { /* could not open directory */ perror (""); return false; } //We now step through adjusting the scales of the various images so the guass coloring is maximized //But we may still want to look at tfidf to see which ones should be weighted more, etc. maximizeAlignment(features); float max=0; float min =99999; float avg_max=0; int firstx=9999; int lastx=0; int firsty=9999; int lasty=0; for (int f=0; f<codebook->size(); f++) { float local_max=0; bool hitFirst=false; for (int x=0; x<featureAverages[f].cols; x++) for (int y=0; y<featureAverages[f].rows; y++) { float val = featureAverages[f].at<float>(y,x); if (val > 300 || val < -300) cout << "val (" << x <<","<<y<<") " << val << endl; if (val>max) max=val; if (val<min) min=val; if (val>local_max) local_max=val; if (val>WINDOW_THRESH) { if (!hitFirst) { hitFirst=true; if (x<firstx) firstx=x; if (y<firsty) firsty=y; } if (x>lastx) lastx=x; if (y>lasty) lasty=y; } } avg_max+=local_max; } // penalty=min+(max-min)*.2; avg_max /= codebook->size(); penalty=avg_max*.15;//.2 // windowWidth/=count; // windowHeight/=count; windowWidth = lastx-firstx; windowHeight = lasty-firsty; cout << "window size is "<<windowWidth<<"x"<<windowHeight<<endl; //show averages showAverages(); return true; }
int main (int argc, char ** argv) { if (argc < 2) { pcl::console::print_info ("Syntax is: %s input.pcd <options>\n", argv[0]); pcl::console::print_info (" where options are:\n"); pcl::console::print_info (" -n radius ...................................... Estimate surface normals\n"); pcl::console::print_info (" -k min_scale,nr_octaves,nr_scales,min_contrast... Detect keypoints\n"); pcl::console::print_info (" -l radius ....................................... Compute local descriptors\n"); pcl::console::print_info (" -s output_name (without .pcd extension).......... Save outputs\n"); pcl::console::print_info ("Note: \n"); pcl::console::print_info (" Each of the first four options depends on the options above it.\n"); pcl::console::print_info (" Saving (-s) will output individual files for each option used (-n,-k,-f,-g).\n"); return (1); } // Load the input file PointCloudPtr cloud (new PointCloud); pcl::io::loadPCDFile (argv[1], *cloud); pcl::console::print_info ("Loaded %s (%lu points)\n", argv[1], cloud->size ()); // Estimate surface normals SurfaceNormalsPtr normals; double surface_radius; bool estimate_surface_normals = pcl::console::parse_argument (argc, argv, "-n", surface_radius) > 0; if (estimate_surface_normals) { normals = estimateSurfaceNormals (cloud, surface_radius); pcl::console::print_info ("Estimated surface normals\n"); } // Detect keypoints PointCloudPtr keypoints; std::string params_string; bool detect_keypoints = pcl::console::parse_argument (argc, argv, "-k", params_string) > 0; if (detect_keypoints) { assert (normals); std::vector<std::string> tokens; boost::split (tokens, params_string, boost::is_any_of (","), boost::token_compress_on); assert (tokens.size () == 4); float min_scale = atof(tokens[0].c_str ()); int nr_octaves = atoi(tokens[1].c_str ()); int nr_scales = atoi(tokens[2].c_str ()); float min_contrast = atof(tokens[3].c_str ()); keypoints = detectKeypoints (cloud, normals, min_scale, nr_octaves, nr_scales, min_contrast); pcl::console::print_info ("Detected %lu keypoints\n", keypoints->size ()); } // Compute local descriptors LocalDescriptorsPtr local_descriptors; double feature_radius; bool compute_local_descriptors = pcl::console::parse_argument (argc, argv, "-l", feature_radius) > 0; if (compute_local_descriptors) { assert (normals && keypoints); local_descriptors = computeLocalDescriptors (cloud, normals, keypoints, feature_radius); pcl::console::print_info ("Computed local descriptors\n"); } // Compute global descriptor GlobalDescriptorsPtr global_descriptor; if (normals) { global_descriptor = computeGlobalDescriptor (cloud, normals); pcl::console::print_info ("Computed global descriptor\n"); } // Save output std::string base_filename, output_filename; bool save_cloud = pcl::console::parse_argument (argc, argv, "-s", base_filename) > 0; if (save_cloud) { if (normals) { output_filename = base_filename; output_filename.append ("_normals.pcd"); pcl::io::savePCDFile (output_filename, *normals); pcl::console::print_info ("Saved surface normals as %s\n", output_filename.c_str ()); } if (keypoints) { output_filename = base_filename; output_filename.append ("_keypoints.pcd"); pcl::io::savePCDFile (output_filename, *keypoints); pcl::console::print_info ("Saved keypoints as %s\n", output_filename.c_str ()); } if (local_descriptors) { output_filename = base_filename; output_filename.append ("_localdesc.pcd"); pcl::io::savePCDFile (output_filename, *local_descriptors); pcl::console::print_info ("Saved local descriptors as %s\n", output_filename.c_str ()); } if (global_descriptor) { output_filename = base_filename; output_filename.append ("_globaldesc.pcd"); pcl::io::savePCDFile (output_filename, *global_descriptor); pcl::console::print_info ("Saved global descriptor as %s\n", output_filename.c_str ()); } } // Or visualize the result else { pcl::console::print_info ("Starting visualizer... Close window to exit\n"); pcl::visualization::PCLVisualizer vis; pcl::visualization::PCLHistogramVisualizer hist_vis; vis.addPointCloud (cloud); if (normals) { vis.addPointCloudNormals<PointT,NormalT> (cloud, normals, 4, 0.02, "normals"); } if (keypoints) { pcl::visualization::PointCloudColorHandlerCustom<PointT> red (keypoints, 255, 0, 0); vis.addPointCloud (keypoints, red, "keypoints"); vis.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "keypoints"); } if (global_descriptor) { hist_vis.addFeatureHistogram (*global_descriptor, 308, "Global descriptor"); } vis.resetCamera (); vis.spin (); } return (0); }