Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <stdexcept>
- #include <iomanip>
- #include <string>
- #include <opencv2/objdetect.hpp>
- #include <opencv2/highgui.hpp>
- #include <opencv2/imgproc.hpp>
- #include <opencv2/imgcodecs.hpp>
- #include <opencv2/video.hpp>
- #include <opencv2/videoio.hpp>
- using namespace cv;
- using namespace std;
- typedef vector<vector<float> > HogData;
- const char* keys =
- {
- "{ help h | | print help message }"
- "{ directory d | | images directory}"
- };
- static void computeHOG(HOGDescriptor &hog, Mat &img, HogData &hogdata, int value)
- {
- Mat gray;
- cvtColor(img, gray, COLOR_BGR2GRAY );
- resize(gray, gray, Size(80, 80));
- hog.winSize = Size(80,80);
- vector<Point> positions;
- vector<float> descriptor;
- hog.compute(gray,descriptor,cv::Size(8,8),cv::Size(0,0),positions);
- descriptor.insert(descriptor.begin(),value);
- hogdata.push_back(descriptor);
- }
- int main(int argc, char** argv)
- {
- CommandLineParser parser(argc, argv, keys);
- HogData hogdata;
- HOGDescriptor hog;
- string pattern_glob = "";
- if (parser.has("directory"))
- {
- pattern_glob = parser.get<string>("directory");
- }
- if (!pattern_glob.empty())
- {
- //Read from input image files
- vector<String> filenames;
- //Read from video file
- Mat frame;
- int value;
- if (!pattern_glob.empty())
- {
- String folder(pattern_glob);
- glob(folder, filenames);
- }
- vector<String>::const_iterator it_image = filenames.begin();
- for (; it_image != filenames.end(); ++it_image)
- {
- cout << "\nRead: " << *it_image << endl;
- value = ((string) *it_image).at(((((string) *it_image).find_first_of("/")) + 1)) - '0';
- cout << "Real value : " << value << endl;
- frame = imread(*it_image);
- if (!frame.empty())
- {
- computeHOG(hog, frame, hogdata, value);
- }
- }
- }
- ofstream myfile ("resultHOGElliot.data", ofstream::trunc);
- cout << hogdata.at(0).size() << endl;
- if (myfile.is_open())
- {
- for (vector<float> vf : hogdata) {
- for (float f : vf) {
- myfile << setprecision(2) << f << ",";
- }
- myfile <<'\b'; //Cursor moves 1 position backwards
- myfile << endl;
- }
- myfile.close();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement