Commit cd1e2d52 张士柳

1 个父辈 8c1dfa89
...@@ -331,6 +331,16 @@ namespace eyemLib_Sharp ...@@ -331,6 +331,16 @@ namespace eyemLib_Sharp
int iYe; // 端点(右下) y 坐标 int iYe; // 端点(右下) y 坐标
} }
[StructLayout(LayoutKind.Sequential)]
public struct EyemRect3
{
public int iXs; // 起始点(左上角) x 坐标
public int iYs; // 起始点(左上角) y 坐标
public int iWidth; // x 方向大小(宽度)
public int iHeight; // y 方向大小(高度)
public double dVar; // 某种可能会使用的值
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Orthogonal Coordinate System // Orthogonal Coordinate System
...@@ -589,6 +599,12 @@ namespace eyemLib_Sharp ...@@ -589,6 +599,12 @@ 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 eyemImageRead(string filename, int iFalgs, out EyemImage tpImage); private static extern int eyemImageRead(string filename, int iFalgs, out EyemImage tpImage);
//读取视频,支持彩色
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemVideoCapture(string filename, out VideoHandle hObject, out EyemImage* tpImages, out int ipNum);
//释放视频句柄
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern bool eyemVideoCaptureFree(IntPtr hObject);
//读取Raw格式图像,仅支持8/16位 //读取Raw格式图像,仅支持8/16位
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemImageReadRaw(string filename, int iWidth, int iHeight, int iDepth, out EyemImage tpImage); private static extern int eyemImageReadRaw(string filename, int iWidth, int iHeight, int iDepth, out EyemImage tpImage);
...@@ -704,9 +720,9 @@ namespace eyemLib_Sharp ...@@ -704,9 +720,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)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemTrackFeature(EyemImage tpPrevImg, EyemImage tpNextImg); private static extern int eyemTrackFeature(EyemImage tpRefImg, EyemImage tpNextImg, IntPtr tpArray, int iArraySize, IntPtr ipResults);
#endregion #endregion
public static void eyemReadImageTool(string fileName) public static void eyemReadImageTool(string fileName)
...@@ -893,7 +909,7 @@ namespace eyemLib_Sharp ...@@ -893,7 +909,7 @@ namespace eyemLib_Sharp
//eyemCountObjectIrregularParts(ucpImage, file.Replace(".png", ""), 0d, "IP_LONG_PARTS", 100, 5, ref pNumObj, out tpDstImg); //eyemCountObjectIrregularParts(ucpImage, file.Replace(".png", ""), 0d, "IP_LONG_PARTS", 100, 5, ref pNumObj, out tpDstImg);
//int ipNum; EyemBarCode* tpResults; //int ipNum; EyemBarCode* tpResults;
//DataCodeHandle hObject; //DataCodeHandle hObject;
//int iRes = eyemDetectAndDecode(ucpImage, tpRoi, file.Replace(".png", ""), "QR_CODE|DATA_MATRIX|CODE_39|CODE_128", out hObject, out tpResults, out ipNum, false, 11, 5, 128, 256, 1d); //int iRes = eyemDetectAndDecode(image, tpRoi, file.Replace(".png", ""), "QR_CODE|DATA_MATRIX|CODE_39|CODE_128", out hObject, out tpResults, out ipNum, false, 11, 5, 128, 256, 1d);
//for (int i = 0; i < ipNum; i++) //for (int i = 0; i < ipNum; i++)
//{ //{
// Console.WriteLine("类型:" + Marshal.PtrToStringAnsi(tpResults[i].hType) + ";坐标" + "[" + tpResults[i].iCenterX.ToString() + "," + tpResults[i].iCenterY.ToString() + "]" + ";角度:" + tpResults[i].dAngle.ToString("F4") + "," + ";内容:" + Marshal.PtrToStringAnsi(tpResults[i].hText) + ""); // Console.WriteLine("类型:" + Marshal.PtrToStringAnsi(tpResults[i].hType) + ";坐标" + "[" + tpResults[i].iCenterX.ToString() + "," + tpResults[i].iCenterY.ToString() + "]" + ";角度:" + tpResults[i].dAngle.ToString("F4") + "," + ";内容:" + Marshal.PtrToStringAnsi(tpResults[i].hText) + "");
...@@ -907,30 +923,71 @@ namespace eyemLib_Sharp ...@@ -907,30 +923,71 @@ namespace eyemLib_Sharp
eyemImageFree(ref image); eyemImageFree(ref image);
} }
public static void eyemTest2(string[] fileNames) public static void eyemTestVideoCapture(string fileName)
{ {
EyemImage imageRef = new EyemImage(); List<EyemRect3> tpRois = new List<EyemRect3>();
EyemImage imageNext = new EyemImage(); EyemRect3 roi1 = new EyemRect3();
roi1.iXs = 0; roi1.iYs = 400; roi1.iWidth = 100; roi1.iHeight = 100; roi1.dVar = 0.35;
eyemTrackFeature(imageRef, imageNext); EyemRect3 roi2 = new EyemRect3();
roi2.iXs = 101; roi2.iYs = 400; roi2.iWidth = 100; roi2.iHeight = 100; roi2.dVar = 0.35;
////读取参考图像 EyemRect3 roi3 = new EyemRect3();
//int iRet = eyemImageRead(fileNames[0], -1, out imageRef); roi3.iXs = 202; roi3.iYs = 400; roi3.iWidth = 100; roi3.iHeight = 100; roi3.dVar = 0.35;
EyemRect3 roi4 = new EyemRect3();
//for (int i = 1; i < fileNames.Length; i++) roi4.iXs = 303; roi4.iYs = 400; roi4.iWidth = 100; roi4.iHeight = 100; roi4.dVar = 0.35;
//需要监控的位置
tpRois.Add(roi1); tpRois.Add(roi2); tpRois.Add(roi3); tpRois.Add(roi4);
//转内存指针
IntPtr hGlobal = eyemStructArray2IntPtr(tpRois.ToArray());
int ipNum; EyemImage* tpImages;
VideoHandle hObject;
eyemVideoCapture(fileName, out hObject, out tpImages, out ipNum);
//信号值,用于后续处理
int[] bitSingle = new int[tpRois.Count];
//类似于实时采集的图像
for (int i = 1; i < ipNum; i++)
{
int[] iArrRes = new int[tpRois.Count];
//fixed (int* ipResults = &iArrRes[0])
//{ //{
// EyemImage imageNext = new EyemImage(); int iRet = eyemTrackFeature(tpImages[0], tpImages[i], hGlobal, tpRois.Count, Marshal.UnsafeAddrOfPinnedArrayElement(iArrRes, 0)/* new IntPtr((void*)ipResults)*/);
// iRet = eyemImageRead(fileNames[i], -1, out imageNext);
// if (iRet != 0)
// {
// Console.WriteLine("读图失败!");
// return;
// }
// eyemTrackFeature(imageRef, imageNext);
// eyemImageFree(ref imageNext);
//} //}
//eyemImageFree(ref imageRef); //过滤出有效信号(连续存在数帧以上才算,防止误触发),或者直接用iArrRes的值作为信号
toSingleFilter(iArrRes, ref bitSingle);
for (int j = 0; j < bitSingle.Length; j++)
{
//设定信号持续帧数阈值
if (bitSingle[j] > 15)
{
//检测到信号
Console.WriteLine("检测到:" + j + "处有信号");
}
}
}
//释放资源
Marshal.FreeHGlobal(hGlobal);
hObject.Dispose();
}
//
public static void toSingleFilter(int[] iArrRes, ref int[] bitSingle)
{
for (int i = 0; i < iArrRes.Length; i++)
{
bitSingle[i] += iArrRes[i];
if (bitSingle[i] >= 1)//信号起始
{
//如果有一帧没检测到就重新累计
if (iArrRes[i] == 0)
{
bitSingle[i] = 0;
}
}
}
} }
public static void eyemTest(string[] fileNames) public static void eyemTest(string[] fileNames)
...@@ -978,6 +1035,7 @@ namespace eyemLib_Sharp ...@@ -978,6 +1035,7 @@ namespace eyemLib_Sharp
eyemImageFree(ref imageDiff); eyemImageFree(ref imageDiff);
} }
#region EyemImage转换成Bitmap
public static Bitmap eyemCvtToBitmap(EyemImage tpImage) public static Bitmap eyemCvtToBitmap(EyemImage tpImage)
{ {
//统一将图像转换成8位显示 //统一将图像转换成8位显示
...@@ -1020,34 +1078,20 @@ namespace eyemLib_Sharp ...@@ -1020,34 +1078,20 @@ namespace eyemLib_Sharp
return bitmap; return bitmap;
} }
#endregion
public static void eyemOpenWindow(EyemImage tpImage) #region 结构体转内存指针
{ public static IntPtr eyemStructArray2IntPtr<T>(T[] tpArray)
}
public static void eyemDestoryWindow(EyemImage tpImage)
{
}
public static void eyemImageDisplay(EyemImage tpImage)
{
}
#region 结构转内存指针
public static IntPtr teStructArray2IntPtr(EyemOcsDXY[] tpPoints, int iLength)
{ {
if (tpPoints == null) if (tpArray == null)
throw new ArgumentNullException("cvPoint2D32f"); throw new ArgumentNullException(typeof(T).Name.ToString());
//分配结构体需要的内存 //分配结构体需要的内存,需要释放
IntPtr memory = Marshal.AllocHGlobal(checked(Marshal.SizeOf(typeof(EyemOcsDXY)) * iLength)); IntPtr hGlobal = Marshal.AllocHGlobal(checked(Marshal.SizeOf(typeof(T)) * tpArray.Length));
for (int index = 0; index < iLength; index++) for (int index = 0; index < tpArray.Length; index++)
{ {
Marshal.StructureToPtr(tpPoints[index], (IntPtr)(checked((long)memory + index * Marshal.SizeOf(typeof(EyemOcsDXY)))), false); Marshal.StructureToPtr(tpArray[index], (IntPtr)(checked((long)hGlobal + index * Marshal.SizeOf(typeof(T)))), false);
} }
return memory; return hGlobal;
} }
#endregion #endregion
...@@ -1079,6 +1123,15 @@ namespace eyemLib_Sharp ...@@ -1079,6 +1123,15 @@ namespace eyemLib_Sharp
return eyemDetectAndDecodeFree(handle); return eyemDetectAndDecodeFree(handle);
} }
} }
//释放视频句柄
public class VideoHandle : SafeHandleZeroOrMinusOneIsInvalid
{
public VideoHandle() : base(true) { }
protected override bool ReleaseHandle()
{
return eyemVideoCaptureFree(handle);
}
}
#endregion #endregion
} }
......
...@@ -21,13 +21,18 @@ namespace eyemLib_Sharp ...@@ -21,13 +21,18 @@ namespace eyemLib_Sharp
// }); // });
// Console.Write("请按任意键继续。。。"); // Console.Write("请按任意键继续。。。");
//} //}
EyemLib.eyemTest2(fileNames); //EyemLib.eyemTest2(fileNames);
//foreach (var item in fileNames) //foreach (var item in fileNames)
//{ //{
// //EyemLib.eyemReadImageTool(item); // //EyemLib.eyemReadImageTool(item);
// EyemLib.eyemReadImageTool(item);
//} //}
for (int i = 0; i < 1; i++)
{
EyemLib.eyemTestVideoCapture("D:\\插件完成检测\\视频\\cap5.mp4");
}
//for (int i = 0; i < 5000; i++) //for (int i = 0; i < 5000; i++)
//{ //{
......
#include "eyemBarCode.h" #include "eyemBarCode.h"
static cv::Mat getQRRegion(cv::Mat src, cv::RotatedRect rect, double angle)
{
cv::Point center = rect.center;
// 获得左上角和右下角的角点,而且要保证不超出图片范围,用于抠图
cv::Point TopLeft = cv::Point(cvRound(center.x), cvRound(center.y)) - cv::Point(cvRound(rect.size.height / 2), cvRound(rect.size.width / 2));
TopLeft.x = TopLeft.x > src.cols ? src.cols : TopLeft.x;
TopLeft.x = TopLeft.x < 0 ? 0 : TopLeft.x;
TopLeft.y = TopLeft.y > src.rows ? src.rows : TopLeft.y;
TopLeft.y = TopLeft.y < 0 ? 0 : TopLeft.y;
int after_width, after_height;
if (TopLeft.x + rect.size.width > src.cols) {
after_width = src.cols - TopLeft.x - 1;
}
else {
after_width = cvRound(rect.size.width) - 1;
}
if (TopLeft.y + rect.size.height > src.rows) {
after_height = src.rows - TopLeft.y - 1;
}
else {
after_height = cvRound(rect.size.height) - 1;
}
// 获得二维码的位置
cv::Rect RoiRect = cv::Rect(TopLeft.x, TopLeft.y, after_width, after_height);
// dst是被旋转的图片,roi为输出图片,mask为掩模
cv::Mat mask, roi, dst;
cv::Mat image;
// 建立中介图像辅助处理图像
std::vector<cv::Point> contour;
// 获得矩形的四个点
cv::Point2f points[4];
rect.points(points);
for (int i = 0; i < 4; i++)
contour.push_back(points[i]);
std::vector<std::vector<cv::Point>> contours;
contours.push_back(contour);
// 再中介图像中画出轮廓
drawContours(mask, contours, 0, cv::Scalar(255, 255, 255), -1);
// 通过mask掩膜将src中特定位置的像素拷贝到dst中。
src.copyTo(dst, mask);
// 旋转
cv::Mat M = getRotationMatrix2D(center, angle, 1);
warpAffine(dst, image, M, src.size());
// 截图
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];
...@@ -659,7 +608,7 @@ static void decodeMul(std::vector<WaitArea> &waitAreas, std::vector<std::string> ...@@ -659,7 +608,7 @@ static void decodeMul(std::vector<WaitArea> &waitAreas, std::vector<std::string>
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, tpImage.iDepth, tpImage.vpImage); cv::Mat src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage);
if (src.empty()) { if (src.empty()) {
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
} }
......
...@@ -86,7 +86,7 @@ int eyemVideoCapture(const char *fileName, IntPtr *hObject, EyemImage **tpImages ...@@ -86,7 +86,7 @@ int eyemVideoCapture(const char *fileName, IntPtr *hObject, EyemImage **tpImages
if (!cap.isOpened()) if (!cap.isOpened())
return FUNC_CANNOT_CALC; return FUNC_CANNOT_CALC;
int totalFrmNum = cap.get(cv::CAP_PROP_FRAME_COUNT); int totalFrmNum = (int)cap.get(cv::CAP_PROP_FRAME_COUNT);
std::vector<EyemImage> *pFrames = new std::vector<EyemImage>(); std::vector<EyemImage> *pFrames = new std::vector<EyemImage>();
...@@ -865,15 +865,14 @@ void eyemImageFree(EyemImage &tpImage) ...@@ -865,15 +865,14 @@ void eyemImageFree(EyemImage &tpImage)
tpImage.vpImage = NULL; tpImage.vpImage = NULL;
} }
int eyemVideoCaptureFree(IntPtr hObject) bool eyemVideoCaptureFree(IntPtr hObject)
{ {
std::vector<EyemImage> *tpImages = reinterpret_cast<std::vector<EyemImage>*>(hObject); std::vector<EyemImage> *tpImages = reinterpret_cast<std::vector<EyemImage>*>(hObject);
for (std::vector<EyemImage>::iterator it = tpImages->begin(); it != tpImages->end(); ++it) for (std::vector<EyemImage>::iterator it = tpImages->begin(); it != tpImages->end(); ++it)
{ {
EyemImage tpImage = (*it); (*it).iWidth = (*it).iHeight = (*it).iDepth = (*it).iChannels = 0;
tpImage.iWidth = tpImage.iHeight = tpImage.iDepth = tpImage.iChannels = 0; free((*it).vpImage), (*it).vpImage = NULL;
free(tpImage.vpImage), tpImage.vpImage = NULL;
} }
delete tpImages; delete tpImages;
tpImages = NULL; tpImages = NULL;
......
...@@ -133,6 +133,15 @@ typedef struct { ...@@ -133,6 +133,15 @@ typedef struct {
int iYe; // 端点(右下) y 坐标 int iYe; // 端点(右下) y 坐标
} EyemRect2; } EyemRect2;
// 矩形定义
typedef struct {
int iXs; // 起始点(左上角) x 坐标
int iYs; // 起始点(左上角) y 坐标
int iWidth; // x 方向大小(宽度)
int iHeight; // y 方向大小(高度)
double dVar; // 可能会使用的值
} EyemRect3;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Orthogonal Coordinate System // Orthogonal Coordinate System
...@@ -786,6 +795,7 @@ extern "C" { ...@@ -786,6 +795,7 @@ extern "C" {
// 函数接口 // 函数接口
EXPORTS int eyemImageRead(const char *filename, int iFalgs, EyemImage *ucpImage); EXPORTS int eyemImageRead(const char *filename, int iFalgs, EyemImage *ucpImage);
EXPORTS int eyemVideoCapture(const char *fileName, IntPtr *hObject, EyemImage **tpImages, int *ipNum);
EXPORTS int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth, EyemImage *tpImage); EXPORTS int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth, EyemImage *tpImage);
EXPORTS int eyemImageMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType, EyemImage *tpImage); EXPORTS int eyemImageMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType, EyemImage *tpImage);
EXPORTS int eyemImageCopy(EyemImage tpSrcImg, EyemImage &tpDstImg); EXPORTS int eyemImageCopy(EyemImage tpSrcImg, EyemImage &tpDstImg);
...@@ -796,6 +806,7 @@ extern "C" { ...@@ -796,6 +806,7 @@ extern "C" {
EXPORTS int eyemImageDiv(EyemImage tpImage1, EyemImage tpImage2, EyemImage &tpDstImg); EXPORTS int eyemImageDiv(EyemImage tpImage1, EyemImage tpImage2, EyemImage &tpDstImg);
EXPORTS int eyemImageAbs(EyemImage tpImage, EyemImage &tpDstImg); EXPORTS int eyemImageAbs(EyemImage tpImage, EyemImage &tpDstImg);
EXPORTS void eyemImageFree(EyemImage &ipImage); EXPORTS void eyemImageFree(EyemImage &ipImage);
EXPORTS bool eyemVideoCaptureFree(IntPtr hObject);
#ifdef __cplusplus #ifdef __cplusplus
} }
...@@ -823,7 +834,7 @@ extern "C" { ...@@ -823,7 +834,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); EXPORTS int eyemTrackFeature(EyemImage tpPrevImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum, int *ipResults);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -2733,69 +2733,50 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, const char *fileName, doubl ...@@ -2733,69 +2733,50 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, const char *fileName, doubl
return FUNC_OK; return FUNC_OK;
} }
int eyemTrackFeature(EyemImage tpRefImg, EyemImage tpNextImg) int eyemTrackFeature(EyemImage tpRefImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum, int *ipResults)
{ {
//cv::Mat refImg(tpRefImg.iHeight, tpRefImg.iWidth, cv::Mat refImg(tpRefImg.iHeight, tpRefImg.iWidth,
// MAKETYPE(tpRefImg.iDepth, tpRefImg.iChannels), tpRefImg.vpImage); MAKETYPE(tpRefImg.iDepth, tpRefImg.iChannels), tpRefImg.vpImage);
//cv::Mat nextImg(tpNextImg.iHeight, tpNextImg.iWidth, cv::Mat nextImg(tpNextImg.iHeight, tpNextImg.iWidth,
// MAKETYPE(tpNextImg.iDepth, tpNextImg.iChannels), tpNextImg.vpImage); 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); 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); cv::cvtColor(nextImg, nextImg, cv::COLOR_BGR2GRAY);
nFrmNum++;
cv::Mat dst; cv::Mat dst;
cv::absdiff(nextImg, refImg, dst); cv::absdiff(nextImg, refImg, dst);
cv::Mat binary; cv::Mat binary;
cv::threshold(dst, binary, 35, 255, cv::THRESH_BINARY); cv::threshold(dst, binary, 25, 255, cv::THRESH_BINARY);
for (int i = 0; i < iRoiNum; i++)
{
cv::Mat labels, stats, centroids; cv::Mat labels, stats, centroids;
int nccomps = cv::connectedComponentsWithStats(binary, labels, stats, centroids); int nccomps = cv::connectedComponentsWithStats(binary(cv::Rect(tpRois[i].iXs, tpRois[i].iYs, tpRois[i].iWidth, tpRois[i].iHeight)), \
labels, stats, centroids);
//判断结果
if (((double)cv::countNonZero(labels) / (double(tpRois[i].iWidth*(double)tpRois[i].iHeight))) > tpRois[i].dVar)
{
ipResults[i] = 1;
}
else
ipResults[i] = 0;
}
return FUNC_OK;
}
if (nFrmNum == 60) int eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum)
break; {
cv::Mat refImg(tpRefImg.iHeight, tpRefImg.iWidth,
MAKETYPE(tpRefImg.iDepth, tpRefImg.iChannels), tpRefImg.vpImage);
std::cout << "TimeCost:" << ((double)clock() - (double)begin) / CLOCKS_PER_SEC * 1000 << std::endl; cv::Mat nextImg(tpNextImg.iHeight, tpNextImg.iWidth,
MAKETYPE(tpNextImg.iDepth, tpNextImg.iChannels), tpNextImg.vpImage);
//if (!dst.empty())
//{
// cv::imshow("eyemLib", binary);
// cv::waitKey(10);
//}
} while (true);
cv::waitKey(0);
return FUNC_OK; return FUNC_OK;
} }
\ No newline at end of file \ No newline at end of file
1>------ 已启动生成: 项目: eyemLib, 配置: Debug x64 ------
1> eyemSmooth.cpp
1> eyemMath.cpp
1> eyemMat.cpp
1> eyemGeneric.cpp
1> eyemFit.cpp
1> eyemEdge1d.cpp
1> eyemEdge.cpp
1> eyemClp2d.cpp
1> eyemBin.cpp
1> eyemBarCode.cpp
1> 正在生成代码...
1> 正在跳过...(未检测到相关更改)
1> eyemMisc.cpp
1> eyemLib.cpp
1> eyemCalib.cpp
1> 正在创建库 C:\Users\张士柳\OneDrive\程序\VSProject\eyemLib\x64\Debug\eyemLib.lib 和对象 C:\Users\张士柳\OneDrive\程序\VSProject\eyemLib\x64\Debug\eyemLib.exp
1> eyemLib.vcxproj -> C:\Users\张士柳\OneDrive\程序\VSProject\eyemLib\x64\Debug\eyemLib.dll
1> eyemLib.vcxproj -> C:\Users\张士柳\OneDrive\程序\VSProject\eyemLib\x64\Debug\eyemLib.pdb (Full PDB)
2>------ 已启动生成: 项目: eyemLib-Sharp, 配置: Debug Any CPU ------
2>C:\Users\张士柳\OneDrive\程序\VSProject\eyemLib\eyemLib-Sharp\EyemLib.cs(719,23,719,29): warning CS0219: The variable 'image2' is assigned but its value is never used
2>C:\Users\张士柳\OneDrive\程序\VSProject\eyemLib\eyemLib-Sharp\EyemLib.cs(894,20,894,27): warning CS0219: The variable 'pNumObj' is assigned but its value is never used
2> eyemLib-Sharp -> C:\Users\张士柳\OneDrive\程序\VSProject\eyemLib\x64\Debug\eyemLib-Sharp.exe
========== 生成: 成功 2 个,失败 0 个,最新 0 个,跳过 0 个 ==========
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!