Commit 697c55cc 张士柳

1 个父辈 5361861d
......@@ -924,24 +924,22 @@ namespace eyemLib_Sharp
//eyemCountObject(image, file.Replace(".png", ""), 35, 0, 100, 5, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularParts(image, file.Replace(".png", ""), 0.1, "IP_LARGE_PARTS", 100, 7, ref pNumObj, out tpDstImg);
//eyemCountObjectE(image, fileName, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, file.Replace(".png", ""), "IP_LARGE_PARTS", "D://批量测试图像2//template.png", 0.7, ref pNumObj, out tpDstImg);
eyemCountObjectIrregularPartsE(image, file.Replace(".png", ""), "IP_LARGE_PARTS", "D://批量测试图像2//template.png", 0.6, ref pNumObj, out tpDstImg);
//Bitmap bmp = eyemCvtToBitmap(tpDstImg);
//bmp.Save("D://ResOut//" + file);
//<解码测试
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, 7, 5, 128, 256, 1d);
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) + "");
Marshal.FreeCoTaskMem(tpResults[i].hText); Marshal.FreeCoTaskMem(tpResults[i].hType);
}
hObject.Dispose();
Bitmap bmp = eyemCvtToBitmap(tpDstImg);
bmp.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
////<解码测试
//int ipNum; EyemBarCode* tpResults;
//DataCodeHandle hObject;
//int iRes = eyemDetectAndDecode(image, tpRoi, file.Replace(".png", ""), "QR_CODE|DATA_MATRIX|CODE_39|CODE_128|CODE_93", out hObject, out tpResults, out ipNum, false, 5, 5, 128, 256, 1d);
//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) + "");
// Marshal.FreeCoTaskMem(tpResults[i].hText); Marshal.FreeCoTaskMem(tpResults[i].hType);
//}
//hObject.Dispose();
sw.Stop();
Console.WriteLine("耗时:" + sw.ElapsedMilliseconds.ToString() + ",结果:" + pNumObj);
......
......@@ -441,7 +441,7 @@ static void decodeMul(std::vector<WaitArea> &waitAreas, std::vector<std::string>
{
//创建解码器
Ref<Reader> reader_;
reader_.reset(Ref<Reader>(new zxing::oned::MultiFormatOneDReader(DecodeHints::CODE_128_HINT | DecodeHints::CODE_39_HINT)));
reader_.reset(Ref<Reader>(new zxing::oned::MultiFormatOneDReader(DecodeHints::CODE_128_HINT | DecodeHints::CODE_39_HINT|DecodeHints::CODE_93_HINT)));
//一维码识别
for (int ii = 0; ii < waitAreas[i].oneDMats.size(); ii++)
{
......@@ -460,7 +460,7 @@ static void decodeMul(std::vector<WaitArea> &waitAreas, std::vector<std::string>
Ref<Binarizer> binarizer(new GlobalHistogramBinarizer(source));
Ref<BinaryBitmap> bitmap(new BinaryBitmap(binarizer));
//解码
Ref<Result> result(reader_->decode(bitmap, DecodeHints::CODE_128_HINT | DecodeHints::CODE_39_HINT));
Ref<Result> result(reader_->decode(bitmap, DecodeHints::CODE_128_HINT | DecodeHints::CODE_39_HINT|DecodeHints::CODE_93_HINT));
if (!result.empty())
{
bDecode = true;
......
......@@ -3814,9 +3814,9 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, cons
//图像裁剪
//环鸿&佳世达
//src = src(cv::Range(200, src.cols - 70), cv::Range(200, src.rows - 10)).clone();
src = src(cv::Range(200, src.cols - 70), cv::Range(200, src.rows - 10)).clone();
//苏州公司&成都纬创
src = src(cv::Range(10, src.cols - 10), cv::Range(10, src.rows - 10)).clone();
//src = src(cv::Range(10, src.cols - 10), cv::Range(10, src.rows - 10)).clone();
//图像尺寸
int X = src.cols, Y = src.rows;
......@@ -3877,6 +3877,8 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, cons
cv::Mat binary, srcPrev;
cv::bitwise_not(src8U, srcPrev);
cv::Mat lbMat(Y, X, CV_8UC1, cv::Scalar(0));
//使用小料算法
if (strcmp(ccSubType, "IP_SMALL_PARTS") == 0)
{
......@@ -4072,7 +4074,7 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, cons
//用于计数
cv::Mat matchParts(Y, X, CV_8UC1, cv::Scalar(0));
double begin0 = (double)cv::getTickCount();
//double begin0 = (double)cv::getTickCount();
cv::parallel_for_(cv::Range(0, 4), [&](const cv::Range& range)->void {
for (int tpl = range.start; tpl < range.end; tpl++)
......@@ -4112,7 +4114,7 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, cons
}
});
std::cout << "剩余耗时:" << 1000 * (static_cast<double>(cv::getTickCount()) - begin0) / cv::getTickFrequency() << std::endl;
//std::cout << "剩余耗时:" << 1000 * (static_cast<double>(cv::getTickCount()) - begin0) / cv::getTickFrequency() << std::endl;
///<追踪元件算法
//标记初始区域
......@@ -4126,11 +4128,6 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, cons
}
#endif
double begin1 = (double)cv::getTickCount();
//单个元件尺寸
double sinPartSize = (double)tplWidth*(double)tplHeight;
//标签图
cv::Mat trackMat(Y, X, CV_8UC1, cv::Scalar(0));
......@@ -4158,6 +4155,9 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, cons
std::vector<cv::Point> vT = { cv::Point(points[0]),cv::Point(points[1]) ,cv::Point(points[2]) ,cv::Point(points[3]) };
cv::fillConvexPoly(trackMat, vT, cv::Scalar(255));
//标记计数
lbMat.ptr<uint8_t>(cvRound(startCenter.y))[cvRound(startCenter.x)] = 255;
struct Track {
int iLimit, iPartSize;
double dMatchDeg;
......@@ -4183,12 +4183,13 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, cons
//起始扫描半径
const double startRadius = cv::norm(startCenter - reelCenter);
//偏移角度(元件尺寸)
const double dOffset = (2 * asin(2 * trackLength / (2 * startRadius))) * 180 / PI;
//偏移角度(元件间距)
const double dOffset = (2 * asin(2 * trackLength / (2 * startRadius))) * 180. / PI;
//初始搜索角度,用以确定元件间距
const double dScanRange = 15;
//追踪元件间距(弦长,可以尽量避免因个别器件偏离导致的追踪中断)
double dChordL = .0;
for (double t = startAngle + (dOffset / 1.5); t < startAngle + (dOffset / 1.5) + dScanRange; t += dMinorStep)
for (double t = startAngle + (dOffset / 1.5); t < startAngle + (dOffset / 1.5) + dScanRange; t += dMinorStep * 2)
{
float x = float(reelCenter.x + startRadius*cos(t*c));
float y = float(reelCenter.y + startRadius*sin(t*c));
......@@ -4201,6 +4202,8 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, cons
cv::Point p2 = cv::Point(cvRound(x + trackWidth * cos(angle + CV_PI)),
cvRound(y + trackWidth * sin(angle + CV_PI)));
cv::line(cc, p1, p2, cv::Scalar(0, 255, 0, 255));
cv::LineIterator it(binary, p1, p2, 4);
for (int n = 0; n < it.count; n++, ++it)
{
......@@ -4212,6 +4215,7 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, cons
break;
}
}
if (dChordL > 0)
break;
}
......@@ -4294,20 +4298,22 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, cons
cv::Mat yyuc = srcPrev(rr);
//不同方向模板图像
//不同方向模板图像(考虑实时更新模板图像或多角度模板,这样可能速度会下降)
cv::Mat yyu = getTplMat(tplMat, 90 - (trackAngle + 180));
//计算中心位置
cv::Mat tplResult0;
cv::matchTemplate(yyuc, yyu, tplResult0, cv::TM_CCOEFF_NORMED);
//
double maxyyu; cv::Point maxyyuloc;
cv::minMaxLoc(tplResult0, NULL, &maxyyu, NULL, &maxyyuloc);
//更新元件精确位置
trackCenter = cv::Point2f(maxyyuloc.x + rr.x + cvRound((float)yyu.cols / 2.0f), \
maxyyuloc.y + rr.y + cvRound((float)yyu.rows / 2.0f));
trackCenter = cv::Point2f(float(maxyyuloc.x + rr.x + cvRound((float)yyu.cols / 2.0f)), \
float(maxyyuloc.y + rr.y + cvRound((float)yyu.rows / 2.0f)));
//cv::drawMarker(cc, trackCenter, cv::Scalar(0, 0, 255, 255));
......@@ -4323,7 +4329,7 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, cons
//更新元件区域
calcRotateRect(trackCenter, (float)trackAngle, (float)trackLength, (float)trackWidth, pts);
//判断是否结束(重新考虑终止条件)
//判断是否结束
if ((trackMat.ptr<uint8_t>(cvRound(trackCenter.y))[cvRound(trackCenter.x)] == 255) || (maxyyu < dMinScore*0.7))
{
found = false;
......@@ -4334,6 +4340,9 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, cons
std::vector<cv::Point> ptPoly = { cv::Point(pts[0]),cv::Point(pts[1]) ,cv::Point(pts[2]) ,cv::Point(pts[3]) };
cv::fillConvexPoly(trackMat, ptPoly, cv::Scalar(255));
//标记计数
lbMat.ptr<uint8_t>(cvRound(trackCenter.y))[cvRound(trackCenter.x)] = 255;
//画出元件区域
//for (int j = 0; j < 4; j++)
//{
......@@ -4416,7 +4425,7 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, cons
cv::Mat yyuc = srcPrev(rr);
//不同方向模板图像
//不同方向模板图像(考虑实时更新模板图像或多角度模板,这样可能速度会下降)
cv::Mat yyu = getTplMat(tplMat, 90 - (trackAngle + 180));
//计算中心位置
......@@ -4428,8 +4437,8 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, cons
cv::minMaxLoc(tplResult0, NULL, &maxyyu, NULL, &maxyyuloc);
//更新元件精确位置
trackCenter = cv::Point2f(maxyyuloc.x + rr.x + cvRound((float)yyu.cols / 2.0f), \
maxyyuloc.y + rr.y + cvRound((float)yyu.rows / 2.0f));
trackCenter = cv::Point2f(float(maxyyuloc.x + rr.x + cvRound((float)yyu.cols / 2.0f)), \
float(maxyyuloc.y + rr.y + cvRound((float)yyu.rows / 2.0f)));
//cv::drawMarker(cc, trackCenter, cv::Scalar(0, 0, 255, 255));
......@@ -4456,6 +4465,9 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, cons
std::vector<cv::Point> ptPoly = { cv::Point(pts[0]),cv::Point(pts[1]) ,cv::Point(pts[2]) ,cv::Point(pts[3]) };
cv::fillConvexPoly(trackMat, ptPoly, cv::Scalar(255));
//标记计数
lbMat.ptr<uint8_t>(cvRound(trackCenter.y))[cvRound(trackCenter.x)] = 255;
//画出元件区域
//for (int j = 0; j < 4; j++)
//{
......@@ -5164,8 +5176,8 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, cons
}
//计数
int numObj = cv::countNonZero(binary);
std::string text = "Reel Number = " + std::to_string(numObj);
int numObj = cv::countNonZero(lbMat);
std::string text = "Reel Number = " + std::to_string(numObj);
cv::putText(cc, text, cv::Point(35, 35), 0, 1.0, cv::Scalar(0, 140, 255, 255), 2);
std::string trayNum = std::to_string(numObj);
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!