Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* analysis.h start ***************************************/
- #ifndef ANALYSIS_H
- #define ANALYSIS_H
- void analysisWrapper(std::string filePath);
- #endif /* ANALYSIS_H */
- /* analysis.h end *****************************************/
- /* analysis.cpp start *************************************/
- #include <iostream>
- #include "opencv2/highgui/highgui.hpp"
- #include "opencv2/core/core.hpp"
- #include "opencv2/imgproc/imgproc.hpp"
- #include "opencv2/imgproc/types_c.h"
- #include "boost/filesystem.hpp"
- void doAnalysis(boost::filesystem::path imgPath, int threshold) {
- cv::Mat im_grey, im_bin, im_bin_smooth; // Greyscale, binary and smoothed images
- // Read in image as greyscale
- std::cout << "Reading in image...";
- im_grey = cv::imread(imgPath.string(), CV_LOAD_IMAGE_GRAYSCALE);
- std::cout << "Success" << std::endl;
- // Threshold image to binary
- std::cout << "Thresholding image...";
- im_bin = im_grey > threshold;
- std::cout << "Success" << std::endl;
- // Smooth binary image
- std::cout << "Smoothing image...";
- for (int i = 1; i < 31; i = i + 2) {
- cv::GaussianBlur(im_bin, im_bin_smooth, cv::Size(i, i), 0, 0);
- }
- std::cout << "Success" << std::endl;
- }
- void analysisWrapper(std::string filePath) {
- // Variables
- boost::filesystem::path imgDir(filePath); // Path to directory holding images
- int threshold = 75; // Threshold level
- //Iterate over all files in directory imgDir
- for (boost::filesystem::directory_iterator i(imgDir);
- i != boost::filesystem::directory_iterator(); ++i) {
- // If file is .jpg or .jpeg then run analysis
- if (i->path().extension() == ".jpg" || i->path().extension() == ".jpeg") {
- doAnalysis(i->path(), threshold);
- }
- }
- }
- /* analysis.cpp end *************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement