Commit 3f8a946f 张士柳

更新内容:

EyemImage结构体新增iDepth/iChannels属性;
EyemBinBlob结构体增加iLabel属性
增加了ColorConversionCodes作为颜色转换枚举
修改eyemImageFree中的参数,改为ref EyemImage
1 个父辈 8aec1e0d
......@@ -551,6 +551,7 @@ namespace eyemLib_Sharp
[StructLayout(LayoutKind.Sequential)]
public struct EyemBinBlob
{
public int iLabel; // 标签
public int iArea; // 面积
public double dCenterX; // 重心x坐标
public double dCenterY; // 重心y坐标
......@@ -636,7 +637,7 @@ namespace eyemLib_Sharp
private static extern int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpThresholdImg, int iOffset, int iLightDark, out EyemImage tpDstImg);
//二值Blob分析
[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资源
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern bool eyemBinFree(IntPtr hObject);
......@@ -703,6 +704,9 @@ namespace eyemLib_Sharp
//释放工具所使用句柄
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
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
public static void eyemReadImageTool(string fileName)
......@@ -721,6 +725,8 @@ namespace eyemLib_Sharp
return;
}
//flag = eyemImageMalloc(image.iWidth, image.iHeight, 1, "uint16_t", out image1);
//flag = eyemImageMalloc(image.iWidth, image.iHeight, 1, "int8_t", out image2);
......@@ -739,11 +745,10 @@ namespace eyemLib_Sharp
//int ipNum;
//BlobHandle hObject;
//EyemBinBlob* eyemBlob;
//EyemChainCode* eyemContours;
//eyemBinBlob(ucpImage, out hObject, 100, out tpDstImg, out eyemContours, out eyemBlob, out ipNum);
//eyemBinBlob(image, out hObject, 100, out eyemBlob, out ipNum, out tpDstImg);
//for (int i = 0; i < ipNum; i++)
//{
// tpResult.Add(eyemBlob[i]);
// //tpResult.Add(eyemBlob[i]);
//}
//hObject.Dispose();
#endregion
......@@ -902,6 +907,32 @@ namespace eyemLib_Sharp
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)
{
int iRet = 0;
......
......@@ -21,13 +21,20 @@ namespace eyemLib_Sharp
// });
// Console.Write("请按任意键继续。。。");
//}
EyemLib.eyemTest2(fileNames);
for (int i = 0; i < 5000; i++)
{
EyemLib.eyemTest(fileNames);
//EyemLib.eyemReadImageTool(fileName);
Thread.Sleep(2);
}
//foreach (var item in fileNames)
//{
// //EyemLib.eyemReadImageTool(item);
//}
//for (int i = 0; i < 5000; i++)
//{
// //EyemLib.eyemTest(fileNames);
// //EyemLib.eyemReadImageTool(fileNames);
// //Thread.Sleep(2);
//}
Console.Write("请按任意键继续。。。");
Console.ReadKey();
}
......
......@@ -51,7 +51,6 @@ static cv::Mat getQRRegion(cv::Mat src, cv::RotatedRect rect, double angle)
return image(RoiRect);
}
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];
......@@ -68,7 +67,6 @@ static void split(const std::string &cStrText, const std::string &cStrDelim, std
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)
{
//图像尺寸
......@@ -259,14 +257,12 @@ static void filterByApriltag(cv::Mat &binary, cv::Mat &labels, std::vector<tMap>
});
}
static inline bool isContainsTwoDCode()
{
return false;
}
static double getThreshVal_Otsu_8u(const cv::Mat& _src)
{
cv::Size size = _src.size();
......@@ -343,7 +339,6 @@ static double getThreshVal_Otsu_8u(const cv::Mat& _src)
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)
{
//进入线程锁
......@@ -569,7 +564,6 @@ static void decodeMul(std::vector<WaitArea> &waitAreas, std::vector<std::string>
mtx.unlock();
}
static int calcHist(cv::Mat src)
{
const int histSize = 256;
......@@ -584,7 +578,6 @@ static int calcHist(cv::Mat src)
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)
{
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
return FUNC_OK;
}
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);
......@@ -1791,7 +1783,6 @@ int eyemCalcDetectParameter(EyemImage tpImage, EyemRect tpRoi, const char *ccFil
return FUNC_OK;
}
bool eyemDetectAndDecodeFree(IntPtr hObject)
{
std::vector<EyemBarCode> *tpResults = reinterpret_cast<std::vector<EyemBarCode>*>(hObject);
......
......@@ -1233,6 +1233,7 @@ int eyemBinAutoThreshold(EyemImage tpImage, double dSigma, int iLightDark, int b
int eyemBinDilation(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg)
{
return FUNC_OK;
}
......@@ -1251,6 +1252,410 @@ int eyemBinClosing(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDst
return FUNC_OK;
}
int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob **tpResult, int *ipNum, EyemImage *tpDstImg)
{
cv::Mat image(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage);
if (image.empty()) {
return FUNC_IMAGE_NOT_EXIST;
}
//必须是二值图像
if (image.channels() != 1)
cv::cvtColor(image, image, cv::COLOR_BGR2GRAY);
const int X = image.cols, Y = image.rows;
cv::Mat lbImage;
lbImage = cv::Mat::zeros(image.rows, image.cols, CV_32FC1);
unsigned int numPixels = 0;
CvBlobs blobs;
CvLabel label = 0;
cvReleaseBlobs(blobs);
CvLabel lastLabel = 0;
CvBlob *lastBlob = NULL;
for (int y = 0; y < Y; y++)
{
for (int x = 0; x < X; x++)
{
if (image.ptr<uint8_t>(y)[x])
{
bool labeled = lbImage.ptr<int32_t>(y)[x];
if ((!lbImage.ptr<int32_t>(y)[x]) && ((y == 0) || (!image.ptr<uint8_t>(y - 1)[x])))
{
labeled = true;
// Label contour.
label++;
CV_Assert(label != UINT_MAX);
lbImage.ptr<int32_t>(y)[x] = label;
numPixels++;
if (y > 0)
lbImage.ptr<int32_t>(y - 1)[x] = UINT_MAX;
CvBlob *blob = new CvBlob;
blob->label = label;
blob->area = 1;
blob->minx = x; blob->maxx = x;
blob->miny = y; blob->maxy = y;
blob->m10 = x; blob->m01 = y;
blob->m11 = x*y;
blob->m20 = x*x; blob->m02 = y*y;
blob->internalContours.clear();
blobs.insert(CvLabelBlob(label, blob));
lastLabel = label;
lastBlob = blob;
blob->contour.startingPoint = cv::Point(x, y);
unsigned char direction = 1;
unsigned int xx = x;
unsigned int yy = y;
bool contourEnd = false;
do
{
for (unsigned int numAttempts = 0; numAttempts < 3; numAttempts++)
{
bool found = false;
for (unsigned char i = 0; i < 3; i++)
{
int nx = xx + movesE[direction][i][0];
int ny = yy + movesE[direction][i][1];
if ((nx < X) && (nx >= 0) && (ny < Y) && (ny >= 0))
{
if (image.ptr<uint8_t>(ny)[nx])
{
found = true;
blob->contour.chainCode.push_back(movesE[direction][i][3]);
xx = nx;
yy = ny;
direction = movesE[direction][i][2];
break;
}
else
{
lbImage.ptr<int32_t>(ny)[nx] = UINT_MAX;
}
}
}
if (!found)
direction = (direction + 1) % 4;
else
{
if (lbImage.ptr<int32_t>(yy)[xx] != label)
{
lbImage.ptr<int32_t>(yy)[xx] = label;
numPixels++;
if (xx < blob->minx) blob->minx = xx;
else if (xx > blob->maxx) blob->maxx = xx;
if (yy < blob->miny) blob->miny = yy;
else if (yy > blob->maxy) blob->maxy = yy;
blob->area++;
blob->m10 += xx; blob->m01 += yy;
blob->m11 += xx*yy;
blob->m20 += xx*xx; blob->m02 += yy*yy;
}
break;
}
if (contourEnd = ((xx == x) && (yy == y) && (direction == 1)))
break;
}
} while (!contourEnd);
}
if ((y + 1 < Y) && (!image.ptr<uint8_t>(y + 1)[x]) && (!lbImage.ptr<int32_t>(y + 1)[x]))
{
labeled = true;
// Label internal contour
CvLabel l;
CvBlob *blob = NULL;
if (!lbImage.ptr<int32_t>(y)[x])
{
l = lbImage.ptr<int32_t>(y)[x - 1];
lbImage.ptr<int32_t>(y)[x] = l;
numPixels++;
if (l == lastLabel)
blob = lastBlob;
else
{
blob = blobs.find(l)->second;
lastLabel = l;
lastBlob = blob;
}
blob->area++;
blob->m10 += x; blob->m01 += y;
blob->m11 += x*y;
blob->m20 += x*x; blob->m02 += y*y;
}
else
{
l = lbImage.ptr<int32_t>(y)[x];
if (l == lastLabel)
blob = lastBlob;
else
{
blob = blobs.find(l)->second;
lastLabel = l;
lastBlob = blob;
}
}
// XXX This is not necessary (I believe). I only do this for consistency.
lbImage.ptr<int32_t>(y + 1)[x] = UINT_MAX;
CvContourChainCode *contour = new CvContourChainCode;
contour->startingPoint = cv::Point(x, y);
unsigned char direction = 3;
unsigned int xx = x;
unsigned int yy = y;
do
{
for (unsigned int numAttempts = 0; numAttempts < 3; numAttempts++)
{
bool found = false;
for (unsigned char i = 0; i < 3; i++)
{
int nx = xx + movesI[direction][i][0];
int ny = yy + movesI[direction][i][1];
if (image.ptr<uint8_t>(ny)[nx])
{
found = true;
contour->chainCode.push_back(movesI[direction][i][3]);
xx = nx;
yy = ny;
direction = movesI[direction][i][2];
break;
}
else
{
lbImage.ptr<int32_t>(ny)[nx] = UINT_MAX;
}
}
if (!found)
direction = (direction + 1) % 4;
else
{
if (!lbImage.ptr<int32_t>(yy)[xx])
{
lbImage.ptr<int32_t>(yy)[xx] = l;
numPixels++;
blob->area++;
blob->m10 += xx; blob->m01 += yy;
blob->m11 += xx*yy;
blob->m20 += xx*xx; blob->m02 += yy*yy;
}
break;
}
}
} while (!(xx == x && yy == y));
blob->internalContours.push_back(contour);
}
if (!labeled)
{
// Internal pixel
CvLabel l = lbImage.ptr<int32_t>(y)[x - 1];
lbImage.ptr<int32_t>(y)[x] = l;
numPixels++;
CvBlob *blob = NULL;
if (l == lastLabel)
blob = lastBlob;
else
{
blob = blobs.find(l)->second;
lastLabel = l;
lastBlob = blob;
}
blob->area++;
blob->m10 += x; blob->m01 += y;
blob->m11 += x*y;
blob->m20 += x*x; blob->m02 += y*y;
}
}
}
}
EyemBinBlob blob;
std::vector<EyemBinBlob> * eyemBlobs = new std::vector<EyemBinBlob>();
for (CvBlobs::iterator it = blobs.begin(); it != blobs.end(); ++it)
{
(*it).second->centroid = cv::Point2d((*it).second->m10 / (*it).second->area, (*it).second->m01 / (*it).second->area);
(*it).second->u11 = (*it).second->m11 - ((*it).second->m10*(*it).second->m01) / (*it).second->m00;
(*it).second->u20 = (*it).second->m20 - ((*it).second->m10*(*it).second->m10) / (*it).second->m00;
(*it).second->u02 = (*it).second->m02 - ((*it).second->m01*(*it).second->m01) / (*it).second->m00;
double m00_2 = (*it).second->m00 * (*it).second->m00;
(*it).second->n11 = (*it).second->u11 / m00_2;
(*it).second->n20 = (*it).second->u20 / m00_2;
(*it).second->n02 = (*it).second->u02 / m00_2;
(*it).second->p1 = (*it).second->n20 + (*it).second->n02;
double nn = (*it).second->n20 - (*it).second->n02;
(*it).second->p2 = nn*nn + 4.*((*it).second->n11*(*it).second->n11);
blob.iLabel = (*it).second->label;
blob.iArea = (*it).second->area;
blob.dCenterX = (*it).second->centroid.x;
blob.dCenterY = (*it).second->centroid.y;
blob.iXs = (*it).second->minx;
blob.iYs = (*it).second->miny;
blob.iXe = (*it).second->maxx;
blob.iYe = (*it).second->maxy;
blob.iWidth = blob.iXe - blob.iXs;
blob.iHeight = blob.iYe - blob.iYs;
blob.dTheta = .5*atan2(2.*(*it).second->u11, ((*it).second->u20 - (*it).second->u02));
eyemBlobs->push_back(blob);
}
//输出结果
*hObject = reinterpret_cast<IntPtr>(eyemBlobs);
*tpResult = eyemBlobs->data();
*ipNum = (int)eyemBlobs->size();
//释放资源
cvReleaseBlobs(blobs);
return FUNC_OK;
}
int eyemBinBlobRender(EyemImage tpImage, IntPtr hObject, EyemImage *tpDstImg)
{
std::vector<EyemBinBlob> *tpResult = reinterpret_cast<std::vector<EyemBinBlob>*>(hObject);
cv::Mat showMat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage);
//转彩色图像
if (showMat.channels() != 3)
cv::cvtColor(showMat, showMat, cv::COLOR_GRAY2BGR);
int X = tpDstImg->iWidth = tpImage.iWidth, Y = tpDstImg->iHeight = tpImage.iHeight; tpDstImg->iDepth = 0; tpDstImg->iChannels = 3;
//内存尺寸
int _Size = tpImage.iWidth*tpImage.iHeight * 3;
//输出结果
if (NULL != tpDstImg)
{
_Size *= sizeof(uint8_t);
tpDstImg->vpImage = (uint8_t *)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
const double alpha = 1.0;
Palete pal;
unsigned int colorCount = 0;
for (std::vector<EyemBinBlob>::iterator it = tpResult->begin(); it != tpResult->end(); ++it)
{
CvLabel label = (*it).iLabel;
double r, g, b;
_HSV2RGB_((double)((colorCount * 77) % 360), .5, 1., r, g, b);
colorCount++;
pal[label] = CV_RGB(r, g, b);
}
for (std::vector<EyemBinBlob>::iterator it = tpResult->begin(); it != tpResult->end(); ++it)
{
double x1, y1, x2, y2;
double lengthLine = MAX((*it).iXe - (*it).iXs, (*it).iYe - (*it).iYs) / 2.;
x1 = (*it).dCenterX - lengthLine*cos((*it).dTheta);
y1 = (*it).dCenterY - lengthLine*sin((*it).dTheta);
x2 = (*it).dCenterX + lengthLine*cos((*it).dTheta);
y2 = (*it).dCenterY + lengthLine*sin((*it).dTheta);
cv::line(showMat, cv::Point(int(x1), int(y1)), cv::Point(int(x2), int(y2)), cv::Scalar(0, 255, 0));
cv::rectangle(showMat, cv::Point((*it).iXs, (*it).iYs), cv::Point((*it).iXe, (*it).iYe), cv::Scalar(0, 0, 255));
cv::line(showMat, cv::Point(int((*it).dCenterX) - 3, int((*it).dCenterY)), cv::Point(int((*it).dCenterX) + 3, int((*it).dCenterY)), cv::Scalar(255, 0, 0));
cv::line(showMat, cv::Point(int((*it).dCenterX), int((*it).dCenterY) - 3), cv::Point(int((*it).dCenterX), int((*it).dCenterY) + 3), cv::Scalar(255, 0, 0));
}
//拷贝数据
memcpy(tpDstImg->vpImage, showMat.data, _Size);
}
cv::Mat showMat2(tpDstImg->iHeight, tpDstImg->iWidth, MAKETYPE(tpDstImg->iDepth, tpDstImg->iChannels), tpDstImg->vpImage);
return FUNC_OK;
}
int eyemBinBlobFilterByArea(IntPtr hObject, int iMinArea, int iMaxArea)
{
std::vector<EyemBinBlob> *tpResult = reinterpret_cast<std::vector<EyemBinBlob>*>(hObject);
std::vector<EyemBinBlob>::iterator it = tpResult->begin();
while (it != tpResult->end())
{
if ((*it).iArea < iMinArea || (*it).iArea > iMaxArea)
{
it = tpResult->erase(it);
}
else
++it;
}
return FUNC_OK;
}
int eyemBinBlobFilterByLabel(IntPtr hObject, int iLabel)
{
std::vector<EyemBinBlob> *tpResult = reinterpret_cast<std::vector<EyemBinBlob>*>(hObject);
std::vector<EyemBinBlob>::iterator it = tpResult->begin();
while (it != tpResult->end())
{
if ((*it).iLabel != iLabel)
{
it = tpResult->erase(it);
}
else
++it;
}
return FUNC_OK;
}
bool eyemBinFree(IntPtr hObject)
{
std::vector<EyemBinBlob> *tpResult = reinterpret_cast<std::vector<EyemBinBlob>*>(hObject);
......
#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())
return FUNC_IMAGE_NOT_EXIST;
......@@ -78,6 +78,35 @@ int eyemImageRead(const char *filename, int iFlag, EyemImage *tpImage)
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)
{
//图像信息
......@@ -768,4 +797,12 @@ void eyemImageFree(EyemImage &tpImage)
tpImage.iWidth = tpImage.iHeight = tpImage.iDepth = tpImage.iChannels = 0;
free(tpImage.vpImage);
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
......@@ -581,6 +581,7 @@ enum
// Blob 分析结果
typedef struct {
int iLabel; // 标签
int iArea; // 面积
double dCenterX; // 重心x坐标
double dCenterY; // 重心y坐标
......@@ -610,6 +611,10 @@ extern "C" {
EXPORTS int eyemBinErosion(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 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);
#ifdef __cplusplus
......@@ -818,6 +823,7 @@ extern "C" {
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 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
}
......
......@@ -2733,4 +2733,69 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, const char *fileName, doubl
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!