33 lines
943 B
C++
33 lines
943 B
C++
#include "include/yolo.hpp"
|
|
|
|
label_t* yolo_mklabel(cv::Rect box) {
|
|
// why is c++ like this
|
|
label_t* label = (label_t*)malloc(sizeof(label_t));
|
|
|
|
label->confidence = 1;
|
|
label->xmin = box.x;
|
|
label->ymin = box.y;
|
|
label->xmax = box.x + box.width;
|
|
label->ymax = box.y + box.height;
|
|
|
|
return label;
|
|
}
|
|
|
|
void yolo_write_labels(std::string fname, std::vector<cv::Rect> boxes) {
|
|
std::ofstream f;
|
|
f.open(fname);
|
|
if (!f) {
|
|
std::cerr << "Could not open file for writing" << std::endl;
|
|
exit(1);
|
|
}
|
|
|
|
for (size_t i = 0; i < boxes.size(); i++) {
|
|
auto box = boxes[i];
|
|
f << LABEL_NAME << " 1 " << box.x << " " << box.y << " "
|
|
<< box.x + box.width << " " << box.y + box.height << std::endl;
|
|
std::cout << LABEL_NAME << " 1 " << box.x << " " << box.y << " "
|
|
<< box.x + box.width << " " << box.y + box.height
|
|
<< std::endl;
|
|
}
|
|
}
|