Things.
This commit is contained in:
parent
879cbc4a32
commit
d2c2286173
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,7 +1,10 @@
|
||||
*.o
|
||||
obj/
|
||||
runs/
|
||||
*.out
|
||||
.cache/
|
||||
dataset/
|
||||
testdir/
|
||||
datasets/
|
||||
testimgs/
|
||||
yolov8*.pt
|
||||
compile_commands.json
|
||||
|
6
README.md
Normal file
6
README.md
Normal file
@ -0,0 +1,6 @@
|
||||
# imgboxer
|
||||
|
||||
Creates YOLOv8 image labels, based on paired data under normal and fluorescent
|
||||
conditions.
|
||||
|
||||
Depends on OpenCV.
|
5
data.yaml
Normal file
5
data.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
train: images/train
|
||||
val: images/val
|
||||
|
||||
nc: 1
|
||||
names: ['tooth']
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
#include "util.hpp"
|
||||
#include "img.hpp"
|
||||
#include "preprocess.hpp"
|
||||
#include "bound.hpp"
|
||||
|
9
src/include/util.hpp
Normal file
9
src/include/util.hpp
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
#include <string>
|
||||
|
||||
// Re-extension a file name.
|
||||
std::string reext(const std::string& fname);
|
||||
|
||||
#endif
|
@ -3,8 +3,8 @@
|
||||
|
||||
// Create the YOLOv8 image labels.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
@ -22,7 +22,7 @@ typedef struct Label {
|
||||
label_t* yolo_mklabel(cv::Rect box);
|
||||
|
||||
// Write labels to file from cv::Rect.
|
||||
void yolo_write_labels(char* fname, std::vector<cv::Rect> boxes);
|
||||
void yolo_write_labels(std::string fname, std::vector<cv::Rect> boxes);
|
||||
|
||||
|
||||
#endif
|
||||
|
13
src/main.cpp
13
src/main.cpp
@ -6,7 +6,7 @@ using namespace cv;
|
||||
int main(int argc, char** argv) {
|
||||
// Check for invalid invocation.
|
||||
if (argc != 2) {
|
||||
printf("%s IMAGE", argv[0]);
|
||||
printf("%s IMAGE\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -27,14 +27,15 @@ int main(int argc, char** argv) {
|
||||
|
||||
for (size_t i = 0; i < contours.size(); i++) {
|
||||
rectangle(img, boxes[i], Scalar(255, 255, 255), 1);
|
||||
drawContours(img, contours, (int)i, Scalar(255, 255, 255), 1, LINE_8);
|
||||
}
|
||||
drawContours(img, contours, (int)i, Scalar(255, 255, 255), 1, LINE_8); }
|
||||
|
||||
yolo_write_labels("asdf", boxes);
|
||||
std::string label_fname = reext(argv[1]);
|
||||
|
||||
yolo_write_labels(label_fname, boxes);
|
||||
|
||||
// Show image with bounding boxes.
|
||||
imshow("Bounding Boxes", img);
|
||||
waitKey(0);
|
||||
// imshow("Bounding Boxes", img);
|
||||
// waitKey(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
8
src/util.cpp
Normal file
8
src/util.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include "include/util.hpp"
|
||||
|
||||
std::string reext(const std::string& fname) {
|
||||
size_t dot_pos = fname.rfind('.');
|
||||
if (dot_pos == std::string::npos) return fname + ".txt";
|
||||
|
||||
return fname.substr(0, dot_pos) + ".txt";
|
||||
}
|
15
src/yolo.cpp
15
src/yolo.cpp
@ -13,9 +13,20 @@ label_t* yolo_mklabel(cv::Rect box) {
|
||||
return label;
|
||||
}
|
||||
|
||||
void yolo_write_labels(char* fname, std::vector<cv::Rect> boxes) {
|
||||
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];
|
||||
printf("%s 1 %d %d %d %d\n", LABEL_NAME, box.x, box.y, box.x + box.width, box.y + box.height);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user