feat.初步完成基建技能目标识别

This commit is contained in:
MistEO
2021-10-17 01:42:09 +08:00
parent 0adccf2af7
commit 6afe081468
48 changed files with 303 additions and 20 deletions

View File

@@ -0,0 +1,35 @@
/******
* 转换透明图片若Alpha通道不为255则直接设置为黑色
******/
#include <filesystem>
#include <opencv2/opencv.hpp>
int main()
{
std::string input_dir = R"(D:\Code\MeoAssistance\resource\infrast)";
std::string output_dir = R"(D:\Code\MeoAssistance\resource\infrast\cvt\)";
for (auto&& entry : std::filesystem::directory_iterator(input_dir)) {
if (entry.path().extension() != ".png") {
continue;
}
cv::Mat image = cv::imread(entry.path().u8string(), -1);
cv::Mat cvt;
cv::cvtColor(image, cvt, cv::COLOR_BGRA2BGR);
for (int c = 0; c != image.cols; ++c) {
for (int r = 0; r != image.rows; ++r) {
auto p = image.at<cv::Vec4b>(c, r);
if (p[3] != 255) {
cvt.at<cv::Vec3b>(c, r) = cv::Vec3b(0, 0, 0);
}
}
}
std::string out_file = output_dir + entry.path().filename().u8string();
cv::imwrite(out_file, cvt);
}
return 0;
}