Commit 29630f64 张士柳

1 个父辈 b2c1dc1c
...@@ -983,6 +983,13 @@ namespace eyemLib_Sharp ...@@ -983,6 +983,13 @@ namespace eyemLib_Sharp
private static extern int eyemNNDetector(EyemImage tpImage, out int ipNum, ref BboxContainer container); private static extern int eyemNNDetector(EyemImage tpImage, out int ipNum, ref BboxContainer container);
#endregion #endregion
#region 模板匹配
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMakeShapeModel(EyemImage tpImage, double dContrast, double dMinContrast, int iApertureSize = 3, bool bL2gradient = false);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemFindShapeModel(EyemImage tpImage, int iNumLevels, double dAngleStart, double dAngleExtent, double dAngleStep, double dMinContrast, double dContrast, double dGreediness, double dMinScore, bool bOptimization = true);
#endregion
#region 项目 #region 项目
//普通器件(仍采用旧的算法) //普通器件(仍采用旧的算法)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
...@@ -1144,12 +1151,34 @@ namespace eyemLib_Sharp ...@@ -1144,12 +1151,34 @@ namespace eyemLib_Sharp
//flag = eyemLibImpl(image, tpHsvModel, out tpDstImg); //flag = eyemLibImpl(image, tpHsvModel, out tpDstImg);
EyemImage templ, search;
flag = eyemImageRead("D://批量测试图像//template.png", -1, out templ);
if (flag != 0)
{
Console.WriteLine("读图失败!");
return;
}
flag = eyemImageRead("D://批量测试图像//search1.png", -1, out search);
if (flag != 0)
{
Console.WriteLine("读图失败!");
return;
}
flag = eyemMakeShapeModel(templ, 100, 10);
flag = eyemFindShapeModel(search, 10, 0, 90, 1, 10, 100, 0.9, 0.9);
//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);
//} //}
//return; sw.Stop();
Console.WriteLine("时间花费" + sw.ElapsedMilliseconds.ToString());
eyemImageFree(ref templ);
eyemImageFree(ref search);
return;
//flag = eyemNormalize(ref image); //flag = eyemNormalize(ref image);
...@@ -1170,14 +1199,14 @@ namespace eyemLib_Sharp ...@@ -1170,14 +1199,14 @@ namespace eyemLib_Sharp
//flag = eyemShockFilter(image, 9, 1.5, 0.5, 10, out tpDstImg); //flag = eyemShockFilter(image, 9, 1.5, 0.5, 10, out tpDstImg);
flag = eyemNonLocalMeansFilter(image, 7, 21, 3.0, -1); //flag = eyemNonLocalMeansFilter(image, 7, 21, 3.0, -1);
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);
} //}
return; //return;
#region Test Blob #region Test Blob
//sw.Restart(); //sw.Restart();
......
...@@ -21,6 +21,7 @@ namespace eyemLib_Sharp ...@@ -21,6 +21,7 @@ namespace eyemLib_Sharp
foreach (var item in fileNames) foreach (var item in fileNames)
{ {
EyemLib.eyemReadImageTool(item); EyemLib.eyemReadImageTool(item);
break;
} }
EyemLib.Free(); EyemLib.Free();
Console.Write("请按任意键继续。。。"); Console.Write("请按任意键继续。。。");
......
...@@ -671,12 +671,12 @@ extern "C" { ...@@ -671,12 +671,12 @@ extern "C" {
#endif #endif
// 函数接口 // 函数接口
EXPORTS int eyemEdge1dGenMeasureRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, const char *ccSubType, int iTransition, double dSigma, double dAmpThresh, IntPtr *hObject); EXPORTS int eyemEdge1dGenMeasureRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, const char *ccSubType, int iTransition, double dSigma, double dAmpThresh, IntPtr *hObject);
EXPORTS int eyemEdge1dGenPosRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, int iTransition, double dSigma, double dAmpThresh, IntPtr *hObject); EXPORTS int eyemEdge1dGenPosRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, int iTransition, double dSigma, double dAmpThresh, IntPtr *hObject);
EXPORTS int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int iCapLength, int iCapWidth, int nCalipers, int nFilterSize, int iSearchDirec, double dAmpThreshold, const char *ccTransition, IntPtr *hObject); EXPORTS int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int iCapLength, int iCapWidth, int nCalipers, int nFilterSize, int iSearchDirec, double dAmpThreshold, const char *ccTransition, IntPtr *hObject);
EXPORTS int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iCapLength, int iCapWidth, int nCalipers, int iFilterSize, int iSearchDirec, double dAmpThreshold, const char *ccTransition, IntPtr *hObject); EXPORTS int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iCapLength, int iCapWidth, int nCalipers, int iFilterSize, int iSearchDirec, double dAmpThreshold, const char *ccTransition, IntPtr *hObject);
EXPORTS int eyemPolarTrans(EyemImage tpImage, EyemOcsDXY tpCenter, int iRadius, int iSapWidth); EXPORTS int eyemPolarTrans(EyemImage tpImage, EyemOcsDXY tpCenter, int iRadius, int iSapWidth);
EXPORTS bool eyemEdge1dGenMeasureFree(IntPtr hObject); EXPORTS bool eyemEdge1dGenMeasureFree(IntPtr hObject);
#ifdef __cplusplus #ifdef __cplusplus
} }
...@@ -691,11 +691,28 @@ extern "C" { ...@@ -691,11 +691,28 @@ extern "C" {
#endif #endif
// 函数接口 // 函数接口
EXPORTS int eyemEdgesPixel(EyemImage tpImage, double dThreshold, IntPtr *hObject, int *ipNum, EyemOcsDXY **hResults); EXPORTS int eyemEdgesPixel(EyemImage tpImage, double dThreshold, IntPtr *hObject, int *ipNum, EyemOcsDXY **hResults);
EXPORTS int eyemEdgesSubpixel(EyemImage tpImage, IntPtr *hObject, EyemOcsDXY **tpEdges, int iFilter, int iLow, int iHigh); EXPORTS int eyemEdgesSubpixel(EyemImage tpImage, IntPtr *hObject, EyemOcsDXY **tpEdges, int iFilter, int iLow, int iHigh);
EXPORTS int eyemSkeleton(EyemImage tpImage, EyemImage &skeleton); EXPORTS int eyemSkeleton(EyemImage tpImage, EyemImage &skeleton);
EXPORTS int eyemSobelAmp(EyemImage tpImage, EyemImage &ImaAmp); EXPORTS int eyemSobelAmp(EyemImage tpImage, EyemImage &ImaAmp);
EXPORTS int eyemAutoCanny(EyemImage tpImage, float dSigma = 0.33); EXPORTS int eyemAutoCanny(EyemImage tpImage, float dSigma = 0.33);
#ifdef __cplusplus
}
#endif
//////////////////////////////////////////////////////////////////////////////////////////////
// 模板匹配(eyemMatchShapes.cpp)
//
#ifdef __cplusplus
extern "C" {
#endif
// 函数接口
EXPORTS int eyemMakeShapeModel(EyemImage tpImage, double dContrast, double dMinContrast, int iApertureSize = 3, bool bL2gradient = false);
EXPORTS int eyemFindShapeModel(EyemImage tpImage, int iNumLevels, double dAngleStart, double dAngleExtent, double dAngleStep, double dMinContrast, double dContrast, double dGreediness, double dMinScore, bool bOptimization = true);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define __EYEM_MATCHSHAPES_H #define __EYEM_MATCHSHAPES_H
#include "eyemLib.h" #include "eyemLib.h"
#include <algorithm>
class shape_based_matching class shape_based_matching
{ {
...@@ -14,29 +13,35 @@ public: ...@@ -14,29 +13,35 @@ public:
shape_based_matching() {}; shape_based_matching() {};
~shape_based_matching(void); ~shape_based_matching(void);
int create_shape_model(cv::Mat tpTemplate, double maxContrast, double minContrast); int create_shape_model(cv::Mat tpTemplate, double maxContrast, double minContrast, double apertureSize = 3, bool L2gradient = false);
double find_shape_model(cv::Mat tpImage, double minScore, double greediness, cv::Point* resultPoint); double find_shape_model(cv::Mat tpImage, double minScore, double greediness, cv::Point& resultPoint);
void draw_match_shapes(cv::Mat, cv::Point, cv::Scalar, int); void draw_match_shapes(cv::Mat&, cv::Point, cv::Scalar, int);
void draw_match_shapes(cv::Mat, cv::Scalar, int);
private: private:
int noOfCordinates; struct PointInfo
cv::Point* resultPoints; {
int modelHeight; cv::Point Point;
int modelWidth; cv::Point2d Center;
double* edgeMagnitude; cv::Point2d Offset;
double* edgeDerivativeX; cv::Point2d Derivative;
double* edgeDerivativeY; double Magnitude, Direction;
cv::Point centerOfGravity;
PointInfo() {}
bool modelDefined; PointInfo(cv::Point Point, cv::Point2d Derivative, double Magnitude, double Direction) :Point(Point), Derivative(Derivative), Magnitude(Magnitude), Direction(Direction) {}
void create_double_matrix(double** &matrix, cv::Size size); void update(cv::Point2d Center)
{
void release_double_matrix(double** &matrix, int size); this->Center = Center;
this->Offset = cv::Point2d((double)this->Point.x - Center.x, (double)this->Point.y - Center.y);
}
};
cv::Size templSize;
std::vector<PointInfo> results;
}; };
shape_based_matching sbm;
#endif/* __EYEM_MATCHSHAPES_H */ #endif/* __EYEM_MATCHSHAPES_H */
\ No newline at end of file \ No newline at end of file
...@@ -7941,7 +7941,6 @@ int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, dou ...@@ -7941,7 +7941,6 @@ int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, dou
return FUNC_OK; return FUNC_OK;
} }
#include "eyemMatchShapes.h"
int eyemLibImpl(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemImage *tpDstImg) int eyemLibImpl(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemImage *tpDstImg)
{ {
CV_Assert(NULL != tpImage.vpImage); CV_Assert(NULL != tpImage.vpImage);
...@@ -7956,109 +7955,6 @@ int eyemLibImpl(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemImage *tpDstImg) ...@@ -7956,109 +7955,6 @@ int eyemLibImpl(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemImage *tpDstImg)
(tpHSVModel.dpRangeUExt[0] + tpHSVModel.dpRangeUExt[1] + tpHSVModel.dpRangeUExt[2]) != 0) { (tpHSVModel.dpRangeUExt[0] + tpHSVModel.dpRangeUExt[1] + tpHSVModel.dpRangeUExt[2]) != 0) {
std::cout << "红色" << std::endl; std::cout << "红色" << std::endl;
} }
return FUNC_OK;
//shape_based_matching GM; // object to implent geometric matching
//int lowThreshold = 10; //deafult value
//int highThreashold = 100; //deafult value
//double minScore = 0.25; //deafult value
//double greediness = 0.8; //deafult value
//double total_time = 0;
//double score = 0;
//cv::Point result;
//cv::Mat templateImage = cv::imread("D://批量测试图像//template2.png", cv::IMREAD_GRAYSCALE);
//if (templateImage.data == NULL)
//{
// return 0;
//}
////Load Search Image
//cv::Mat searchImage = cv::imread("D://批量测试图像//rings_01.png", cv::IMREAD_GRAYSCALE);
//if (searchImage.data == NULL)
//{
// return 0;
//}
//lowThreshold = atoi("10");
//highThreashold = atoi("100");//get high threshold
//minScore = atof("0.25");
//greediness = atof("0.9");
//cv::Mat grayTemplateImg; //(templateImage.size(), CV_8U, 1);
//templateImage.copyTo(grayTemplateImg);
//if (GM.create_shape_model(grayTemplateImg, lowThreshold, highThreashold) != FUNC_OK)
//{
// std::cout << "ERROR: could not create model...";
// return 0;
//}
//else {
// cv::Mat cc;
// cv::cvtColor(templateImage, cc, cv::COLOR_GRAY2BGR);
//}
////测试用833
////测试用
//cv::Mat cc;
//cv::cvtColor(templateImage, cc, cv::COLOR_GRAY2BGR);
//for (int i = 0; i < 833; i++)
//{
// //cc.ptr<cv::Vec3b>(resultPoints)[resultPoints[i].y] = cv::Vec3b(0, 0, 255);
//}
////CvSize searchSize = cvSize(searchImage->width, searchImage->height);
//cv::Mat graySearchImg; //= cvCreateImage(searchSize, IPL_DEPTH_8U, 1);
// // Convert color image to gray image.
//searchImage.copyTo(graySearchImg);
//clock_t start_time1 = clock();
//score = GM.find_shape_model(graySearchImg, minScore, greediness, &result);
//clock_t finish_time1 = clock();
//total_time = ((double)finish_time1 - (double)start_time1) / CLOCKS_PER_SEC;
//cv::Mat rgb;
//if (score > minScore) // if score is atleast 0.4
//{
// std::cout << " Found at [" << result.x << ", " << result.y << "]\n Score = " << score << "\n Searching Time = " << total_time * 1000 << "ms";
// cvtColor(searchImage, rgb, cv::COLOR_GRAY2BGR);
// GM.draw_match_shapes(rgb, result, cv::Scalar(0, 255, 0), 1);
//}
//else
// std::cout << " Object Not found";
////////////////////////////////////
//std::cout << "\n ------------------------------------\n\n";
//std::cout << "\n Press any key to exit!";
////Display result
//cv::Mat dispTemplate;
//cvtColor(templateImage, dispTemplate, cv::COLOR_GRAY2BGR);
//GM.draw_match_shapes(dispTemplate, CV_RGB(255, 0, 0), 1);
//cv::namedWindow("Template", cv::WINDOW_AUTOSIZE);
//cv::imshow("Template", dispTemplate);
//cv::namedWindow("Search Image", cv::WINDOW_AUTOSIZE);
//imshow("Search Image", rgb);
//cv::waitKey(0);
//cv::destroyWindow("Search Image");
//cv::destroyWindow("Template");
//return 0;
#pragma region resize img #pragma region resize img
//const int minInputSize = 832; //const int minInputSize = 832;
......
...@@ -387,10 +387,16 @@ int eyemNonLocalMeansFilter(EyemImage tpImage, int iCMPSize, int iSearchSize, do ...@@ -387,10 +387,16 @@ int eyemNonLocalMeansFilter(EyemImage tpImage, int iCMPSize, int iSearchSize, do
//mvs[2] = cv::imread("C:\\Users\\nzslw\\OneDrive\\程序\\VSProject\\eyemLib\\x64\\Debug\\Portada_paper_r.png", 0); //mvs[2] = cv::imread("C:\\Users\\nzslw\\OneDrive\\程序\\VSProject\\eyemLib\\x64\\Debug\\Portada_paper_r.png", 0);
cv::Mat dest; cv::Mat dest;
//cv::blur(image, dest, cv::Size(3, 3));
//cv::merge(mvs, dest); //cv::merge(mvs, dest);
nonLocalMeansFilter_SSE(image, dest, cv::Size(3, 3), cv::Size(5, 5), 21.0, -1, 0); //for (int i = 0; i < 10; i++)
//{
//nonLocalMeansFilter_SSE(image, dest, cv::Size(3, 3), cv::Size(5, 5), 10.0, -1, 0);
//image = dest;
//}
cv::imwrite("Portada_paper5.png", dest);
//cv::imwrite("Portada_paper5.png", dest);
return FUNC_OK; return FUNC_OK;
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!