-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.h
35 lines (33 loc) · 890 Bytes
/
file.h
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
#pragma once
#include <fstream>
// 读取图像到dst,并返回图像名称(不带拓展名)
std::string imgRead(std::string imgPath, cv::Mat& dst) {
std::string pureName = imgPath.substr(0, imgPath.rfind("."));
clock_t start = clock();
dst = cv::imread(imgPath);
std::cout << "imread:" << clock() - start << "ms\n";
if (!dst.data) {
printf("读取图像失败\n");
exit(-1);
}
else return pureName;
}
// 计算基准点(每条直线的纵坐标均值),并将基准线和基准点输出到.csv文件
void lineWrite(const std::vector<std::vector<cv::Point>> vLine, const std::string imgName) {
std::ofstream fout(imgName + ".csv");
if (!fout) {
std::cout << imgName << ".csv无法打开";
return;
}
std::string s;
for (auto it : vLine) {
double avgY = 0;
for (auto jt : it)
avgY += jt.y;
avgY /= it.size();
for (auto jt : it)
s += cv::format("%d,%d,%lf\n", jt.x, jt.y, avgY);
}
fout << s;
fout.close();
}