Commit 3f8a946f 张士柳

更新内容:

EyemImage结构体新增iDepth/iChannels属性;
EyemBinBlob结构体增加iLabel属性
增加了ColorConversionCodes作为颜色转换枚举
修改eyemImageFree中的参数,改为ref EyemImage
1 个父辈 8aec1e0d
...@@ -551,6 +551,7 @@ namespace eyemLib_Sharp ...@@ -551,6 +551,7 @@ namespace eyemLib_Sharp
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct EyemBinBlob public struct EyemBinBlob
{ {
public int iLabel; // 标签
public int iArea; // 面积 public int iArea; // 面积
public double dCenterX; // 重心x坐标 public double dCenterX; // 重心x坐标
public double dCenterY; // 重心y坐标 public double dCenterY; // 重心y坐标
...@@ -636,7 +637,7 @@ namespace eyemLib_Sharp ...@@ -636,7 +637,7 @@ namespace eyemLib_Sharp
private static extern int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpThresholdImg, int iOffset, int iLightDark, out EyemImage tpDstImg); private static extern int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpThresholdImg, int iOffset, int iLightDark, out EyemImage tpDstImg);
//二值Blob分析 //二值Blob分析
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBinBlob(EyemImage tpImage, out BlobHandle hObject, int iAreaThrs, out EyemImage tpDstImage, out EyemChainCode* tpContours, out EyemBinBlob* tpResult, out int ipNum); private static extern int eyemBinBlob(EyemImage tpImage, out BlobHandle hObject, int iAreaThrs, out EyemBinBlob* tpResult, out int ipNum, out EyemImage tpDstImage);
//释放Blob资源 //释放Blob资源
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern bool eyemBinFree(IntPtr hObject); private static extern bool eyemBinFree(IntPtr hObject);
...@@ -703,6 +704,9 @@ namespace eyemLib_Sharp ...@@ -703,6 +704,9 @@ namespace eyemLib_Sharp
//释放工具所使用句柄 //释放工具所使用句柄
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern bool eyemDetectAndDecodeFree(IntPtr hObject); private static extern bool eyemDetectAndDecodeFree(IntPtr hObject);
//背景跟踪
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemTrackFeature(EyemImage tpPrevImg, EyemImage tpNextImg);
#endregion #endregion
public static void eyemReadImageTool(string fileName) public static void eyemReadImageTool(string fileName)
...@@ -721,6 +725,8 @@ namespace eyemLib_Sharp ...@@ -721,6 +725,8 @@ namespace eyemLib_Sharp
return; return;
} }
//flag = eyemImageMalloc(image.iWidth, image.iHeight, 1, "uint16_t", out image1); //flag = eyemImageMalloc(image.iWidth, image.iHeight, 1, "uint16_t", out image1);
//flag = eyemImageMalloc(image.iWidth, image.iHeight, 1, "int8_t", out image2); //flag = eyemImageMalloc(image.iWidth, image.iHeight, 1, "int8_t", out image2);
...@@ -739,11 +745,10 @@ namespace eyemLib_Sharp ...@@ -739,11 +745,10 @@ namespace eyemLib_Sharp
//int ipNum; //int ipNum;
//BlobHandle hObject; //BlobHandle hObject;
//EyemBinBlob* eyemBlob; //EyemBinBlob* eyemBlob;
//EyemChainCode* eyemContours; //eyemBinBlob(image, out hObject, 100, out eyemBlob, out ipNum, out tpDstImg);
//eyemBinBlob(ucpImage, out hObject, 100, out tpDstImg, out eyemContours, out eyemBlob, out ipNum);
//for (int i = 0; i < ipNum; i++) //for (int i = 0; i < ipNum; i++)
//{ //{
// tpResult.Add(eyemBlob[i]); // //tpResult.Add(eyemBlob[i]);
//} //}
//hObject.Dispose(); //hObject.Dispose();
#endregion #endregion
...@@ -902,6 +907,32 @@ namespace eyemLib_Sharp ...@@ -902,6 +907,32 @@ namespace eyemLib_Sharp
eyemImageFree(ref image); eyemImageFree(ref image);
} }
public static void eyemTest2(string[] fileNames)
{
EyemImage imageRef = new EyemImage();
EyemImage imageNext = new EyemImage();
eyemTrackFeature(imageRef, imageNext);
////读取参考图像
//int iRet = eyemImageRead(fileNames[0], -1, out imageRef);
//for (int i = 1; i < fileNames.Length; i++)
//{
// EyemImage imageNext = new EyemImage();
// iRet = eyemImageRead(fileNames[i], -1, out imageNext);
// if (iRet != 0)
// {
// Console.WriteLine("读图失败!");
// return;
// }
// eyemTrackFeature(imageRef, imageNext);
// eyemImageFree(ref imageNext);
//}
//eyemImageFree(ref imageRef);
}
public static void eyemTest(string[] fileNames) public static void eyemTest(string[] fileNames)
{ {
int iRet = 0; int iRet = 0;
......
...@@ -21,13 +21,20 @@ namespace eyemLib_Sharp ...@@ -21,13 +21,20 @@ namespace eyemLib_Sharp
// }); // });
// Console.Write("请按任意键继续。。。"); // Console.Write("请按任意键继续。。。");
//} //}
EyemLib.eyemTest2(fileNames);
for (int i = 0; i < 5000; i++) //foreach (var item in fileNames)
{ //{
EyemLib.eyemTest(fileNames); // //EyemLib.eyemReadImageTool(item);
//EyemLib.eyemReadImageTool(fileName); //}
Thread.Sleep(2);
}
//for (int i = 0; i < 5000; i++)
//{
// //EyemLib.eyemTest(fileNames);
// //EyemLib.eyemReadImageTool(fileNames);
// //Thread.Sleep(2);
//}
Console.Write("请按任意键继续。。。"); Console.Write("请按任意键继续。。。");
Console.ReadKey(); Console.ReadKey();
} }
......
...@@ -51,7 +51,6 @@ static cv::Mat getQRRegion(cv::Mat src, cv::RotatedRect rect, double angle) ...@@ -51,7 +51,6 @@ static cv::Mat getQRRegion(cv::Mat src, cv::RotatedRect rect, double angle)
return image(RoiRect); return image(RoiRect);
} }
static void split(const std::string &cStrText, const std::string &cStrDelim, std::vector<std::string> &vStrs) static void split(const std::string &cStrText, const std::string &cStrDelim, std::vector<std::string> &vStrs)
{ {
char *cpStr = new char[strlen(cStrText.c_str()) + 1]; char *cpStr = new char[strlen(cStrText.c_str()) + 1];
...@@ -68,7 +67,6 @@ static void split(const std::string &cStrText, const std::string &cStrDelim, std ...@@ -68,7 +67,6 @@ static void split(const std::string &cStrText, const std::string &cStrDelim, std
cpStr = NULL; cpStr = NULL;
} }
static void filterByApriltag(cv::Mat &binary, cv::Mat &labels, std::vector<tMap> &vPts, std::vector<uchar> &colors, int nccomps, double dToleErr = 0.5) static void filterByApriltag(cv::Mat &binary, cv::Mat &labels, std::vector<tMap> &vPts, std::vector<uchar> &colors, int nccomps, double dToleErr = 0.5)
{ {
//图像尺寸 //图像尺寸
...@@ -259,14 +257,12 @@ static void filterByApriltag(cv::Mat &binary, cv::Mat &labels, std::vector<tMap> ...@@ -259,14 +257,12 @@ static void filterByApriltag(cv::Mat &binary, cv::Mat &labels, std::vector<tMap>
}); });
} }
static inline bool isContainsTwoDCode() static inline bool isContainsTwoDCode()
{ {
return false; return false;
} }
static double getThreshVal_Otsu_8u(const cv::Mat& _src) static double getThreshVal_Otsu_8u(const cv::Mat& _src)
{ {
cv::Size size = _src.size(); cv::Size size = _src.size();
...@@ -343,7 +339,6 @@ static double getThreshVal_Otsu_8u(const cv::Mat& _src) ...@@ -343,7 +339,6 @@ static double getThreshVal_Otsu_8u(const cv::Mat& _src)
return max_val; return max_val;
} }
static void decodeMul(std::vector<WaitArea> &waitAreas, std::vector<std::string> &hints, cv::Mat &showMat, std::vector<DecodeResult> &decodeResults, int iBlockSize, const int iRangeC, double dMinorStep) static void decodeMul(std::vector<WaitArea> &waitAreas, std::vector<std::string> &hints, cv::Mat &showMat, std::vector<DecodeResult> &decodeResults, int iBlockSize, const int iRangeC, double dMinorStep)
{ {
//进入线程锁 //进入线程锁
...@@ -569,7 +564,6 @@ static void decodeMul(std::vector<WaitArea> &waitAreas, std::vector<std::string> ...@@ -569,7 +564,6 @@ static void decodeMul(std::vector<WaitArea> &waitAreas, std::vector<std::string>
mtx.unlock(); mtx.unlock();
} }
static int calcHist(cv::Mat src) static int calcHist(cv::Mat src)
{ {
const int histSize = 256; const int histSize = 256;
...@@ -584,7 +578,6 @@ static int calcHist(cv::Mat src) ...@@ -584,7 +578,6 @@ static int calcHist(cv::Mat src)
return maxIdx[0]; return maxIdx[0];
} }
int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, const char *ccFileName, const char *ccCodeType, IntPtr *hObject, EyemBarCode **hResults, int *ipNum, bool bUseNiBlack, int iBlockSize, const int iRangeC, int iSymbolMin, int iSymbolMax, double dScaleUpAndDown, double dToleErr, double dMinorStep) int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, const char *ccFileName, const char *ccCodeType, IntPtr *hObject, EyemBarCode **hResults, int *ipNum, bool bUseNiBlack, int iBlockSize, const int iRangeC, int iSymbolMin, int iSymbolMax, double dScaleUpAndDown, double dToleErr, double dMinorStep)
{ {
cv::Mat src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage); cv::Mat src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage);
...@@ -1503,7 +1496,6 @@ int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, const char *ccFileNam ...@@ -1503,7 +1496,6 @@ int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, const char *ccFileNam
return FUNC_OK; return FUNC_OK;
} }
int eyemCalcDetectParameter(EyemImage tpImage, EyemRect tpRoi, const char *ccFileName, bool bTrainOneD, int iBlockSize, int *ipNum, int *iSymbolMin, int *iSymbolMax) int eyemCalcDetectParameter(EyemImage tpImage, EyemRect tpRoi, const char *ccFileName, bool bTrainOneD, int iBlockSize, int *ipNum, int *iSymbolMin, int *iSymbolMax)
{ {
cv::Mat src = cv::Mat(tpImage.iHeight, tpImage.iWidth, tpImage.iDepth, tpImage.vpImage); cv::Mat src = cv::Mat(tpImage.iHeight, tpImage.iWidth, tpImage.iDepth, tpImage.vpImage);
...@@ -1791,7 +1783,6 @@ int eyemCalcDetectParameter(EyemImage tpImage, EyemRect tpRoi, const char *ccFil ...@@ -1791,7 +1783,6 @@ int eyemCalcDetectParameter(EyemImage tpImage, EyemRect tpRoi, const char *ccFil
return FUNC_OK; return FUNC_OK;
} }
bool eyemDetectAndDecodeFree(IntPtr hObject) bool eyemDetectAndDecodeFree(IntPtr hObject)
{ {
std::vector<EyemBarCode> *tpResults = reinterpret_cast<std::vector<EyemBarCode>*>(hObject); std::vector<EyemBarCode> *tpResults = reinterpret_cast<std::vector<EyemBarCode>*>(hObject);
......
#include "eyemGeneric.h" #include "eyemGeneric.h"
int eyemImageRead(const char *filename, int iFlag, EyemImage *tpImage) int eyemImageRead(const char *fileName, int iFlag, EyemImage *tpImage)
{ {
cv::Mat _src = cv::imread(filename, iFlag); cv::Mat _src = cv::imread(fileName, iFlag);
if (_src.empty()) if (_src.empty())
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
...@@ -78,6 +78,35 @@ int eyemImageRead(const char *filename, int iFlag, EyemImage *tpImage) ...@@ -78,6 +78,35 @@ int eyemImageRead(const char *filename, int iFlag, EyemImage *tpImage)
return FUNC_OK; return FUNC_OK;
} }
int eyemVideoCapture(const char *fileName, IntPtr *hObject, EyemImage **tpImages, int *ipNum)
{
cv::VideoCapture cap;
cap.open(fileName);
if (!cap.isOpened())
return FUNC_CANNOT_CALC;
int totalFrmNum = cap.get(cv::CAP_PROP_FRAME_COUNT);
std::vector<cv::Mat> *pFrames = new std::vector<cv::Mat>();
cv::Mat nextImg;
while (true)
{
cap >> nextImg;
if (nextImg.empty())
break;
pFrames->push_back(nextImg);
}
//*tpImages = pFrames->data();
//*ipNum = static_cast<int>(pFrames->size());
//*hObject = dynamic_cast<IntPtr>();
return FUNC_OK;
}
int eyemImageMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType, EyemImage *tpImage) int eyemImageMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType, EyemImage *tpImage)
{ {
//图像信息 //图像信息
...@@ -768,4 +797,12 @@ void eyemImageFree(EyemImage &tpImage) ...@@ -768,4 +797,12 @@ void eyemImageFree(EyemImage &tpImage)
tpImage.iWidth = tpImage.iHeight = tpImage.iDepth = tpImage.iChannels = 0; tpImage.iWidth = tpImage.iHeight = tpImage.iDepth = tpImage.iChannels = 0;
free(tpImage.vpImage); free(tpImage.vpImage);
tpImage.vpImage = NULL; tpImage.vpImage = NULL;
}
int eyemVideoCaptureFree(IntPtr hObject)
{
std::vector<cv::Mat> *tpImages = reinterpret_cast<std::vector<cv::Mat>*>(hObject);
delete tpImages;
tpImages = NULL;
return true;
} }
\ No newline at end of file \ No newline at end of file
...@@ -581,6 +581,7 @@ enum ...@@ -581,6 +581,7 @@ enum
// Blob 分析结果 // Blob 分析结果
typedef struct { typedef struct {
int iLabel; // 标签
int iArea; // 面积 int iArea; // 面积
double dCenterX; // 重心x坐标 double dCenterX; // 重心x坐标
double dCenterY; // 重心y坐标 double dCenterY; // 重心y坐标
...@@ -610,6 +611,10 @@ extern "C" { ...@@ -610,6 +611,10 @@ extern "C" {
EXPORTS int eyemBinErosion(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg); EXPORTS int eyemBinErosion(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg);
EXPORTS int eyemBinOpening(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg); EXPORTS int eyemBinOpening(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg);
EXPORTS int eyemBinClosing(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg); EXPORTS int eyemBinClosing(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg);
EXPORTS int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob **tpResult, int *ipNum, EyemImage *tpDstImg);
EXPORTS int eyemBinBlobFilterByArea(IntPtr hObject, int iMinArea, int iMaxArea);
EXPORTS int eyemBinBlobFilterByLabel(IntPtr hObject, int iLabel);
EXPORTS int eyemBinBlobRender(EyemImage tpImage, IntPtr hObject, EyemImage *tpDstImg);
EXPORTS bool eyemBinFree(IntPtr hObject); EXPORTS bool eyemBinFree(IntPtr hObject);
#ifdef __cplusplus #ifdef __cplusplus
...@@ -818,6 +823,7 @@ extern "C" { ...@@ -818,6 +823,7 @@ extern "C" {
EXPORTS bool eyemDetectAndDecodeFree(IntPtr hObject); EXPORTS bool eyemDetectAndDecodeFree(IntPtr hObject);
EXPORTS int eyemCountObject(EyemImage tpImage, const char *fileName, double dOffset, int iMinArea, int iMaxArea, int iWinSize, LPSTR *lpszNumObj, EyemImage *tpDstImg); EXPORTS int eyemCountObject(EyemImage tpImage, const char *fileName, double dOffset, int iMinArea, int iMaxArea, int iWinSize, LPSTR *lpszNumObj, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectIrregularParts(EyemImage tpImage, const char *fileName, double dOffset, const char * ccSubType, int iMaxArea, int iWinSize, LPSTR *lpszNumObj, EyemImage *tpDstImg); EXPORTS int eyemCountObjectIrregularParts(EyemImage tpImage, const char *fileName, double dOffset, const char * ccSubType, int iMaxArea, int iWinSize, LPSTR *lpszNumObj, EyemImage *tpDstImg);
EXPORTS int eyemTrackFeature(EyemImage tpPrevImg, EyemImage tpNextImg);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -2733,4 +2733,69 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, const char *fileName, doubl ...@@ -2733,4 +2733,69 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, const char *fileName, doubl
return FUNC_OK; return FUNC_OK;
} }
int eyemTrackFeature(EyemImage tpRefImg, EyemImage tpNextImg)
{
//cv::Mat refImg(tpRefImg.iHeight, tpRefImg.iWidth,
// MAKETYPE(tpRefImg.iDepth, tpRefImg.iChannels), tpRefImg.vpImage);
//cv::Mat nextImg(tpNextImg.iHeight, tpNextImg.iWidth,
// MAKETYPE(tpNextImg.iDepth, tpNextImg.iChannels), tpNextImg.vpImage);
cv::VideoCapture cap;
cap.open("D:\\插件完成检测\\视频\\cap5.mp4");
if (!cap.isOpened())
return FUNC_CANNOT_CALC;
int totalFrmNum = cap.get(cv::CAP_PROP_FRAME_COUNT);
//cv::namedWindow("eyemLib", cv::WINDOW_AUTOSIZE);
cv::Mat refImg, nextImg;
cap >> refImg;
cv::cvtColor(refImg, refImg, cv::COLOR_BGR2GRAY);
int nFrmNum = 0;
do
{
clock_t begin = clock();
cap >> nextImg;
if (nextImg.empty())
break;
cv::cvtColor(nextImg, nextImg, cv::COLOR_BGR2GRAY);
nFrmNum++;
cv::Mat dst;
cv::absdiff(nextImg, refImg, dst);
cv::Mat binary;
cv::threshold(dst, binary, 35, 255, cv::THRESH_BINARY);
cv::Mat labels, stats, centroids;
int nccomps = cv::connectedComponentsWithStats(binary, labels, stats, centroids);
if (nFrmNum == 60)
break;
std::cout << "TimeCost:" << ((double)clock() - (double)begin) / CLOCKS_PER_SEC * 1000 << std::endl;
//if (!dst.empty())
//{
// cv::imshow("eyemLib", binary);
// cv::waitKey(10);
//}
} while (true);
cv::waitKey(0);
return FUNC_OK;
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!