From d1c0f2f9f89090ee49302d44d62899dc7e1814e7 Mon Sep 17 00:00:00 2001
From: zjc-zjc-123 <1714105370@qq.com>
Date: Thu, 7 Nov 2024 13:57:17 +0800
Subject: [PATCH] add GreenDetection
add GreenDetection
---
.idea/cotton_color.iml | 8 +++
.../inspectionProfiles/profiles_settings.xml | 6 ++
.idea/misc.xml | 4 ++
.idea/modules.xml | 8 +++
.idea/vcs.xml | 6 ++
.idea/workspace.xml | 66 +++++++++++++++++++
cotton_color.cpp | 37 +++++++++--
cotton_color.vcxproj | 1 +
8 files changed, 131 insertions(+), 5 deletions(-)
create mode 100644 .idea/cotton_color.iml
create mode 100644 .idea/inspectionProfiles/profiles_settings.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/vcs.xml
create mode 100644 .idea/workspace.xml
diff --git a/.idea/cotton_color.iml b/.idea/cotton_color.iml
new file mode 100644
index 0000000..d0876a7
--- /dev/null
+++ b/.idea/cotton_color.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..060d2c5
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..876a814
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..7bc015d
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1730791232605
+
+
+ 1730791232605
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cotton_color.cpp b/cotton_color.cpp
index 5d3df12..1726e43 100644
--- a/cotton_color.cpp
+++ b/cotton_color.cpp
@@ -52,7 +52,33 @@ void vibrantColorDetection(const Mat& inputImage, Mat& outputImage, const map& params) {
+ // 从参数映射中获取饱和度阈值
+ int green = params.at("green");
+ // 将输入图像从 BGR 转换为 HSV
+ Mat lab_image;
+ cvtColor(inputImage, lab_image, cv::COLOR_BGR2Lab);
+
+ // 定义偏绿色的Lab范围(具体值可能需要调整)
+ Scalar lower_green_lab(101, 101, 95);
+ Scalar upper_green_lab(135, 120, green);
+
+ // 创建掩膜
+ Mat mask_lab;
+ inRange(lab_image, lower_green_lab, upper_green_lab, mask_lab);
+
+ // 通过掩膜提取偏绿色部分
+ Mat masked_image_lab;
+ bitwise_and(inputImage, inputImage, masked_image_lab, mask_lab);
+
+ // 显示结果
+ imshow("Original Image", inputImage);
+ imshow("Mask Lab", mask_lab);
+ //cv::imshow("Masked Image Lab", masked_image_lab);
+ waitKey(0);
+ destroyAllWindows();
+}
string openFileDialog() {
// 初始化文件选择对话框
@@ -85,7 +111,7 @@ string openFileDialog() {
}
-void test() {}
+
Mat readImage() {
// 读取输入图像
string imagePath = openFileDialog();
@@ -109,7 +135,7 @@ Mat readImage() {
int main() {
// 读取输入图像
- Mat inputImage = readImage();
+ Mat inputImage = readImage();
if (inputImage.empty()) {
cout << "Error: Could not load image." << endl;
@@ -121,10 +147,10 @@ int main() {
// 使用 map 模拟 JSON 参数传递
map params;
- params["saturationThreshold"] = 100; // 设置饱和度阈值为100
+ params["green"] =134; // 设置饱和度阈值为100
// 调用鲜艳颜色检测函数
- vibrantColorDetection(inputImage, outputImage, params);
+ vibrantGreenDetection(inputImage, outputImage, params);
// 显示原图和检测到的鲜艳区域
imshow("Original Image", inputImage);
@@ -133,4 +159,5 @@ int main() {
// 等待用户按键
waitKey(0);
return 0;
-}
\ No newline at end of file
+}
+
diff --git a/cotton_color.vcxproj b/cotton_color.vcxproj
index 8a13bfb..2c944c3 100644
--- a/cotton_color.vcxproj
+++ b/cotton_color.vcxproj
@@ -122,6 +122,7 @@
NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
E:\opencv4.10\opencv\build\include;%(AdditionalIncludeDirectories)
+ ProgramDatabase
Console