-
Notifications
You must be signed in to change notification settings - Fork 1
/
cow.cpp
60 lines (49 loc) · 1.92 KB
/
cow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include </Users/geohacker/projects/opencv_contrib/modules/dpm/include/opencv2/dpm.hpp>
#include </Users/geohacker/projects/opencv/include/opencv2/opencv.hpp>
#include "/usr/local/include/boost/filesystem.hpp"
#include "/usr/local/include/boost/filesystem/operations.hpp"
#include "/usr/local/include/boost/filesystem/path.hpp"
#include <iostream>
#include <string>
namespace fs = boost::filesystem;
using namespace cv;
using namespace cv::dpm;
using namespace std;
int main( int argc, char** argv )
{
vector<string> models;
vector<string> names;
names.push_back("cow");
models.push_back("cascade.xml");
cv::Ptr<DPMDetector> detector = DPMDetector::create(models,names);
double t = (double) getTickCount();
fs::path full_path( fs::initial_path<fs::path>() );
full_path = fs::system_complete( fs::path( argv[1] ) );
// read the directory
fs::directory_iterator end_iter;
for ( fs::directory_iterator dir_itr( full_path );
dir_itr != end_iter;
++dir_itr )
{
std::cout << dir_itr->path().filename() << "\n";
// use the image and run through the model
Mat frame = imread(dir_itr->path().string());
resize(frame,frame,Size(),2,2);
namedWindow("DPM Cascade Detection", 1);
vector<DPMDetector::ObjectDetection> ds;
detector->detect(frame, ds);
t = ((double) getTickCount() - t)/getTickFrequency();
cerr << "dpm took " << t << " seconds" << endl;
// look at the score and only write the image if confident.
for (unsigned int i = 0; i < ds.size(); i++)
{
int id = ds[i].classID;
cerr << names[id] << "\t" << ds[i].score << "\t" << ds[i].rect << endl;
if (ds[i].score > -0.90) {
rectangle(frame, ds[i].rect, Scalar(255, 255, 255), 1);
imwrite(dir_itr->path().filename().string(), frame);
}
}
}
return 0;
}