-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
84 lines (73 loc) · 2.36 KB
/
test.cpp
File metadata and controls
84 lines (73 loc) · 2.36 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "line2Dup.h"
#include <memory>
#include <iostream>
#include <assert.h>
#include <chrono>
#include <opencv2/dnn.hpp>
using namespace std;
using namespace cv;
class Timer
{
public:
Timer() : beg_(clock_::now()) {}
void reset() { beg_ = clock_::now(); }
double elapsed() const {
return std::chrono::duration_cast<second_>
(clock_::now() - beg_).count(); }
void out(std::string message = ""){
double t = elapsed();
std::cout << message << " elasped time:" << t << "s" << std::endl;
reset();
}
private:
typedef std::chrono::high_resolution_clock clock_;
typedef std::chrono::duration<double, std::ratio<1> > second_;
std::chrono::time_point<clock_> beg_;
};
static std::string prefix = "/home/bruce/Desktop/sjtu/ShapeBased/test/";
void circle_gen(){
Mat bg = Mat(800, 800, CV_8UC3, {0, 0, 0});
cv::circle(bg, {400, 400}, 200, {255,255,255}, -1);
cv::imshow("test", bg);
waitKey(0);
}
void scale_test(){
int num_feature = 150;
line2Dup::Detector detector(num_feature, {4, 8});
std::vector<std::string> ids;
ids.push_back("circle");
detector.readClasses(ids, prefix+"case0/%s_templ.yaml");
Mat test_img = imread("/home/bruce/Pictures/149/5.png");
pyrDown(test_img, test_img);
int stride = 32;
int n = test_img.rows/stride;
int m = test_img.cols/stride;
Rect roi(0, 0, stride*m , stride*n);
Mat img = test_img(roi).clone();
assert(img.isContinuous());
Timer timer;
auto matches = detector.match(img, 75, ids);
timer.out();
std::cout << "matches.size(): " << matches.size() << std::endl;
size_t top5 = 5;
if(top5>matches.size()) top5=matches.size();
for(size_t i=0; i<top5; i++){
auto match = matches[i];
auto templ = detector.getTemplates("circle",
match.template_id);
int x = templ[0].width/2 + match.x;
int y = templ[0].height/2 + match.y;
int r = templ[0].width/2;
Scalar color(255, rand()%255, rand()%255);
cv::putText(img, to_string(int(round(match.similarity))),
Point(match.x+r-10, match.y-3), FONT_HERSHEY_PLAIN, 2, color);
cv::circle(img, {x, y}, r, color, 2);
}
imshow("img", img);
waitKey(0);
std::cout << "test end" << std::endl;
}
int main(){
scale_test();
return 0;
}