Skip to content

Commit

Permalink
更新配置文件系统
Browse files Browse the repository at this point in the history
  • Loading branch information
sxjeru authored Oct 29, 2021
1 parent c7f3efc commit d4d5e4c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
31 changes: 28 additions & 3 deletions merge-1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,30 @@
#include <imgcodecs.hpp>
#include <core.hpp>
#include <highgui.hpp>
#include "config.h"
using namespace std;
using namespace cv;
using namespace Json;
void merge1() {
//获取屏幕分辨率 (用于自动调整预览窗口尺寸)
//int width{ GetSystemMetrics(SM_CXSCREEN) };
//int height{ GetSystemMetrics(SM_CYSCREEN) };
//cout << width << " " << height << endl;

//读取配置文件
int quality;
Value root;
ifstream json("config\\config.json", ios::binary);
Reader reader;
if (reader.parse(json, root))
{
quality = root["qualityJPGfile"].asInt();
}
else {
cout << "配置文件解析错误,请检查文件是否丢失,或存在语法错误!" << endl;
}

bool empty = false;
//获取csv文件数量 (外循环用)
int csvNum = 0, c;
int sum1 = 0, sum2 = 0; //统计处理图片数
Expand Down Expand Up @@ -70,11 +86,14 @@ void merge1() {
//合并差分CG (merge),并保存
vector <int> compression_params;
compression_params.push_back(IMWRITE_JPEG_QUALITY);
compression_params.push_back(95); //输出jpg质量
compression_params.push_back(quality); //输出jpg质量
if (para[j * 10 + 2] != "") {
Mat imgO = imread(imgOpath);
Mat imgD = imread(imgDpath);
if (!imgO.data || !imgD.data) goto jump; //判断图片是否存在
if (!imgO.data || !imgD.data) {
goto jump; //判断图片是否存在
empty = true;
}
int x = stoi(para[j * 10 + 3]), y = stoi(para[j * 10 + 4]), w = stoi(para[j * 10 + 5]), h = stoi(para[j * 10 + 6]); //string -> int
Mat roi(imgO(Rect(x, y, w, h)));
imgD.copyTo(roi);
Expand All @@ -87,7 +106,10 @@ void merge1() {
}
else {
Mat imgO = imread(imgOpath);
if (!imgO.data) goto jump;//判断图片是否存在
if (!imgO.data) {
goto jump; //判断图片是否存在
empty = true;
}
namedWindow("Viewer", WINDOW_NORMAL);
resizeWindow("Viewer", 1200, 675);
imwrite("result\\" + para[j * 10 + 1] + ".jpg", imgO, compression_params);
Expand All @@ -100,6 +122,9 @@ void merge1() {
}
fclose(filelist);
system("del filelist.txt");
if (empty) {
cout << "警告:有部分图片无法读取,请手动检查!" << endl;
}
cout << "\n本次成功合并 " << sum1 << " 张差分图,并保留了 " << sum2 << " 张原图。" << endl;
cout << "共计获得 " << sum1 + sum2 << " 张 CG,好耶~~\n" << endl;
waitKey(1000);
Expand Down
27 changes: 24 additions & 3 deletions merge-2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,29 @@
#include <core.hpp>
#include <highgui.hpp>
#include <imgproc.hpp>
#include "config.h"
using namespace std;
using namespace cv;
using namespace Json;
void merge2() {
//获取屏幕分辨率 (用于自动调整预览窗口尺寸)
//int width{ GetSystemMetrics(SM_CXSCREEN) };
//int height{ GetSystemMetrics(SM_CYSCREEN) };
//cout << width << " " << height << endl;

//读取配置文件
int quality;
Value root;
ifstream json("config\\config.json", ios::binary);
Reader reader;
if (reader.parse(json, root))
{
quality = root["qualityPNGfile"].asInt();
}
else {
cout << "配置文件解析错误,请检查文件是否丢失,或存在语法错误!" << endl;
}

bool empty = false;
//获取csv文件数量 (外循环用)
int csvNum = 0, c;
Expand Down Expand Up @@ -63,7 +79,7 @@ void merge2() {
//合并差分CG (merge),并保存
vector <int> compression_params;
compression_params.push_back(IMWRITE_PNG_COMPRESSION);
compression_params.push_back(3); //输出png压缩程度
compression_params.push_back(quality); //输出png压缩程度
if (para[j * 10 + 2] != "") {
Mat imgO = imread(imgOpath, IMREAD_UNCHANGED); //读取透明png
Mat imgD = imread(imgDpath, IMREAD_UNCHANGED);
Expand All @@ -78,7 +94,8 @@ void merge2() {
Mat roi(imgO(Rect(x, y, w, h)));
imgD.copyTo(roi);
namedWindow("Viewer", WINDOW_NORMAL);
resizeWindow("Viewer", 300, 750);
moveWindow("Viewer", 1, 1);
resizeWindow("Viewer", imgO.cols / 5.5, imgO.rows / 5.5);
imwrite("result\\" + para[j * 10] + ".png", imgO, compression_params);
imshow("Viewer", imgO);
waitKey(1);
Expand All @@ -91,8 +108,9 @@ void merge2() {
empty = true;
}
namedWindow("Viewer", WINDOW_NORMAL);
resizeWindow("Viewer", 300, 750);
resizeWindow("Viewer", imgO.cols / 5.5, imgO.rows / 5.5);
imwrite("result\\" + para[j * 10 + 1] + ".png", imgO, compression_params);
cvtColor(imgO, imgO, COLOR_BGRA2BGR);
imshow("Viewer", imgO);
waitKey(1);
sum2++;
Expand All @@ -102,6 +120,9 @@ void merge2() {
}
fclose(filelist);
system("del filelist.txt");
if (empty) {
cout << "警告:有部分图片无法读取,请手动检查!" << endl;
}
cout << "\n本次成功合并 " << sum1 << " 张差分图,并保留了 " << sum2 << " 张原图。" << endl;
cout << "共计获得 " << sum1 + sum2 << " 张人物立绘,好耶~~\n" << endl;
waitKey(1000);
Expand Down

0 comments on commit d4d5e4c

Please sign in to comment.