Commit 201558f5 张士柳

1 个父辈 8939e507
......@@ -905,7 +905,7 @@ namespace eyemLib_Sharp
string file = fileName.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries)[2];
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS",""
//eyemCountObject(ucpImage, file.Replace(".png", ""), 35, 0, 100, 5, ref pNumObj, out tpDstImg);
eyemCountObjectIrregularParts(image, file.Replace(".png", ""), "IP_LARGE_PARTS", "", 0.7, ref pNumObj, out tpDstImg);
eyemCountObjectIrregularParts(image, file.Replace(".png", ""), "IP_LARGE_PARTS", "D://批量测试图像//template.png", 0.7, ref pNumObj, out tpDstImg);
//int ipNum; EyemBarCode* tpResults;
//DataCodeHandle hObject;
//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);
......@@ -934,12 +934,13 @@ namespace eyemLib_Sharp
EyemRect3 roi4 = new EyemRect3();
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);
......@@ -950,6 +951,7 @@ namespace eyemLib_Sharp
//类似于实时采集的图像
for (int i = 1; i < ipNum; i++)
{
//存放结果
int[] iArrRes = new int[tpRois.Count];
//fixed (int* ipResults = &iArrRes[0])
//{
......
......@@ -49,6 +49,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="EyemLib.cs" />
<Compile Include="EyemLibDemo.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
......
此文件类型无法预览
......@@ -1444,27 +1444,28 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, const char *fileName, const
//使用大料算法
else if (strcmp(ccSubType, "IP_LARGE_PARTS") == 0)
{
//cv::imwrite("tplResult.png", srcPrev);
int tplWidth, tplHeight, tplDstWidth, tplDstHeight;
//用八个方向的模板进行模板匹配
cv::Mat tplResult(Y, X, CV_32F, cv::Scalar(0));
//std::vector<cv::Mat> tplResults;
const float icvDirections[9] = { -180,-135,-90 ,-45,0,45 ,90,135,180 };
for (int tpl = 0; tpl < 8; tpl++)
{
//加载模板
cv::Mat tplMat = cv::imread("D://批量测试图像//template.png", -1);
tplWidth = tplMat.cols, tplHeight = tplMat.rows;
//用八个方向的模板进行模板匹配(模板匹配的方式对于发生形变的器件效果不好)
const float icvDirections[4] = { -180,-90 ,0 ,90 };
//用以计算元件中心
const int icvDirectionDeltas[4][2] = { { tplWidth / 2,tplHeight / 2},{ tplHeight / 2,tplWidth / 2 },{ tplWidth / 2,tplHeight / 2 },{ tplHeight / 2,tplWidth / 2 } };
cv::Mat sinParts(Y, X, CV_8UC1, cv::Scalar(0));
for (int tpl = 0; tpl < 4; tpl++)
{
float t = icvDirections[tpl];
tplDstWidth = tplHeight * abs(sin(t * CV_PI / 180)) + tplWidth * abs(cos(t * CV_PI / 180));
tplDstWidth = cvRound((double)tplHeight * abs(sin(t * CV_PI / 180)) + (double)tplWidth * abs(cos(t * CV_PI / 180)));
tplDstHeight = ceil(tplWidth * abs(sin(t * CV_PI / 180)) + tplHeight * abs(cos(t * CV_PI / 180)));
tplDstHeight = cvRound(ceil((double)tplWidth * abs(sin(t * CV_PI / 180)) + (double)tplHeight * abs(cos(t * CV_PI / 180))));
cv::Mat matx23f(2, 3, CV_64F);
matx23f = cv::getRotationMatrix2D(cv::Point2f((float)tplWidth / 2.0f - 0.5f, (float)tplHeight / 2.0f - 0.5f), t, 1.0);
......@@ -1474,42 +1475,32 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, const char *fileName, const
matx23f.ptr<double>(1)[2] += (float)(tplDstHeight - tplHeight) / 2.0;
//旋转
cv::warpAffine(tplMat, tplMat, matx23f, cv::Size((int)tplDstWidth, (int)tplDstHeight), cv::INTER_CUBIC);
cv::Mat tplMatD;
cv::warpAffine(tplMat, tplMatD, matx23f, cv::Size((int)tplDstWidth, (int)tplDstHeight), cv::INTER_LINEAR, cv::BORDER_CONSTANT, cv::Scalar(0));
//模板匹配
cv::Mat tplResult0;
cv::matchTemplate(srcPrev, tplMat, tplResult0, cv::TM_CCOEFF_NORMED);
//为什么尺寸会发生比那花
//各个方向图取最大值
cv::max(tplResult0, tplResult, tplResult);
cv::matchTemplate(srcPrev, tplMatD, tplResult0, cv::TM_CCOEFF_NORMED);
//为什么尺寸会发生变化
int bottom, right;
bottom = (Y - tplResult0.rows), right = (X - tplResult0.cols);
cv::copyMakeBorder(tplResult0, tplResult0, 0, bottom, 0, right, cv::BORDER_CONSTANT, cv::Scalar(0));
//tplResults.push_back(tplResult);
//分数大于0.7才当作元件处理
cv::add(cv::Mat(tplResult0 > dMinScore) / 255, sinParts, sinParts);
}
////分数大于0.7才当作元件处理
//cv::Mat bin;
//bin = tplResult > dMinScore;
//std::vector<cv::Point> pts;
////
//sinParts += bin;
////连通域分析
//cv::Mat labels, stats, centroids;
//int nccomps2 = cv::connectedComponentsWithStats(bin, labels, stats, centroids);
//for (int i = 1; i < nccomps2; i++) {
// pts.push_back(cv::Point(cvRound(centroids.ptr<double>(i)[1]), cvRound(centroids.ptr<double>(i)[0])));
// cv::drawMarker(cc, cv::Point(cvRound(centroids.ptr<double>(i)[0]) + icvDirectionDeltas[tpl][0], cvRound(centroids.ptr<double>(i)[1]) + icvDirectionDeltas[tpl][1]), cv::Scalar(0, 255, 0, 255));
//}
//for (int t = 0; t < (int)pts.size(); t++)
//{
// cv::rectangle(cc, cv::Rect(pts[t].y, pts[t].x, templ.cols, templ.rows), cv::Scalar(0, 255, 0, 255), 1);
//}
//cv::imwrite("tplResult.png", cc);
cv::imwrite("tplResult.png", cc);
//二值化
cv::threshold(srcPrev, binary, 0, 255, cv::THRESH_BINARY | cv::THRESH_OTSU);
......@@ -2878,6 +2869,9 @@ int eyemTrackFeature(EyemImage tpRefImg, EyemImage tpNextImg, EyemRect3 *tpRois,
cv::Mat nextImg(tpNextImg.iHeight, tpNextImg.iWidth,
MAKETYPE(tpNextImg.iDepth, tpNextImg.iChannels), tpNextImg.vpImage);
if (refImg.empty() | nextImg.empty())
return FUNC_IMAGE_NOT_EXIST;
cv::cvtColor(refImg, refImg, cv::COLOR_BGR2GRAY);
cv::cvtColor(nextImg, nextImg, cv::COLOR_BGR2GRAY);
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!