Advertisement
Guest User

analysis

a guest
Nov 29th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. /* analysis.h start ***************************************/
  2. #ifndef ANALYSIS_H
  3. #define ANALYSIS_H
  4.  
  5. void analysisWrapper(std::string filePath);
  6.  
  7. #endif  /* ANALYSIS_H */
  8. /* analysis.h end *****************************************/
  9.  
  10. /* analysis.cpp start *************************************/
  11. #include <iostream>
  12. #include "opencv2/highgui/highgui.hpp"
  13. #include "opencv2/core/core.hpp"
  14. #include "opencv2/imgproc/imgproc.hpp"
  15. #include "opencv2/imgproc/types_c.h"
  16. #include "boost/filesystem.hpp"
  17.  
  18. void doAnalysis(boost::filesystem::path imgPath, int threshold) {
  19.     cv::Mat im_grey, im_bin, im_bin_smooth; // Greyscale, binary and smoothed images
  20.     // Read in image as greyscale
  21.     std::cout << "Reading in image...";
  22.     im_grey = cv::imread(imgPath.string(), CV_LOAD_IMAGE_GRAYSCALE);
  23.     std::cout << "Success" << std::endl;
  24.     // Threshold image to binary
  25.     std::cout << "Thresholding image...";
  26.     im_bin = im_grey > threshold;
  27.     std::cout << "Success" << std::endl;
  28.     // Smooth binary image
  29.     std::cout << "Smoothing image...";
  30.     for (int i = 1; i < 31; i = i + 2) {
  31.         cv::GaussianBlur(im_bin, im_bin_smooth, cv::Size(i, i), 0, 0);
  32.     }
  33.     std::cout << "Success" << std::endl;
  34. }
  35.  
  36. void analysisWrapper(std::string filePath) {
  37.  
  38.     // Variables
  39.     boost::filesystem::path imgDir(filePath); // Path to directory holding images
  40.     int threshold = 75; // Threshold level
  41.     //Iterate over all files in directory imgDir
  42.     for (boost::filesystem::directory_iterator i(imgDir);
  43.             i != boost::filesystem::directory_iterator(); ++i) {
  44.         // If file is .jpg or .jpeg then run analysis
  45.         if (i->path().extension() == ".jpg" || i->path().extension() == ".jpeg") {
  46.             doAnalysis(i->path(), threshold);
  47.         }
  48.     }
  49. }
  50.  
  51. /* analysis.cpp end *************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement