mirror of
https://github.com/Karllzy/cotton_color.git
synced 2025-11-09 11:13:54 +00:00
添加项目文件。
This commit is contained in:
parent
c3bf8ac649
commit
dc83db813b
53
README.md
Normal file
53
README.md
Normal file
@ -0,0 +1,53 @@
|
||||
# Cotton Color
|
||||
|
||||
## 颜色检测
|
||||
|
||||
### 艳丽色彩检测
|
||||
|
||||
纯色彩检测就可以。饱和度检测。
|
||||
|
||||
思路:rgb -> HSV -> s -> threshold -> 杂质
|
||||
|
||||
### 黑色检测/滴灌带检测
|
||||
|
||||
L a* b* 色彩空间检测,纯黑色就是杂质,但是容易有噪声。
|
||||
|
||||
思路:rgb -> La*b* -> threshold -> 黑色 -> 模板匹配 -> 物体的大小 -> 阈值判断 -> 杂质
|
||||
|
||||
### 暗黄色检测/油棉
|
||||
|
||||
L a* b* 色彩空间检测,检测暗黄色。
|
||||
|
||||
思路:rgb -> La*b* -> threshold -> 暗黄色 -> 模板匹配 -> 物体的大小 -> 阈值判断 -> 杂质
|
||||
|
||||
### 带土地膜检测
|
||||
|
||||
L a* b* 色彩空间检测,检测明黄色、白色。
|
||||
|
||||
思路:rgb -> La*b* -> threshold -> 白色、明黄色 -> 模板匹配 -> 物体的大小 -> 阈值判断 -> 杂质
|
||||
|
||||
|
||||
## 深度学习检测
|
||||
|
||||
需求:模板匹配缺少对于纹理的判断,所以要加上深度学习对于各个杂质进行确认。
|
||||
|
||||
### 方案1:端到端式的方案
|
||||
|
||||
传统思路:rgb -> La*b* -> threshold -> 白色、明黄色 -> 模板匹配 -> 物体的大小 -> 阈值判断 -> 杂质
|
||||
|
||||
深度学习思路:rgb -> 可疑色彩图像增强 -> threshold -> 白色、明黄色 -> 模板匹配 -> 物体的大小 -> 阈值判断 -> 杂质
|
||||
|
|
||||
-> YOLO -> 杂质
|
||||
|
||||
|
||||
### 方案2:验证形式的方案
|
||||
|
||||
传统思路:rgb -> La*b* -> threshold -> 白色、明黄色 -> 模板匹配 -> 物体的大小 -> 阈值判断 -> 杂质
|
||||
|
||||
融合深度学习思路:rgb -> La*b* -> threshold -> 白色、明黄色 -> 模板匹配 -> 物体的大小 -> 阈值判断 -> 杂质
|
||||
| |
|
||||
激进方案 -> 深度学习 - > 区块判别 -> 杂质 |
|
||||
|
|
||||
保守方案 -> 深度学习确认 -> 杂质
|
||||
|
||||
|
||||
81
cotton_color.cpp
Normal file
81
cotton_color.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
|
||||
/**
|
||||
* @brief 鲜艳色彩检测函数,通过饱和度阈值检测输入图像中鲜艳的颜色区域。
|
||||
*
|
||||
* 此函数将输入图像从 BGR 色彩空间转换到 HSV 色彩空间,并提取出饱和度 (S) 通道。然后,通过设置饱和度阈值,
|
||||
* 来检测图像中饱和度大于阈值的区域,标记为输出图像的鲜艳颜色区域。
|
||||
*
|
||||
* @param inputImage 输入图像,类型为 cv::Mat,要求为 BGR 色彩空间。
|
||||
* @param outputImage 输出图像,类型为 cv::Mat,输出图像将标记出鲜艳颜色区域,原始图像尺寸。
|
||||
* @param saturationThreshold 饱和度阈值,类型为 int,用于过滤低饱和度的区域,范围通常为 0 到 255。
|
||||
* 饱和度高于此阈值的区域将被认为是鲜艳的颜色。
|
||||
*
|
||||
* @note 饱和度阈值越高,输出图像将只保留更为鲜艳的区域。
|
||||
* 若饱和度阈值过低,可能会检测到过多的区域。
|
||||
*/
|
||||
/**
|
||||
* @brief 鲜艳色彩检测函数,通过饱和度阈值检测输入图像中鲜艳的颜色区域。
|
||||
*
|
||||
* @param inputImage 输入图像,类型为 cv::Mat,要求为 BGR 色彩空间。
|
||||
* @param outputImage 输出图像,类型为 cv::Mat,输出图像将标记出鲜艳颜色区域,原始图像尺寸。
|
||||
* @param params 参数映射,用于传递各种可配置的参数,如饱和度阈值等。
|
||||
*/
|
||||
void vibrantColorDetection(const Mat& inputImage, Mat& outputImage, const map<string, int>& params) {
|
||||
// 从参数映射中获取饱和度阈值
|
||||
int saturationThreshold = params.at("saturationThreshold");
|
||||
|
||||
// 将输入图像从 BGR 转换为 HSV
|
||||
Mat hsvImage;
|
||||
cvtColor(inputImage, hsvImage, COLOR_BGR2HSV);
|
||||
|
||||
// 分离 HSV 图像的各个通道
|
||||
Mat channels[3];
|
||||
split(hsvImage, channels);
|
||||
|
||||
// 获取饱和度通道 (S)
|
||||
Mat saturation = channels[1];
|
||||
|
||||
// 创建输出图像,将饱和度大于阈值的区域标记为杂质
|
||||
outputImage = Mat::zeros(inputImage.size(), CV_8UC1);
|
||||
|
||||
// 对饱和度图像应用阈值处理
|
||||
threshold(saturation, outputImage, saturationThreshold, 255, THRESH_BINARY);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
// 读取输入图像
|
||||
Mat inputImage = imread("C:\\Program Files\\Matrox Imaging\\Images\\test.bmp");
|
||||
|
||||
if (inputImage.empty()) {
|
||||
cout << "Error: Could not load image!" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 创建输出图像
|
||||
Mat outputImage;
|
||||
|
||||
// 使用 map 模拟 JSON 参数传递
|
||||
map<string, int> params;
|
||||
params["saturationThreshold"] = 100; // 设置饱和度阈值为100
|
||||
|
||||
// 调用鲜艳颜色检测函数
|
||||
vibrantColorDetection(inputImage, outputImage, params);
|
||||
|
||||
// 显示原图和检测到的鲜艳区域
|
||||
imshow("Original Image", inputImage);
|
||||
imshow("Detected Vibrant Colors", outputImage);
|
||||
|
||||
// 等待用户按键
|
||||
waitKey(0);
|
||||
return 0;
|
||||
}
|
||||
31
cotton_color.sln
Normal file
31
cotton_color.sln
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.11.35327.3
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cotton_color", "cotton_color.vcxproj", "{6205CBCD-F3B8-4365-B6BD-FFA76FF9D993}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{6205CBCD-F3B8-4365-B6BD-FFA76FF9D993}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{6205CBCD-F3B8-4365-B6BD-FFA76FF9D993}.Debug|x64.Build.0 = Debug|x64
|
||||
{6205CBCD-F3B8-4365-B6BD-FFA76FF9D993}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{6205CBCD-F3B8-4365-B6BD-FFA76FF9D993}.Debug|x86.Build.0 = Debug|Win32
|
||||
{6205CBCD-F3B8-4365-B6BD-FFA76FF9D993}.Release|x64.ActiveCfg = Release|x64
|
||||
{6205CBCD-F3B8-4365-B6BD-FFA76FF9D993}.Release|x64.Build.0 = Release|x64
|
||||
{6205CBCD-F3B8-4365-B6BD-FFA76FF9D993}.Release|x86.ActiveCfg = Release|Win32
|
||||
{6205CBCD-F3B8-4365-B6BD-FFA76FF9D993}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {96810E2B-2AC9-4993-AC53-052B8AA18FA4}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
138
cotton_color.vcxproj
Normal file
138
cotton_color.vcxproj
Normal file
@ -0,0 +1,138 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{6205cbcd-f3b8-4365-b6bd-ffa76ff9d993}</ProjectGuid>
|
||||
<RootNamespace>cottoncolor</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>C:\Users\ZLSDKJ\source\opencv\build\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>C:\Users\ZLSDKJ\source\opencv\build\x64\vc16\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>opencv_world4100.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="cotton_color.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
22
cotton_color.vcxproj.filters
Normal file
22
cotton_color.vcxproj.filters
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="cotton_color.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Loading…
Reference in New Issue
Block a user