From 81bc9be03b12d7a29e9bc4cc1ede5c433a7af1dc Mon Sep 17 00:00:00 2001
From: wwj <3427896184@qq.com>
Date: 星期日, 29 六月 2025 15:59:32 +0800
Subject: [PATCH] 日志5
---
Server/汪卫军/log/日志_汪卫军_0626.doc | 0
Server/汪卫军/code/ImageProcessor.h | 15 +++++++
Server/汪卫军/code/ImageProcessor.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 108 insertions(+), 0 deletions(-)
diff --git "a/Server/\346\261\252\345\215\253\345\206\233/code/ImageProcessor.cpp" "b/Server/\346\261\252\345\215\253\345\206\233/code/ImageProcessor.cpp"
new file mode 100644
index 0000000..4148d4e
--- /dev/null
+++ "b/Server/\346\261\252\345\215\253\345\206\233/code/ImageProcessor.cpp"
@@ -0,0 +1,93 @@
+// ImageProcessor.cpp - 照片处理模块实现
+#include "stdafx.h"
+#include "ImageProcessor.h"
+#include <opencv2/opencv.hpp>
+
+ImageProcessor::ImageProcessor() {}
+
+ImageProcessor::~ImageProcessor() {}
+
+bool ImageProcessor::CropFace(const unsigned char* imageData, int width, int height,
+ unsigned char*& faceData, int& faceWidth, int& faceHeight) const {
+ try {
+ // 创建OpenCV图像
+ cv::Mat image(height, width, CV_8UC3, const_cast<unsigned char*>(imageData));
+
+ // 加载人脸检测器
+ cv::CascadeClassifier face_cascade;
+ if (!face_cascade.load(cv::samples::findFile("haarcascade_frontalface_alt.xml"))) {
+ std::cerr << "无法加载人脸检测器" << std::endl;
+ return false;
+ }
+
+ // 转换为灰度图
+ cv::Mat gray;
+ cv::cvtColor(image, gray, cv::COLOR_BGR2GRAY);
+ cv::equalizeHist(gray, gray);
+
+ // 检测人脸
+ std::vector<cv::Rect> faces;
+ face_cascade.detectMultiScale(gray, faces, 1.1, 2, 0 | cv::CASCADE_SCALE_IMAGE, cv::Size(30, 30));
+
+ if (faces.empty()) {
+ return false;
+ }
+
+ // 获取第一个检测到的人脸
+ cv::Rect face_rect = faces[0];
+ cv::Mat face = image(face_rect);
+
+ // 保存人脸数据
+ faceWidth = face.cols;
+ faceHeight = face.rows;
+ size_t dataSize = faceWidth * faceHeight * 3;
+
+ faceData = new unsigned char[dataSize];
+ memcpy(faceData, face.data, dataSize);
+
+ return true;
+ }
+ catch (const std::exception& e) {
+ std::cerr << "裁剪人脸失败: " << e.what() << std::endl;
+ return false;
+ }
+}
+
+bool ImageProcessor::EnhanceQuality(unsigned char* imageData, int width, int height) const {
+ try {
+ // 创建OpenCV图像
+ cv::Mat image(height, width, CV_8UC3, imageData);
+
+ // 图像增强处理
+ cv::Mat enhanced;
+ cv::GaussianBlur(image, enhanced, cv::Size(0, 0), 3);
+ cv::addWeighted(image, 1.5, enhanced, -0.5, 0, enhanced);
+
+ // 复制回原始数据
+ memcpy(imageData, enhanced.data, width * height * 3);
+
+ return true;
+ }
+ catch (const std::exception& e) {
+ std::cerr << "增强图像质量失败: " << e.what() << std::endl;
+ return false;
+ }
+}
+
+bool ImageProcessor::ValidateImage(const unsigned char* imageData, int width, int height) const {
+ try {
+ // 简单验证:检查图像尺寸是否合理
+ if (width < 10 || height < 10) {
+ return false;
+ }
+
+ // 这里可以添加更复杂的图像验证逻辑
+ // 例如:检查图像是否模糊、是否包含人脸等
+
+ return true;
+ }
+ catch (const std::exception& e) {
+ std::cerr << "验证图像失败: " << e.what() << std::endl;
+ return false;
+ }
+}
\ No newline at end of file
diff --git "a/Server/\346\261\252\345\215\253\345\206\233/code/ImageProcessor.h" "b/Server/\346\261\252\345\215\253\345\206\233/code/ImageProcessor.h"
new file mode 100644
index 0000000..2a5727b
--- /dev/null
+++ "b/Server/\346\261\252\345\215\253\345\206\233/code/ImageProcessor.h"
@@ -0,0 +1,15 @@
+// ImageProcessor.h - 照片处理模块
+#pragma once
+#include <string>
+#include "FaceImageManager.h"
+
+class ImageProcessor {
+public:
+ ImageProcessor();
+ ~ImageProcessor();
+
+ bool CropFace(const unsigned char* imageData, int width, int height,
+ unsigned char*& faceData, int& faceWidth, int& faceHeight) const;
+ bool EnhanceQuality(unsigned char* imageData, int width, int height) const;
+ bool ValidateImage(const unsigned char* imageData, int width, int height) const;
+};
\ No newline at end of file
diff --git "a/Server/\346\261\252\345\215\253\345\206\233/log/\346\227\245\345\277\227_\346\261\252\345\215\253\345\206\233_0626.doc" "b/Server/\346\261\252\345\215\253\345\206\233/log/\346\227\245\345\277\227_\346\261\252\345\215\253\345\206\233_0626.doc"
new file mode 100644
index 0000000..1e736cb
--- /dev/null
+++ "b/Server/\346\261\252\345\215\253\345\206\233/log/\346\227\245\345\277\227_\346\261\252\345\215\253\345\206\233_0626.doc"
Binary files differ
--
Gitblit v1.8.0