Commit 0871eb39 张士柳

1 个父辈 da2526be
...@@ -995,12 +995,28 @@ namespace eyemLib_Sharp ...@@ -995,12 +995,28 @@ namespace eyemLib_Sharp
private static extern int eyemInitNNDetector(string detectorConfigPath, string detectorModelPath, int iNetSizew, int iNetSizeh); private static extern int eyemInitNNDetector(string detectorConfigPath, string detectorModelPath, int iNetSizew, int iNetSizeh);
/// <summary> /// <summary>
/// 设置检测参数
/// </summary>
/// <param name="fConfidence">置信度</param>
/// <param name="fNMSThreshold">非极大值抑制阈值</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemNNDetectorParams(float fConfidence, float fNMSThreshold);
/// <summary>
/// 目标检测器 /// 目标检测器
/// </summary> /// </summary>
/// <param name="tpImage">输入图像</param> /// <param name="tpImage">输入图像</param>
/// <returns></returns> /// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemNNDetector(EyemImage tpImage, out int ipNum, ref BboxContainer container, out EyemImage tpDstImg); private static extern int eyemNNDetector(EyemImage tpImage, out int ipNum, ref BboxContainer container, out EyemImage tpDstImg);
/// <summary>
/// 初始化darknet分类器
/// </summary>
/// <param name="classifierConfigPath">配置地址</param>
/// <param name="classifierModelPath">模型地址</param>
/// <param name="ntype">0 检测网络,1 分类网络</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemInitClassifier(string classifierConfigPath, string classifierModelPath, int ntype); private static extern int eyemInitClassifier(string classifierConfigPath, string classifierModelPath, int ntype);
...@@ -1085,6 +1101,14 @@ namespace eyemLib_Sharp ...@@ -1085,6 +1101,14 @@ namespace eyemLib_Sharp
//多功能工具 //多功能工具
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, string funcName, double dThreshold, int iNumToIgnore, ref EyemOcsFXYR tpCircle, out EyemImage tpDstImg); private static extern int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, string funcName, double dThreshold, int iNumToIgnore, ref EyemOcsFXYR tpCircle, out EyemImage tpDstImg);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemDetectCircleUseHough(EyemImage tpImage, EyemRect tpRoi, EyemRect limRoi, out EyemOcsDXYR tpCircle, out EyemImage tpDstImg, double dp, double dMinDist, double dParam1, double dParam2, double dMinRadius, double dMaxRadius, int iMethod = 3, bool useValLimit = false);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void loadImage2Mem(string key, EyemImage tpImage);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int setProcessLevel(double pl);
#endregion #endregion
#region 测试专用接口 #region 测试专用接口
...@@ -1094,6 +1118,8 @@ namespace eyemLib_Sharp ...@@ -1094,6 +1118,8 @@ namespace eyemLib_Sharp
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemEdge1dRidgeDetection(EyemImage tpImage); private static extern int eyemEdge1dRidgeDetection(EyemImage tpImage);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBuildTrainFile(string filePath, string fileName);
#endregion #endregion
...@@ -1119,9 +1145,15 @@ namespace eyemLib_Sharp ...@@ -1119,9 +1145,15 @@ namespace eyemLib_Sharp
OnNewLogCallback += new TCallBack(EyemLib_OnNewLogCallback); OnNewLogCallback += new TCallBack(EyemLib_OnNewLogCallback);
eyemInitNNDataCodeModel(".\\darknet\\detect-tiny.cfg", ".\\darknet\\detect-tiny.weights", ".\\darknet\\sr.prototxt", ".\\darknet\\sr.caffemodel"); //setProcessLevel(2.0);
//EyemImage image_back = new EyemImage();
//eyemImageRead("D:\\Img20211028142015.png", -1, out image_back);
//loadImage2Mem("back", image_back);
eyemInitClassifier("D:\\detect-tiny-tray.cfg", "D:\\detect-tiny-tray.weights", 0); //eyemInitNNDataCodeModel(".\\darknet\\detect-tiny.cfg", ".\\darknet\\detect-tiny.weights", ".\\darknet\\sr.prototxt", ".\\darknet\\sr.caffemodel");
//eyemInitClassifier("D:\\detect-tiny-tray.cfg", "D:\\detect-tiny-tray.weights", 0);
} }
public static void Free() public static void Free()
...@@ -1177,13 +1209,29 @@ namespace eyemLib_Sharp ...@@ -1177,13 +1209,29 @@ namespace eyemLib_Sharp
sw.Restart(); sw.Restart();
string file = fileName.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries)[2]; string file = fileName.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries)[2];
//string[] fileNames = Directory.GetFiles(@"D:\训练数据集\点料机料盘识别\val_images", "*.png", SearchOption.AllDirectories); //string[] fileNames = Directory.GetFiles(@"C:\Users\nzslw\PycharmProjects\pythonProject\venv\data\AntBee\test\ants", "*.jpg", SearchOption.AllDirectories);
//eyemBuildTrainFile(@"D:\darknet-master\build\darknet\x64\data\val_images", "D:/val.txt");
//return;
//foreach (var item in fileNames)
//{
// eyemBuildTrainFile(item, "D:\\标签识别\\" + item.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries)[4]);
//}
//return;
//List<string> random_shuffle = new List<string>(fileNames); //List<string> random_shuffle = new List<string>(fileNames);
////随机打乱顺序 ////随机打乱顺序
//RandomShuffle(random_shuffle); //RandomShuffle(random_shuffle);
//bool HaveDuplicates = random_shuffle.GroupBy(i => i).Where(g => g.Count() > 1).Count() >= 1; //bool HaveDuplicates = random_shuffle.GroupBy(i => i).Where(g => g.Count() > 1).Count() >= 1;
//for (int i = 0; i < fileNames.Length; i++)
//{
// string item = fileNames[i];
// string[] items = item.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
// FileInfo fi = new FileInfo(item);
// fi.MoveTo(@"D:\日志\" + (i+83).ToString() + ".png");
//}
//return;
//StreamWriter swr = new StreamWriter("D:\\val.txt", true); //StreamWriter swr = new StreamWriter("D:\\val.txt", true);
//foreach (var item in random_shuffle) //foreach (var item in random_shuffle)
//{ //{
...@@ -1226,7 +1274,7 @@ namespace eyemLib_Sharp ...@@ -1226,7 +1274,7 @@ namespace eyemLib_Sharp
//tpHsvModel.dpRangeL = new double[] { 100, 43, 46 }; tpHsvModel.dpRangeU = new double[] { 124, 255, 255 }; //tpHsvModel.dpRangeL = new double[] { 100, 43, 46 }; tpHsvModel.dpRangeU = new double[] { 124, 255, 255 };
//tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 }; //tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 };
//eyemClassifier(image); //eyemClassifier(image);
//flag = eyemLibImpl(image, out tpDstImg); flag = eyemLibImpl(image, out tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg); //Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null) //if (bitmap != null)
//{ //{
...@@ -1234,7 +1282,7 @@ namespace eyemLib_Sharp ...@@ -1234,7 +1282,7 @@ namespace eyemLib_Sharp
//} //}
//eyemImageFree(ref tpDstImg); //eyemImageFree(ref tpDstImg);
//eyemImageFree(ref image); //eyemImageFree(ref image);
//return; return;
//EyemImage templ, search; //EyemImage templ, search;
//flag = eyemImageRead("D://批量测试图像//template.png", -1, out templ); //flag = eyemImageRead("D://批量测试图像//template.png", -1, out templ);
...@@ -1454,9 +1502,14 @@ namespace eyemLib_Sharp ...@@ -1454,9 +1502,14 @@ namespace eyemLib_Sharp
tpRoi.iWidth = image.iWidth - 100; tpRoi.iWidth = image.iWidth - 100;
tpRoi.iHeight = image.iHeight - 100; tpRoi.iHeight = image.iHeight - 100;
//flag = eyemMulFuncTool(image, tpRoi, "__func1", 65, 75, ref tpCircle, out tpDstImg);
int[] ipReelNum = new int[4];
//flag = eyemAchvMatchMat(image, tpRoi, out tpDstImg); //flag = eyemAchvMatchMat(image, tpRoi, out tpDstImg);
//EyemOcsDXYR tpCircle = new EyemOcsDXYR();
//EyemRect limRoi = new EyemRect();
//limRoi.iXs = 222; limRoi.iYs = 222;
//limRoi.iWidth = 214;
//limRoi.iHeight = 214;
//flag = eyemDetectCircleUseHough(image, tpRoi, limRoi, out tpCircle, out tpDstImg, 1.0, 80, 100, 50, 28, 43, 3, true);
//////flag = eyemMulFuncTool(image, tpRoi, "__func1__", 65, 75, ref tpCircle, out tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg); //Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null) //if (bitmap != null)
//{ //{
...@@ -1521,20 +1574,21 @@ namespace eyemLib_Sharp ...@@ -1521,20 +1574,21 @@ namespace eyemLib_Sharp
//如果对象供其他接口使用要先释放 //如果对象供其他接口使用要先释放
//eyemImageFree(ref tpDstImg); //eyemImageFree(ref tpDstImg);
int[] ipReelNum = new int[4];
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS",,IP_SQUARE_PARTS //"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS",,IP_SQUARE_PARTS
//eyemCountObject(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg); //eyemCountObject(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
//eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), "IP_LARGE_PARTS", ipReelNum, out tpDstImg); //eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), "IP_LARGE_PARTS", ipReelNum, out tpDstImg);
//eyemCountObjectE(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg); eyemCountObjectE(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + "20210825095751-1.tpl", hModelID, ipReelNum, out tpDstImg); //eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + "20210825095751-1.tpl", hModelID, ipReelNum, out tpDstImg);
//移除模板 //移除模板
//flag = eyemRemoveModelByName(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl"); //flag = eyemRemoveModelByName(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg); Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null) if (bitmap != null)
//{ {
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file); bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
//} }
//< 解码测试 //< 解码测试
//int ipNum; EyemBarCode* tpResults; //int ipNum; EyemBarCode* tpResults;
......
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14 # Visual Studio 14
VisualStudioVersion = 14.0.25420.1 VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "eyemLib", "eyemLib\eyemLib.vcxproj", "{33D5F550-C799-4B05-8E14-ACA390DF5442}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "eyemLib", "eyemLib\eyemLib.vcxproj", "{33D5F550-C799-4B05-8E14-ACA390DF5442}"
EndProject EndProject
......
...@@ -20,12 +20,23 @@ void setLogCallback(TCallback cb) ...@@ -20,12 +20,23 @@ void setLogCallback(TCallback cb)
} }
int killProcessID = -1; int killProcessID = -1;
void setSkipProcessID(int pid) void setSkipProcessID(int pid)
{ {
killProcessID = pid; killProcessID = pid;
} }
double processLevel = 2.0;
void setProcessLevel(double processLevel_)
{
processLevel = processLevel_;
}
std::map<std::string, EyemImage> imageMap;
void loadImage2Mem(const char *key, EyemImage tpImage)
{
imageMap.insert(std::pair<std::string, EyemImage>(std::string(key), tpImage));
}
Logger logger; Logger logger;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
......
...@@ -868,6 +868,7 @@ extern "C" { ...@@ -868,6 +868,7 @@ extern "C" {
// 函数接口 // 函数接口
EXPORTS int eyemInitNNDetector(const char *detectorConfigPath, const char *detectorModelPath, int iNetSizew, int iNetSizeh); EXPORTS int eyemInitNNDetector(const char *detectorConfigPath, const char *detectorModelPath, int iNetSizew, int iNetSizeh);
EXPORTS int eyemNNDetectorParams(float fConfidence, float fNMSThreshold);
EXPORTS int eyemNNDetector(EyemImage tpImage, int *ipNum, BboxContainer &container, EyemImage *tpDstImg); EXPORTS int eyemNNDetector(EyemImage tpImage, int *ipNum, BboxContainer &container, EyemImage *tpDstImg);
EXPORTS int eyemInitClassifier(const char *classifierConfigPath, const char *classifierModelPath, int ntype); EXPORTS int eyemInitClassifier(const char *classifierConfigPath, const char *classifierModelPath, int ntype);
EXPORTS int eyemClassifier(EyemImage tpImage); EXPORTS int eyemClassifier(EyemImage tpImage);
...@@ -925,11 +926,13 @@ extern "C" { ...@@ -925,11 +926,13 @@ extern "C" {
EXPORTS int eyemTrackFeature(EyemImage tpPrevImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum, int *ipResults, EyemImage *tpDstImg); EXPORTS int eyemTrackFeature(EyemImage tpPrevImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum, int *ipResults, EyemImage *tpDstImg);
EXPORTS int eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum); EXPORTS int eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum);
EXPORTS int eyemMarkerTracing(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemOcsFXYR *tpCircle, EyemImage *tpDstImg, bool bHighAccuracy = false); EXPORTS int eyemMarkerTracing(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemOcsFXYR *tpCircle, EyemImage *tpDstImg, bool bHighAccuracy = false);
EXPORTS int eyemDetectCircleUseHough(EyemImage tpImage, EyemRect tpRoi, EyemRect limRoi, EyemOcsDXYR *tpCircle, EyemImage *tpDstImg, double dp, double dMinDist, double dParam1, double dParam2, double dMinRadius, double dMaxRadius, int iMethod = 3, bool useValLimit = false);
EXPORTS int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, double dThreshold, int iNumToIgnore, EyemOcsFXYR *tpCircle, EyemImage *tpDstImg); EXPORTS int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, double dThreshold, int iNumToIgnore, EyemOcsFXYR *tpCircle, EyemImage *tpDstImg);
EXPORTS int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg); EXPORTS int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg);
EXPORTS int eyemDrawLine(EyemImage tpImage, EyemOcsDABC tpLine); EXPORTS int eyemDrawLine(EyemImage tpImage, EyemOcsDABC tpLine);
EXPORTS int eyemDrawCircle(EyemImage tpImage, EyemOcsDXYR tpCircle); EXPORTS int eyemDrawCircle(EyemImage tpImage, EyemOcsDXYR tpCircle);
EXPORTS int eyemDrawRectangle(EyemImage tpImag, EyemRect tpRect); EXPORTS int eyemDrawRectangle(EyemImage tpImag, EyemRect tpRect);
EXPORTS int eyemBuildTrainFile(const char *filePath, const char *fileName);
#ifdef __cplusplus #ifdef __cplusplus
} }
...@@ -938,6 +941,12 @@ extern "C" { ...@@ -938,6 +941,12 @@ extern "C" {
// 跳过某接口执行 // 跳过某接口执行
extern "C" __declspec(dllexport) void setSkipProcessID(int pid); extern "C" __declspec(dllexport) void setSkipProcessID(int pid);
//设置全局参数
extern "C" __declspec(dllexport) void setProcessLevel(double pl);
// 加载图像到内存
extern "C" __declspec(dllexport) void loadImage2Mem(const char *key, EyemImage tpImage);
// 日志回调定义 // 日志回调定义
typedef void(__stdcall*TCallback)(const char* msg); typedef void(__stdcall*TCallback)(const char* msg);
......
此文件类型无法预览
...@@ -83,8 +83,8 @@ ...@@ -83,8 +83,8 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
<IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;D:\darknet\include;D:\3rdparty\pthreads\include;$(IncludePath)</IncludePath> <IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Release;D:\darknet\lib;D:\3rdparty\pthreads\lib;$(LibraryPath)</LibraryPath> <LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Release;$(LibraryPath)</LibraryPath>
<TargetExt>.dll</TargetExt> <TargetExt>.dll</TargetExt>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
...@@ -161,7 +161,7 @@ ...@@ -161,7 +161,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libdmtx.lib;libzxing.lib;libdecode.lib;darknet.lib;pthreadVC2.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>libdmtx.lib;libzxing.lib;libdecode.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
......
...@@ -13,5 +13,7 @@ constexpr double c = PI / 180.; ...@@ -13,5 +13,7 @@ constexpr double c = PI / 180.;
extern Logger logger; extern Logger logger;
extern int killProcessID; extern int killProcessID;
extern double processLevel;
extern std::map<std::string, EyemImage> imageMap;
#endif/* __EYEM_MISC_H */ #endif/* __EYEM_MISC_H */
...@@ -4,10 +4,13 @@ class NNDetector::Impl { ...@@ -4,10 +4,13 @@ class NNDetector::Impl {
public: public:
Impl() {} Impl() {}
~Impl() {} ~Impl() {}
//目标检测 //目标检测
std::vector<cv::Rect> detect(const cv::Mat& img); std::vector<cv::Rect> detect(const cv::Mat& img);
//目标检测器 //目标检测器
std::shared_ptr<YoloWrapper> detector_; std::shared_ptr<YoloWrapper> detector_;
//目标检测参数
float _fConfidence = 0.01f, _fNMSThreshold = 0.05f;
}; };
NNDetector::NNDetector(const std::string & detector_config_path, NNDetector::NNDetector(const std::string & detector_config_path,
...@@ -23,6 +26,11 @@ NNDetector::NNDetector(const std::string & detector_config_path, ...@@ -23,6 +26,11 @@ NNDetector::NNDetector(const std::string & detector_config_path,
} }
} }
void NNDetector::setInputParams(float fConfidence, float fNMSThreshold)
{
p->_fConfidence = fConfidence; p->_fNMSThreshold = fNMSThreshold;
}
std::vector<cv::Rect> NNDetector::detect(cv::InputArray img) std::vector<cv::Rect> NNDetector::detect(cv::InputArray img)
{ {
CV_Assert(!img.empty()); CV_Assert(!img.empty());
...@@ -41,6 +49,7 @@ std::vector<cv::Rect> NNDetector::detect(cv::InputArray img) ...@@ -41,6 +49,7 @@ std::vector<cv::Rect> NNDetector::detect(cv::InputArray img)
} }
std::vector<cv::Rect> NNDetector::Impl::detect(const cv::Mat& img) { std::vector<cv::Rect> NNDetector::Impl::detect(const cv::Mat& img) {
detector_->setPreferableParams(_fConfidence, _fNMSThreshold);
return detector_->forward(img); return detector_->forward(img);
} }
...@@ -56,6 +65,12 @@ int eyemInitNNDetector(const char *detectorConfigPath, const char *detectorModel ...@@ -56,6 +65,12 @@ int eyemInitNNDetector(const char *detectorConfigPath, const char *detectorModel
return FUNC_OK; return FUNC_OK;
} }
int eyemNNDetectorParams(float fConfidence, float fNMSThreshold)
{
pNNDetector->setInputParams(fConfidence, fNMSThreshold);
return FUNC_OK;
}
int eyemNNDetector(EyemImage tpImage, int *ipNum, BboxContainer &container, EyemImage *tpDstImg) int eyemNNDetector(EyemImage tpImage, int *ipNum, BboxContainer &container, EyemImage *tpDstImg)
{ {
cv::Mat src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone(); cv::Mat src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
...@@ -106,6 +121,7 @@ int eyemNNDetector(EyemImage tpImage, int *ipNum, BboxContainer &container, Eyem ...@@ -106,6 +121,7 @@ int eyemNNDetector(EyemImage tpImage, int *ipNum, BboxContainer &container, Eyem
return FUNC_OK; return FUNC_OK;
} }
#ifdef _DEBUG
int eyemInitClassifier(const char *classifierConfigPath, const char *classifierModelPath, int ntype) int eyemInitClassifier(const char *classifierConfigPath, const char *classifierModelPath, int ntype)
{ {
try { try {
...@@ -142,3 +158,4 @@ int eyemClassifier(EyemImage tpImage) ...@@ -142,3 +158,4 @@ int eyemClassifier(EyemImage tpImage)
return FUNC_OK; return FUNC_OK;
} }
#endif
\ No newline at end of file \ No newline at end of file
...@@ -13,7 +13,8 @@ public: ...@@ -13,7 +13,8 @@ public:
NNDetector(const std::string& detector_config_path, NNDetector(const std::string& detector_config_path,
const std::string& detector_model_path, const cv::Size& input_size); const std::string& detector_model_path, const cv::Size& input_size);
NNDetector() {}; NNDetector() {};
//ü
void setInputParams(float fConfidence, float fNMSThreshold);
std::vector<cv::Rect> detect(cv::InputArray img); std::vector<cv::Rect> detect(cv::InputArray img);
protected: protected:
...@@ -23,6 +24,8 @@ protected: ...@@ -23,6 +24,8 @@ protected:
cv::Ptr<NNDetector> pNNDetector; cv::Ptr<NNDetector> pNNDetector;
#ifdef _DEBUG
cv::Ptr<YoloDarknet> pClassifier; cv::Ptr<YoloDarknet> pClassifier;
#endif
#endif/* __EYEMNNDETECTOR_H */ #endif/* __EYEMNNDETECTOR_H */
\ No newline at end of file \ No newline at end of file
...@@ -13,6 +13,12 @@ int YoloWrapper::init(const std::string& detector_config_path, ...@@ -13,6 +13,12 @@ int YoloWrapper::init(const std::string& detector_config_path,
return 0; return 0;
} }
int YoloWrapper::setPreferableParams(float fConfidence, float fNMSThreshold)
{
this->confidence = fConfidence; this->NMSThreshold = fNMSThreshold;
return 0;
}
std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) { std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) {
//获取输出层名称 //获取输出层名称
auto layerNames = net_.getLayerNames(); auto layerNames = net_.getLayerNames();
...@@ -42,13 +48,11 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) { ...@@ -42,13 +48,11 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) {
//置信度 //置信度
cv::Mat prob = outputBlobs[n](cv::Range(row, row + 1), cv::Range(5, outputBlobs[n].cols)); cv::Mat prob = outputBlobs[n](cv::Range(row, row + 1), cv::Range(5, outputBlobs[n].cols));
double confidence;
cv::Point classIdPoint;
//取得最大分数值与索引 //取得最大分数值与索引
cv::minMaxLoc(prob, 0, &confidence, 0, &classIdPoint); double score = .0; cv::Point classIdPoint;
cv::minMaxLoc(prob, 0, &score, 0, &classIdPoint);
//把可能的区域都算作进去 //把可能的区域都算作进去
if (confidence > 0.01) { if (score > confidence) {
cv::Mat dt = outputBlobs[n](cv::Range(row, row + 1), cv::Range(0, 5)); cv::Mat dt = outputBlobs[n](cv::Range(row, row + 1), cv::Range(0, 5));
int cx = cvRound(dt.ptr<float>(0)[0] * (float)img.cols); int cx = cvRound(dt.ptr<float>(0)[0] * (float)img.cols);
...@@ -59,14 +63,14 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) { ...@@ -59,14 +63,14 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) {
int left = cx - w / 2; int left = cx - w / 2;
int top = cy - h / 2; int top = cy - h / 2;
confidences.push_back((float)confidence); confidences.push_back((float)score);
bboxes.push_back(cv::Rect(left, top, w, h)); bboxes.push_back(cv::Rect(left, top, w, h));
} }
} }
} }
std::vector<int> indices; std::vector<int> indices;
//非极大值抑制 //非极大值抑制
cv::dnn::NMSBoxes(bboxes, confidences, 0.01f, 0.05f, indices); cv::dnn::NMSBoxes(bboxes, confidences, confidence, NMSThreshold, indices);
//裁剪区域 //裁剪区域
auto points = std::vector<cv::Rect>(); auto points = std::vector<cv::Rect>();
for (int i = 0; i < indices.size(); i++) { for (int i = 0; i < indices.size(); i++) {
...@@ -77,6 +81,8 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) { ...@@ -77,6 +81,8 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) {
return points; return points;
} }
#ifdef _DEBUG
class YoloDarknet::Impl { class YoloDarknet::Impl {
public: public:
Impl() {} Impl() {}
...@@ -114,3 +120,4 @@ void YoloDarknet::forward(std::vector<int> &outputPredict, std::vector<float> &o ...@@ -114,3 +120,4 @@ void YoloDarknet::forward(std::vector<int> &outputPredict, std::vector<float> &o
} }
delete[] predicts; predicts = NULL; delete[] confidence; confidence = NULL; delete[] predicts; predicts = NULL; delete[] confidence; confidence = NULL;
} }
#endif
...@@ -8,20 +8,25 @@ ...@@ -8,20 +8,25 @@
#include "opencv2/dnn.hpp" #include "opencv2/dnn.hpp"
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc.hpp"
#ifdef _DEBUG
#include <darknet.h> #include <darknet.h>
#include <yolo_class.h> #include <yolo_class.h>
#endif
class YoloWrapper class YoloWrapper
{ {
public: public:
YoloWrapper() {}; YoloWrapper() {};
int init(const std::string& config_path, const std::string& model_path, const cv::Size& input_size); int init(const std::string& config_path, const std::string& model_path, const cv::Size& input_size);
int setPreferableParams(float fConfidence, float fNMSThreshold);//置信度,非极大值抑制阈值
std::vector<cv::Rect> forward(cv::Mat img); std::vector<cv::Rect> forward(cv::Mat img);
private: private:
cv::Size Size_; cv::Size Size_;
float confidence = 0.01f, NMSThreshold = 0.05f;
cv::dnn::Net net_; cv::dnn::Net net_;
}; };
#ifdef _DEBUG
class YoloDarknet class YoloDarknet
{ {
public: public:
...@@ -36,6 +41,6 @@ protected: ...@@ -36,6 +41,6 @@ protected:
class Impl; class Impl;
cv::Ptr<Impl> p; cv::Ptr<Impl> p;
}; };
#endif
#endif/* __YOLOWRAPPER_H */ #endif/* __YOLOWRAPPER_H */
\ No newline at end of file \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!