mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-18 02:10:21 +08:00
feat.初步完成基建技能目标识别
This commit is contained in:
35
tools/TransparentImageCvt/main.cpp
Normal file
35
tools/TransparentImageCvt/main.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user