-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
123 lines (105 loc) · 3.21 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <opencv2/opencv.hpp>
#include "MSERStates.h"
#include <GCoptimization.h>
#include "CVGeometryUtils.h"
#include <iostream>
#define TESTING 1
using namespace std;
using namespace cv;
//void testDataCost();
void mserExtractor(Mat& image, vector<cv::Rect>& msers_bbox);
int main(int argc, char** argv) {
//if (TESTING)
// testDataCost();
Mat img = imread("test_images/0000.jpg", IMREAD_GRAYSCALE);
vector<Rect> msers_bbox;
mserExtractor(img, msers_bbox);
int num_labels = 10 * 32;
int *numNeighbors;
int **neighborIndexes;
int **neighborWeights;
MSERStates image_states = MSERStates(img, msers_bbox);
image_states.generateDelaunayNeighbors(numNeighbors, neighborIndexes, neighborWeights);
for (int i = 0; i < msers_bbox.size(); i++) {
cout << "numNeighbors[" << i << "] = " << numNeighbors[i] << endl;
}
cout << msers_bbox.size() << endl;
try {
GCoptimizationGeneralGraph *gc = new GCoptimizationGeneralGraph(msers_bbox.size(), num_labels);
gc->setDataCost(MSERStates::static_dataCost, &image_states);
gc->setSmoothCost(MSERStates::static_smoothCost, &image_states);
gc->setAllNeighbors(numNeighbors, neighborIndexes, neighborWeights);
//gc->setLabelOrder(true);
//gc->expansion();
delete gc;
} catch (GCException e) {
e.Report();
}
//gc.setDataCost(MSERStates::static_dataCost, &image_states);
//gc.setSmoothCost(MSERStates::static_smoothCost, &image_states);
//gc.setLabelOrder(true);
//gc.expansion();
//for (int i = 0; i < msers_bbox.size(); i++) {
// image_states.updateState(i, gc.whatLabel(i));
//}
//Mat states_image = image_states.draw();
return 0;
}
//void inputState(int event, int x, int y, int flags, void* userdata) {
// if (event == EVENT_LBUTTONDOWN) {
// void** realData = (void**) userdata;
// int rand_siteID = *(int *) realData[0];
// MSERStates *ms = (MSERStates *) realData[1];
// int k_orientation, scale;
//
// cout << "Input orientation (0 - 31): ";
// cin >> k_orientation;
// cout << endl;
// cout << "Input Scale (0 - 9): ";
// cin >> scale;
// cout << endl;
//
// double result = ms->dataCost(rand_siteID, 10*k_orientation + scale);
//
// cout << "Energy (Remember the lower the better state estimate): " << result << endl;
// cout << endl;
// int key_code = waitKey(0);
// }
//}
//
//void testDataCost() {
// Mat image = imread("test_images/0063.jpg", IMREAD_GRAYSCALE);
// vector<Rect> msers_bbox;
//
// mserExtractor(image, msers_bbox);
//
// MSERStates ms = MSERStates(image, msers_bbox);
//
// srand(time(NULL));
// while(1) {
// Mat image_one_cc, proj_profile;
// image.copyTo(image_one_cc);
//
// /* Show the selected CC */
// int rand_siTeID = rand() % msers_bbox.size();
// Point center = getRectCenter(msers_bbox[rand_siteID]);
// circle(image_one_cc, center, 100, Scalar(0), 5);
//
// namedWindow("Image", 1);
// void *data[2] = { &rand_siteID, &ms };
// imshow("Image", image_one_cc);
// setMouseCallback("Image", inputState, data);
//
// //int key_code = waitKey(0);
// //if (key_code == 1048689)
// // break;
//
//
//
// }
//}
void mserExtractor(Mat& image, vector<cv::Rect>& msers_bbox) {
Ptr<MSER> mserExtractor = MSER::create();
vector<vector<Point> > mser_contours;
mserExtractor->detectRegions(image, mser_contours, msers_bbox);
}