Last active
November 11, 2016 01:50
-
-
Save denkiwakame/39c514997524247f6d46 to your computer and use it in GitHub Desktop.
よく忘れる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// basic | |
float min = *std::min_element(v.begin(),v.end(),[](Type msg1, Type msg2) {return msg1.second > msg2.second }; | |
float sum = std::accumulate(v.begin(), v.end(),0,[](const int sum, const Type& msg){ return sum + msg.second; }) | |
// index sort | |
template<typename T> | |
std::vector<size_t> sort_index(std::vector<T> const& values) { | |
std::vector<size_t> indices(values.size()); | |
std::iota(indices.begin(), indices.end(), static_cast<size_t>(0)); // init index | |
std::sort(indices.begin(), indices.end(), [&](size_t a, size_t b) { return values[a] < values[b]; }); // 昇順? | |
return indices; | |
} | |
// self-defined operator | |
struct myclass { | |
bool operator() (cv::Point pt1, cv::Point pt2) { return (pt1.y < pt2.y);} | |
} myobject; | |
// object-operator | |
struct msg { | |
float res; | |
float x; | |
float y; | |
cv::Vec<float, _LABEL_MAX_NUM_> values; | |
msg() : res(0.0) {}; | |
msg(float res_) : res(res_) {}; | |
msg(int x_, int y_) : res(0.0), x(x_), y(y_) {}; | |
bool operator<(const msg& m) const { return res > m.res; }; | |
}; | |
int main () { | |
// input data | |
std::vector<cv::Point> pts(5); | |
pts[0] = Point(10,40); | |
pts[1] = Point(9,27); | |
pts[2] = Point(5,68); | |
pts[3] = Point(7,55); | |
pts[4] = Point(8,15); | |
// sort vector using myobject as comparator | |
std::sort(pts.begin(), pts.end(), myobject); | |
// sorted by res | |
std::priority_queue<msg> pq; | |
pq.push(msg(3)); | |
pq.push(msg(2)); | |
pq.push(msg(100)); | |
pq.push(msg(10)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment