From db0a968e9944974ed301796bf90e58897458c910 Mon Sep 17 00:00:00 2001 From: RCi <15089880081@163.com> Date: Thu, 13 Jun 2024 16:44:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HandleAiUi-new/algo/ALGO_Inspection.h | 82 +- HanddleAI/HandleAiUi-new/algo/simpleAlgo.h | 5 + HanddleAI/HandleAiUi-new/globalStruct.h | 4 +- .../HandleAiUi-new/halconAlgo/Inspection.h | 1158 ++++++++++++++++- .../uiModule/uiModule_switchProduct.h | 4 +- 5 files changed, 1205 insertions(+), 48 deletions(-) diff --git a/HanddleAI/HandleAiUi-new/algo/ALGO_Inspection.h b/HanddleAI/HandleAiUi-new/algo/ALGO_Inspection.h index cf712382..b22da7d8 100644 --- a/HanddleAI/HandleAiUi-new/algo/ALGO_Inspection.h +++ b/HanddleAI/HandleAiUi-new/algo/ALGO_Inspection.h @@ -5,8 +5,8 @@ #include cv::Mat pinHandleAiEvaluate(std::shared_ptr data, cv::Mat& src, handleAiModelSeg* segPtr, handleAiModelCls* clsPtr); -bool pinHalconEvaluate(cv::Rect& Result, cv::Mat& src, cv::Mat& out, int productType, int type1, int type2); -/////////////////HALCON//////////////////////// +bool pinHalconEvaluate(cv::Rect& Result, cv::Mat& src, cv::Mat& out, int productType); + //公头定位 std::vector pinDetEvaluate(cv::Mat& src, handleAiModelManager* _handleAiModelManager) { @@ -15,45 +15,40 @@ std::vector pinDetEvaluate(cv::Mat& src, handleAiModelManager* _handleAiModelManager->smalDet->Evaluate(src, result); return result; } -std::vector getpinHandleAiEvaluateRect(std::shared_ptr data, cv::Mat& src, std::vector& result) +std::vector getpinHandleAiEvaluateRect(std::shared_ptr data, cv::Mat& src, std::vector& detResult) { - //Bbox转Rect - std::vector rectVec; - for (auto detResult : result) - rectVec.push_back(cv::Rect(detResult.x - detResult.w / 2, detResult.y - detResult.h / 2, detResult.w, detResult.h)); - + std::vector result; //计算过滤条件 int totalWidth = 0; - for (auto detResult : result) + for (auto detResult : detResult) totalWidth += detResult.w; - int avgWidth= totalWidth / rectVec.size(); + int avgWidth= totalWidth / detResult.size(); - std::vector resultRectVec; cv::Point centerPos(src.rows / 2, src.cols / 2); cv::Rect targetRect(src.cols / 3, src.rows / 3, src.cols / 3, src.rows / 3); - for (auto detResult : result) + for (auto detData : detResult) { - if ((detResult.x< targetRect.x || detResult.x > targetRect.x + targetRect.width || - detResult.y < targetRect.y || detResult.y > targetRect.y + targetRect.height) == false) + if ((detData.x< targetRect.x || detData.x > targetRect.x + targetRect.width || + detData.y < targetRect.y || detData.y > targetRect.y + targetRect.height) == false) { - resultRectVec.push_back(cv::Rect(detResult.x - detResult.w / 2, detResult.y - detResult.h / 2, detResult.w, detResult.h)); + result.push_back(detData); } } - return resultRectVec; + return result; } //HALCON检测 -void halconEvaluate(std::shared_ptr data, std::vectorconnectorPos,std::vector&halconImgResult) +void halconEvaluate(std::shared_ptr data, std::vectorconnectorPos,std::vector&halconImgResult) { cv::Mat src = data->oriImgs[0]; - for (auto& rect : connectorPos) + for (auto& box : connectorPos) { cv::Mat halconMatResult; - bool halconBoolResult = pinHalconEvaluate(rect, src, halconMatResult, data->productType, 1, 1); + bool halconBoolResult = pinHalconEvaluate(BboxToRect(box), src, halconMatResult, box.classes); if (halconBoolResult == true) halconImgResult.push_back(halconMatResult);//HALCON检测结果 } } -bool pinHalconEvaluate(cv::Rect& Result, cv::Mat& src,cv::Mat& out,int productType,int type1,int type2) +bool pinHalconEvaluate(cv::Rect& Result, cv::Mat& src,cv::Mat& out,int productType) { #pragma region halcon变量定义 //测量 @@ -83,18 +78,29 @@ bool pinHalconEvaluate(cv::Rect& Result, cv::Mat& src,cv::Mat& out,int productTy //[4]-ping针偏移判NG阈值(mm); //[5]-切图存图开关 hv_in_Parameter.Append(3); - hv_in_Parameter.Append(type1); - hv_in_Parameter.Append(type2); + hv_in_Parameter.Append(1); + hv_in_Parameter.Append(1); hv_in_Parameter.Append(0.0135); hv_in_Parameter.Append(0.2); hv_in_Parameter.Append(2); hv_in_ShapePath = "./halconModel"; - - Pings_Inspection_2_Front_New(ho_in_Image, hv_in_ShapePath, hv_in_Parameter, &hv_out_Pings_X, - &hv_out_Pings_Y, &hv_out_NG_Pings_X, &hv_out_NG_Pings_Y, &hv_out_Pings_Num, - &hv_out_NG_Pings_Num, &hv_out_Flag_INS, &hv_out_Img_INS); + switch (productType) + { + case 0: + Pings_Inspection_2_Front_New(ho_in_Image, hv_in_ShapePath, hv_in_Parameter, &hv_out_Pings_X, + &hv_out_Pings_Y, &hv_out_NG_Pings_X, &hv_out_NG_Pings_Y, &hv_out_Pings_Num, + &hv_out_NG_Pings_Num, &hv_out_Flag_INS, &hv_out_Img_INS); + break; + case 2: + Pings_Inspection_1_Front_New(ho_in_Image, hv_in_ShapePath, hv_in_Parameter, &hv_out_Pings_X, + &hv_out_Pings_Y, &hv_out_NG_Pings_X, &hv_out_NG_Pings_Y, &hv_out_Pings_Num, + &hv_out_NG_Pings_Num, &hv_out_Flag_INS, &hv_out_Img_INS); + break; + default: + break; + } if(hv_out_Flag_INS.D()==1) { out = HObject2Mat(hv_out_Img_INS); @@ -115,28 +121,28 @@ bool pinHalconEvaluate(cv::Rect& Result, cv::Mat& src,cv::Mat& out,int productTy //} } //缺陷检测 -void handleAiEvaluate(std::shared_ptr data, handleAiModelManager* _handleAiModelManager, std::vectorconnectorPos, std::vector&aiImgResult) +void handleAiEvaluate(std::shared_ptr data, handleAiModelManager* _handleAiModelManager, std::vectorconnectorPos, std::vector&aiImgResult) { cv::Mat src = data->oriImgs[0]; - for (auto rect : connectorPos) + for (auto box : connectorPos) { cv::Mat handleAiMat; switch (data->productType) { case 0://AFront - handleAiMat = pinHandleAiEvaluate(data, src(rect), + handleAiMat = pinHandleAiEvaluate(data, src(BboxToRect(box)), _handleAiModelManager->largeSeg, _handleAiModelManager->largeCls); break; case 1://ABack - handleAiMat = pinHandleAiEvaluate(data, src(rect), + handleAiMat = pinHandleAiEvaluate(data, src(BboxToRect(box)), _handleAiModelManager->largeSeg, _handleAiModelManager->largeCls); break; case 2://B - handleAiMat = pinHandleAiEvaluate(data, src(rect), + handleAiMat = pinHandleAiEvaluate(data, src(BboxToRect(box)), _handleAiModelManager->midSeg, _handleAiModelManager->midCls); break; case 3://C - handleAiMat = pinHandleAiEvaluate(data, src(rect), + handleAiMat = pinHandleAiEvaluate(data, src(BboxToRect(box)), _handleAiModelManager->smallSeg, _handleAiModelManager->smallCls); break; } @@ -226,19 +232,19 @@ void ALGO_Inspection(std::shared_ptr data, handleAiModelManager* _hand } cv::Mat src = data->oriImgs[0]; //使用det获取每个公头的位置 - std::vector pinPos= pinDetEvaluate(src, _handleAiModelManager); + std::vector detResult = pinDetEvaluate(src, _handleAiModelManager); //过滤结果,获取用于handleAi/HALCON检测的rect - std::vector detRects = getpinHandleAiEvaluateRect(data,src,pinPos); + std::vector pinPos = getpinHandleAiEvaluateRect(data,src, detResult); //HANDLEAI std::vectoraiImgResult; -#if disableeHandleAiAlgo - handleAiEvaluate(data, _handleAiModelManager, detRects, aiImgResult); +#if enableHandleAiAlgo + handleAiEvaluate(data, _handleAiModelManager, pinPos, aiImgResult); #endif data->handleAiEndTime = std::chrono::high_resolution_clock::now(); //HALCON std::vectorhalconImgResult; -#if disableHalconAlgo - halconEvaluate(data, detRects, halconImgResult); +#if enableHalconAlgo + halconEvaluate(data, pinPos, halconImgResult); #endif data->halconEndTime = std::chrono::high_resolution_clock::now(); //平铺结果图 diff --git a/HanddleAI/HandleAiUi-new/algo/simpleAlgo.h b/HanddleAI/HandleAiUi-new/algo/simpleAlgo.h index 2cd6e152..6f35b268 100644 --- a/HanddleAI/HandleAiUi-new/algo/simpleAlgo.h +++ b/HanddleAI/HandleAiUi-new/algo/simpleAlgo.h @@ -1,6 +1,7 @@ #include #include #include +#include using namespace HalconCpp; struct MatchResult { cv::Rect boundingRect; @@ -639,6 +640,10 @@ static std::vector contourPlusContour(const std::vector& c return res; } +static Rect BboxToRect(handdleAI::Bbox input) +{ + return Rect(input.x - input.w / 2, input.y - input.h / 2, input.w, input.h); +} enum ngTypeEnum { OK, diff --git a/HanddleAI/HandleAiUi-new/globalStruct.h b/HanddleAI/HandleAiUi-new/globalStruct.h index 694474cd..877bd9e0 100644 --- a/HanddleAI/HandleAiUi-new/globalStruct.h +++ b/HanddleAI/HandleAiUi-new/globalStruct.h @@ -20,8 +20,8 @@ #define enableHandleAiModel 1 #define disableBackEndCheck 1 #define disableeAlgo 0 -#define disableeHalconAlgo 1 -#define disableeHandleAiAlgo 0 +#define enableHalconAlgo 1 +#define enableHandleAiAlgo 0 //绐楀彛璁剧疆 #define windowMoveFreshRate 100//绐楀彛绉诲姩姣忕鐨勫埛鏂扮巼 diff --git a/HanddleAI/HandleAiUi-new/halconAlgo/Inspection.h b/HanddleAI/HandleAiUi-new/halconAlgo/Inspection.h index b8a6ca37..458f70fd 100644 --- a/HanddleAI/HandleAiUi-new/halconAlgo/Inspection.h +++ b/HanddleAI/HandleAiUi-new/halconAlgo/Inspection.h @@ -896,6 +896,626 @@ void Pings_Inspection_1_Back (HObject ho_in_Image, HTuple hv_in_ShapePath, HTupl return; } +void Pings_Inspection_1_Front_New(HObject ho_in_Image, HTuple hv_in_ShapePath, HTuple hv_in_Parameter, + HTuple* hv_out_Pings_X, HTuple* hv_out_Pings_Y, HTuple* hv_out_NG_Pings_X, HTuple* hv_out_NG_Pings_Y, + HTuple* hv_out_Pings_Num, HTuple* hv_out_NG_Pings_Num, HTuple* hv_out_Flag, HObject* ho_IMG_INS) +{ + + // Local iconic variables + HObject ho_in_ImageDraw, ho_ROI, ho_ImagePart; + HObject ho_RegionGrid, ho_RegionGridAffineTrans, ho_RegionDilation; + HObject ho_RegionDifference, ho_ConnectedRegions, ho_ROI_0; + HObject ho_ObjectsSelected, ho_ImageReduced, ho_ImageScaled; + HObject ho_Region, ho_RegionErosion, ho_RegionIntersection; + HObject ho_RegionClosing2, ho_RegionFillUp1, ho_RegionOpening; + HObject ho_ConnectedRegions2, ho_SelectedRegions4, ho_RegionClosing; + HObject ho_RegionOpening2, ho_ConnectedRegions3, ho_SelectedRegions; + HObject ho_RegionTrans, ho_Skeleton, ho_Contours1, ho_Contours; + HObject ho_ObjectSelected, ho_MaxLengthContour, ho_Line; + HObject ho_LineIntersection, ho_RegionROI, ho_Rectangle; + HObject ho_RegionDilation1, ho_ImageReduced2, ho_ScaleInspection; + HObject ho_ObjectsSelected2, ho_ImageReduced1, ho_Region1; + HObject ho_RegionOpening1, ho_ConnectedRegions1, ho_SelectedRegions3; + HObject ho_RegionUnion, ho_RegionTrans1, ho_ContoursSplit; + HObject ho_RegionLines, ho_SelectedRegions1, ho_SortedRegions2; + HObject ho_AdegLeft, ho_AdegRight, ho_RegionLeft, ho_RegionRight; + HObject ho_RectangleOK, ho_in_ImageDraw1, ho_in_ImageDraw2; + HObject ho_in_ImageDraw3, ho_RectangleNG; + + // Local control variables + HTuple hv_Area, hv_Row0, hv_Column0, hv_Value1; + HTuple hv_Value, hv_Rect2Len1, hv_Rect2Len2, hv_ImgaeWidth; + HTuple hv_ImgaeHeight, hv__, hv_Row1, hv_Column1, hv_HomMat2DIdentity; + HTuple hv_HomMat2DTranslate, hv_HomMat2DRotate, hv_EvenTuple; + HTuple hv_OddTuple, hv_Index, hv_AbsoluteHisto, hv_RelativeHisto; + HTuple hv_Histo_0to240, hv_GraySum, hv_Index1, hv_Area1; + HTuple hv_GrayMean, hv_Number, hv_Max_Length, hv_Max_Index; + HTuple hv_i, hv_Length, hv_RowBegin, hv_ColBegin, hv_RowEnd; + HTuple hv_ColEnd, hv_Nr, hv_Nc, hv_Dist, hv_RowCenter; + HTuple hv_ColCenter, hv_Phi, hv_LineLength, hv_RowStart; + HTuple hv_ColStart, hv_RowCenter1, hv_ColCenter1, hv_Length1; + HTuple hv_Phi1, hv_Rows, hv_Columns, hv_Index2, hv_OffsetEven; + HTuple hv_Index3, hv_Offset, hv_OffsetOdd, hv_PingsRow; + HTuple hv_PingsCol, hv_PingsNumber, hv_Index4, hv_PingValue; + HTuple hv_MinDistanceLeft, hv_RowLeft1, hv_ColumnLeft1; + HTuple hv_RowLeft2, hv_ColumnLeft2, hv_MinDistanceRight; + HTuple hv_RowRight1, hv_ColumnRight1, hv_RowRight2, hv_ColumnRight2; + HTuple hv_DistanceMin, hv_WindowHandle, hv_MSecond, hv_Second; + HTuple hv_Minute, hv_Hour, hv_Day, hv_YDay, hv_Month, hv_Year; + HTuple hv_FileExists, hv_Exception; + HTupleVector hvec_out_ROI_Row(1), hvec_out_ROI_Col(1); + HTupleVector hvec_EvenFeatures(1), hvec_OddFeatures(1); + + (*hv_out_Flag) = 1; + (*hv_out_Pings_X) = HTuple(); + (*hv_out_Pings_Y) = HTuple(); + (*hv_out_NG_Pings_X) = HTuple(); + (*hv_out_NG_Pings_Y) = HTuple(); + (*hv_out_Pings_Num) = 0; + (*hv_out_NG_Pings_Num) = 0; + ho_in_ImageDraw = ho_in_Image; + + try + { + //定位 + /*Pings_ROI_Rec2(ho_in_Image, hv_in_ShapePath, hv_in_Parameter, &hvec_out_ROI_Row, + &hvec_out_ROI_Col, &(*hv_out_Flag));*/ + HTuple rows, cols; + HTuple in_imageWidth, in_imageHeight; + GetImageSize(ho_in_Image, &in_imageWidth, &in_imageHeight); + /*cols.Append(x - w); rows.Append(y - h); + cols.Append(x + w); rows.Append(y - h); + cols.Append(x + w); rows.Append(y + h); + cols.Append(x - w); rows.Append(y + h); + cols.Append(x - w); rows.Append(y - h);*/ + cols.Append(1); rows.Append(20); + cols.Append(in_imageWidth - 1); rows.Append(40); + cols.Append(in_imageWidth - 1); rows.Append(in_imageHeight - 40); + cols.Append(1); rows.Append(in_imageHeight - 40); + cols.Append(1); rows.Append(20); + hvec_out_ROI_Row[0].T() = rows; + hvec_out_ROI_Col[0].T() = cols; + + hvec_out_ROI_Row[1].T() = rows; + hvec_out_ROI_Col[1].T() = cols; + //12等分 + GenRegionPolygon(&ho_ROI, hvec_out_ROI_Row[0].T(), hvec_out_ROI_Col[0].T()); + FillUp(ho_ROI, &ho_ROI); + AreaCenter(ho_ROI, &hv_Area, &hv_Row0, &hv_Column0); + RegionFeatures(ho_ROI, ((((HTuple("row").Append("column")).Append("rect2_phi")).Append("rect2_len1")).Append("rect2_len2")), + &hv_Value1); + RegionFeatures(ho_ROI, (HTuple("width").Append("height")), &hv_Value); + if (0 != (int(HTuple(hv_Value[0]) < HTuple(hv_Value[1])))) + { + hv_Value1[2] = HTuple(hv_Value1[2]) - (HTuple(90).TupleRad()); + hv_Rect2Len1 = ((const HTuple&)hv_Value1)[3]; + hv_Rect2Len2 = ((const HTuple&)hv_Value1)[4]; + hv_Value1[3] = hv_Rect2Len2; + hv_Value1[4] = hv_Rect2Len1; + } + CropRectangle2(ho_in_Image, &ho_ImagePart, HTuple(hv_Value1[0]), HTuple(hv_Value1[1]), + HTuple(hv_Value1[2]), HTuple(hv_Value1[3]), HTuple(hv_Value1[4]), "true", + "constant"); + GetImageSize(ho_ImagePart, &hv_ImgaeWidth, &hv_ImgaeHeight); + + GenGridRegion(&ho_RegionGrid, hv_ImgaeHeight.TupleReal(), (hv_ImgaeWidth.TupleReal()) / 12, + "lines", hv_ImgaeWidth + 2, hv_ImgaeHeight + 2); + AreaCenter(ho_ImagePart, &hv__, &hv_Row1, &hv_Column1); + HomMat2dIdentity(&hv_HomMat2DIdentity); + HomMat2dTranslate(hv_HomMat2DIdentity, hv_Row0 - hv_Row1, hv_Column0 - hv_Column1, + &hv_HomMat2DTranslate); + HomMat2dRotate(hv_HomMat2DTranslate, HTuple(hv_Value1[2]), hv_Row0, hv_Column0, + &hv_HomMat2DRotate); + AffineTransRegion(ho_RegionGrid, &ho_RegionGridAffineTrans, hv_HomMat2DRotate, + "nearest_neighbor"); + DilationCircle(ho_RegionGridAffineTrans, &ho_RegionDilation, 2.5); + Difference(ho_ROI, ho_RegionDilation, &ho_RegionDifference); + Connection(ho_RegionDifference, &ho_ConnectedRegions); + SelectShape(ho_ConnectedRegions, &ho_ROI_0, "area", "and", 99999, 999999); + SortRegion(ho_ROI_0, &ho_ROI_0, "first_point", "true", "column"); + + //百分比间隔和长度(右至左) + //偶数列5大14小 + hvec_EvenFeatures = (((HTupleVector(1).Insert(0, HTupleVector((HTuple(4).Append(40))))).Insert(1, HTupleVector((HTuple(4.4).Append(15))))).Insert(2, HTupleVector((HTuple(5.6).Append(40))))); + hv_EvenTuple.Clear(); + hv_EvenTuple[0] = 1; + hv_EvenTuple[1] = 0; + hv_EvenTuple[2] = 0; + hv_EvenTuple[3] = 1; + hv_EvenTuple[4] = 0; + hv_EvenTuple[5] = 0; + hv_EvenTuple[6] = 1; + hv_EvenTuple[7] = 0; + hv_EvenTuple[8] = 0; + hv_EvenTuple[9] = 1; + hv_EvenTuple[10] = 0; + hv_EvenTuple[11] = 0; + hv_EvenTuple[12] = 1; + hv_EvenTuple[13] = 0; + hv_EvenTuple[14] = 0; + hv_EvenTuple[15] = 1; + hv_EvenTuple[16] = 0; + hv_EvenTuple[17] = 0; + hv_EvenTuple[18] = 0; + //奇数列6大15小 + hvec_OddFeatures = (((HTupleVector(1).Insert(0, HTupleVector((HTuple(1.8).Append(15))))).Insert(1, HTupleVector((HTuple(4.4).Append(15))))).Insert(2, HTupleVector((HTuple(5.6).Append(40))))); + hv_OddTuple.Clear(); + hv_OddTuple[0] = 0; + hv_OddTuple[1] = 0; + hv_OddTuple[2] = 0; + hv_OddTuple[3] = 1; + hv_OddTuple[4] = 0; + hv_OddTuple[5] = 0; + hv_OddTuple[6] = 1; + hv_OddTuple[7] = 0; + hv_OddTuple[8] = 0; + hv_OddTuple[9] = 1; + hv_OddTuple[10] = 0; + hv_OddTuple[11] = 0; + hv_OddTuple[12] = 1; + hv_OddTuple[13] = 0; + hv_OddTuple[14] = 0; + hv_OddTuple[15] = 1; + hv_OddTuple[16] = 0; + hv_OddTuple[17] = 0; + hv_OddTuple[18] = 0; + + for (hv_Index = 1; hv_Index <= 12; hv_Index += 1) + { + CopyObj(ho_ROI_0, &ho_ObjectsSelected, hv_Index, 1); + ReduceDomain(ho_in_Image, ho_ObjectsSelected, &ho_ImageReduced); + //判断Ping盒灰度情况 + GrayHisto(ho_ObjectsSelected, ho_in_Image, &hv_AbsoluteHisto, &hv_RelativeHisto); + TupleRemove(hv_AbsoluteHisto, (((((((((((((((HTuple(241).Append(242)).Append(243)).Append(244)).Append(245)).Append(246)).Append(247)).Append(248)).Append(249)).Append(250)).Append(251)).Append(252)).Append(253)).Append(254)).Append(255)).Append(256)), + &hv_Histo_0to240); + hv_GraySum = 0; + { + HTuple end_val55 = (hv_Histo_0to240.TupleLength()) - 1; + HTuple step_val55 = 1; + for (hv_Index1 = 0; hv_Index1.Continue(end_val55, step_val55); hv_Index1 += step_val55) + { + hv_GraySum = (hv_Index1 * HTuple(hv_Histo_0to240[hv_Index1])) + hv_GraySum; + } + } + AreaCenter(ho_ObjectsSelected, &hv_Area1, &hv__, &hv__); + hv_GrayMean = hv_GraySum / hv_Area1; + //归一 + ScaleImage(ho_ImageReduced, &ho_ImageScaled, (HTuple(255).TupleReal()) / hv_GrayMean, + -100); + Threshold(ho_ImageScaled, &ho_Region, 0, 35); + + ErosionCircle(ho_ObjectsSelected, &ho_RegionErosion, 5.5); + Intersection(ho_RegionErosion, ho_Region, &ho_RegionIntersection); + ClosingRectangle1(ho_RegionIntersection, &ho_RegionClosing2, 1, 50); + + FillUpShape(ho_RegionClosing2, &ho_RegionFillUp1, "area", 1, 5000); + OpeningRectangle1(ho_RegionFillUp1, &ho_RegionOpening, 1, 30); + Connection(ho_RegionOpening, &ho_ConnectedRegions2); + SelectShapeStd(ho_ConnectedRegions2, &ho_SelectedRegions4, "max_area", 70); + ClosingRectangle1(ho_SelectedRegions4, &ho_RegionClosing, 100, 10); + OpeningRectangle1(ho_RegionClosing, &ho_RegionOpening2, 1, 300); + Connection(ho_RegionOpening2, &ho_ConnectedRegions3); + SelectShapeStd(ho_ConnectedRegions3, &ho_SelectedRegions, "max_area", 70); + ShapeTrans(ho_SelectedRegions, &ho_RegionTrans, "convex"); + + Skeleton(ho_RegionTrans, &ho_Skeleton); + GenContoursSkeletonXld(ho_Skeleton, &ho_Contours1, 1, "filter"); + UnionCollinearContoursXld(ho_Contours1, &ho_Contours, 100, 1, 6, 0.2, "attr_keep"); + CountObj(ho_Contours, &hv_Number); + hv_Max_Length = 0; + hv_Max_Index = 0; + { + HTuple end_val84 = hv_Number; + HTuple step_val84 = 1; + for (hv_i = 1; hv_i.Continue(end_val84, step_val84); hv_i += step_val84) + { + SelectObj(ho_Contours, &ho_ObjectSelected, hv_i); + LengthXld(ho_ObjectSelected, &hv_Length); + if (0 != (int(hv_Max_Length < hv_Length))) + { + hv_Max_Length = hv_Length; + hv_Max_Index = hv_i; + } + } + } + SelectObj(ho_Contours, &ho_MaxLengthContour, hv_Max_Index); + FitLineContourXld(ho_MaxLengthContour, "tukey", -1, 0, 5, 2, &hv_RowBegin, + &hv_ColBegin, &hv_RowEnd, &hv_ColEnd, &hv_Nr, &hv_Nc, &hv_Dist); + LinePosition(hv_RowBegin, hv_ColBegin, hv_RowEnd, hv_ColEnd, &hv_RowCenter, + &hv_ColCenter, &hv_Length, &hv_Phi); + + hv_LineLength = 3000; + hv_RowStart = hv_RowCenter - (((hv_Phi + 1.5708).TupleCos()) * hv_LineLength); + hv_ColStart = hv_ColCenter - (((hv_Phi + 1.5708).TupleSin()) * hv_LineLength); + hv_RowEnd = hv_RowCenter - (((hv_Phi - 1.5708).TupleCos()) * hv_LineLength); + hv_ColEnd = hv_ColCenter - (((hv_Phi - 1.5708).TupleSin()) * hv_LineLength); + GenRegionLine(&ho_Line, hv_RowStart, hv_ColStart, hv_RowEnd, hv_ColEnd); + LinePosition(hv_RowStart, hv_ColStart, hv_RowEnd, hv_ColEnd, &hv_RowCenter1, + &hv_ColCenter1, &hv_Length1, &hv_Phi1); + Intersection(ho_Line, ho_ObjectsSelected, &ho_LineIntersection); + GetRegionPoints(ho_LineIntersection, &hv_Rows, &hv_Columns); + + //偶数 + if (0 != (int((hv_Index % 2) == 0))) + { + GenRectangle2(&ho_RegionROI, HTuple(hv_Rows[(((hv_Rows.TupleLength()) * HTuple(hvec_EvenFeatures[0].T()[0])) * 0.01).TupleInt()]), + HTuple(hv_Columns[(((hv_Rows.TupleLength()) * HTuple(hvec_EvenFeatures[0].T()[0])) * 0.01).TupleInt()]), + hv_Phi1 + (HTuple(90).TupleRad()), 40, HTuple(hvec_EvenFeatures[0].T()[1])); + { + HTuple end_val109 = (hv_EvenTuple.TupleLength()) - 1; + HTuple step_val109 = 1; + for (hv_Index2 = 1; hv_Index2.Continue(end_val109, step_val109); hv_Index2 += step_val109) + { + hv_OffsetEven = 0; + { + HTuple end_val111 = hv_Index2; + HTuple step_val111 = 1; + for (hv_Index3 = 0; hv_Index3.Continue(end_val111, step_val111); hv_Index3 += step_val111) + { + if (0 != (int(hv_Index3 != 0))) + { + if (0 != (int(HTuple(hv_EvenTuple[hv_Index3 - 1]) == 1))) + { + hv_Offset = ((const HTuple&)hvec_EvenFeatures[2].T())[0]; + hv_Length = ((const HTuple&)hvec_EvenFeatures[1].T())[1]; + } + else if (0 != (int(HTuple(hv_EvenTuple[hv_Index3]) == 1))) + { + hv_Offset = ((const HTuple&)hvec_EvenFeatures[2].T())[0]; + hv_Length = ((const HTuple&)hvec_EvenFeatures[2].T())[1]; + } + else + { + hv_Offset = ((const HTuple&)hvec_EvenFeatures[1].T())[0]; + hv_Length = ((const HTuple&)hvec_EvenFeatures[1].T())[1]; + } + } + else + { + hv_Offset = ((const HTuple&)hvec_EvenFeatures[0].T())[0]; + hv_Length = ((const HTuple&)hvec_EvenFeatures[0].T())[1]; + } + hv_OffsetEven += hv_Offset; + } + } + if (0 != (int(hv_Index2 != 0))) + { + if (0 != (int(HTuple(hv_EvenTuple[hv_Index2 - 1]) == 1))) + { + hv_Offset = ((const HTuple&)hvec_EvenFeatures[2].T())[0]; + hv_Length = ((const HTuple&)hvec_EvenFeatures[1].T())[1]; + } + else if (0 != (int(HTuple(hv_EvenTuple[hv_Index2]) == 1))) + { + hv_Offset = ((const HTuple&)hvec_EvenFeatures[2].T())[0]; + hv_Length = ((const HTuple&)hvec_EvenFeatures[2].T())[1]; + } + else + { + hv_Offset = ((const HTuple&)hvec_EvenFeatures[1].T())[0]; + hv_Length = ((const HTuple&)hvec_EvenFeatures[1].T())[1]; + } + } + else + { + hv_Offset = ((const HTuple&)hvec_EvenFeatures[0].T())[0]; + hv_Length = ((const HTuple&)hvec_EvenFeatures[0].T())[1]; + } + GenRectangle2(&ho_Rectangle, HTuple(hv_Rows[(((hv_Rows.TupleLength()) * hv_OffsetEven) * 0.01).TupleInt()]), + HTuple(hv_Columns[(((hv_Columns.TupleLength()) * hv_OffsetEven) * 0.01).TupleInt()]), + hv_Phi1 + (HTuple(90).TupleRad()), 40, hv_Length); + ConcatObj(ho_RegionROI, ho_Rectangle, &ho_RegionROI); + } + } + } + else + { + //奇数 + GenRectangle2(&ho_RegionROI, HTuple(hv_Rows[(((hv_Rows.TupleLength()) * HTuple(hvec_OddFeatures[0].T()[0])) * 0.01).TupleInt()]), + HTuple(hv_Columns[(((hv_Rows.TupleLength()) * HTuple(hvec_OddFeatures[0].T()[0])) * 0.01).TupleInt()]), + hv_Phi1 + (HTuple(90).TupleRad()), 40, HTuple(hvec_OddFeatures[0].T()[1])); + { + HTuple end_val150 = (hv_OddTuple.TupleLength()) - 1; + HTuple step_val150 = 1; + for (hv_Index2 = 1; hv_Index2.Continue(end_val150, step_val150); hv_Index2 += step_val150) + { + hv_OffsetOdd = 0; + { + HTuple end_val152 = hv_Index2; + HTuple step_val152 = 1; + for (hv_Index3 = 0; hv_Index3.Continue(end_val152, step_val152); hv_Index3 += step_val152) + { + if (0 != (int(hv_Index3 != 0))) + { + if (0 != (int(HTuple(hv_OddTuple[hv_Index3 - 1]) == 1))) + { + hv_Offset = ((const HTuple&)hvec_OddFeatures[2].T())[0]; + hv_Length = ((const HTuple&)hvec_OddFeatures[1].T())[1]; + } + else if (0 != (int(HTuple(hv_OddTuple[hv_Index3]) == 1))) + { + hv_Offset = ((const HTuple&)hvec_OddFeatures[2].T())[0]; + hv_Length = ((const HTuple&)hvec_OddFeatures[2].T())[1]; + } + else + { + hv_Offset = ((const HTuple&)hvec_OddFeatures[1].T())[0]; + hv_Length = ((const HTuple&)hvec_OddFeatures[1].T())[1]; + } + } + else + { + hv_Offset = ((const HTuple&)hvec_OddFeatures[0].T())[0]; + hv_Length = ((const HTuple&)hvec_OddFeatures[0].T())[1]; + } + hv_OffsetOdd += hv_Offset; + } + } + if (0 != (int(hv_Index2 != 0))) + { + if (0 != (int(HTuple(hv_OddTuple[hv_Index2 - 1]) == 1))) + { + hv_Offset = ((const HTuple&)hvec_OddFeatures[2].T())[0]; + hv_Length = ((const HTuple&)hvec_OddFeatures[1].T())[1]; + } + else if (0 != (int(HTuple(hv_OddTuple[hv_Index2]) == 1))) + { + hv_Offset = ((const HTuple&)hvec_OddFeatures[2].T())[0]; + hv_Length = ((const HTuple&)hvec_OddFeatures[2].T())[1]; + } + else + { + hv_Offset = ((const HTuple&)hvec_OddFeatures[1].T())[0]; + hv_Length = ((const HTuple&)hvec_OddFeatures[1].T())[1]; + } + } + else + { + hv_Offset = ((const HTuple&)hvec_OddFeatures[0].T())[0]; + hv_Length = ((const HTuple&)hvec_OddFeatures[0].T())[1]; + } + GenRectangle2(&ho_Rectangle, HTuple(hv_Rows[(((hv_Rows.TupleLength()) * hv_OffsetOdd) * 0.01).TupleInt()]), + HTuple(hv_Columns[(((hv_Columns.TupleLength()) * hv_OffsetOdd) * 0.01).TupleInt()]), + hv_Phi1 + (HTuple(90).TupleRad()), 40, hv_Length); + ConcatObj(ho_RegionROI, ho_Rectangle, &ho_RegionROI); + } + } + + } + + RegionFeatures(ho_RegionROI, "row", &hv_PingsRow); + RegionFeatures(ho_RegionROI, "column", &hv_PingsCol); + CountObj(ho_RegionROI, &hv_PingsNumber); + + //测试显示用 + if (0 != (int(HTuple(hv_in_Parameter[5]) == 2))) + { + PaintRegion(ho_LineIntersection, ho_in_ImageDraw, &ho_in_ImageDraw, 255, + "fill"); + } + + //检测 + DilationRectangle1(ho_LineIntersection, &ho_RegionDilation1, 120, 1); + GrayHisto(ho_RegionDilation1, ho_in_Image, &hv_AbsoluteHisto, &hv_RelativeHisto); + TupleRemove(hv_AbsoluteHisto, (((((((((((((((HTuple(241).Append(242)).Append(243)).Append(244)).Append(245)).Append(246)).Append(247)).Append(248)).Append(249)).Append(250)).Append(251)).Append(252)).Append(253)).Append(254)).Append(255)).Append(256)), + &hv_Histo_0to240); + hv_GraySum = 0; + { + HTuple end_val205 = (hv_Histo_0to240.TupleLength()) - 1; + HTuple step_val205 = 1; + for (hv_Index1 = 0; hv_Index1.Continue(end_val205, step_val205); hv_Index1 += step_val205) + { + hv_GraySum = (hv_Index1 * HTuple(hv_Histo_0to240[hv_Index1])) + hv_GraySum; + } + } + AreaCenter(ho_RegionDilation1, &hv_Area1, &hv__, &hv__); + hv_GrayMean = hv_GraySum / hv_Area1; + ReduceDomain(ho_in_Image, ho_RegionDilation1, &ho_ImageReduced2); + ScaleImage(ho_ImageReduced2, &ho_ScaleInspection, (HTuple(255).TupleReal()) / hv_GrayMean, + -120); + + { + HTuple end_val213 = hv_PingsNumber; + HTuple step_val213 = 1; + for (hv_Index4 = 1; hv_Index4.Continue(end_val213, step_val213); hv_Index4 += step_val213) + { + CopyObj(ho_RegionROI, &ho_ObjectsSelected2, hv_Index4, 1); + RegionFeatures(ho_ObjectsSelected2, ((HTuple("row").Append("column")).Append("height")), + &hv_PingValue); + ReduceDomain(ho_ScaleInspection, ho_ObjectsSelected2, &ho_ImageReduced1); + Threshold(ho_ImageReduced1, &ho_Region1, 0, 40); + if (0 != (int(HTuple(hv_PingValue[2]) > ((HTuple(hvec_OddFeatures[0].T()[1]) * 2) + 10)))) + { + OpeningRectangle1(ho_Region1, &ho_RegionOpening1, 1, 50); + Connection(ho_RegionOpening1, &ho_ConnectedRegions1); + SelectShape(ho_ConnectedRegions1, &ho_SelectedRegions3, (HTuple("area").Append("height")), + "and", (HTuple(50).Append(50)), (HTuple(99999).Append(99999))); + } + else + { + OpeningRectangle1(ho_Region1, &ho_RegionOpening1, 1, 10); + Connection(ho_RegionOpening1, &ho_ConnectedRegions1); + SelectShape(ho_ConnectedRegions1, &ho_SelectedRegions3, (HTuple("area").Append("height")), + "and", (HTuple(50).Append(25)), (HTuple(99999).Append(99999))); + } + + Union1(ho_SelectedRegions3, &ho_RegionUnion); + ShapeTrans(ho_RegionUnion, &ho_RegionTrans1, "rectangle1"); + GenContourRegionXld(ho_RegionTrans1, &ho_Contours, "border"); + + SegmentContoursXld(ho_Contours, &ho_ContoursSplit, "lines_circles", 5, 4, + 2); + FitLineContourXld(ho_ContoursSplit, "tukey", -1, 0, 5, 2, &hv_RowBegin, &hv_ColBegin, + &hv_RowEnd, &hv_ColEnd, &hv_Nr, &hv_Nc, &hv_Dist); + GenRegionLine(&ho_RegionLines, hv_RowBegin, hv_ColBegin, hv_RowEnd, hv_ColEnd); + SelectShape(ho_RegionLines, &ho_SelectedRegions1, (HTuple("width").Append("height")), + "and", (HTuple(0).Append(5)), (HTuple(15).Append(150))); + + SortRegion(ho_SelectedRegions1, &ho_SortedRegions2, "first_point", "true", + "column"); + CountObj(ho_SortedRegions2, &hv_Number); + + //未找到边缘,视为合格 + if (0 != (int(hv_Number == 0))) + { + //region_features (ObjectsSelected2, ['row','column'], Value) + //out_NG_Pings_X := [out_NG_Pings_X,PingValue[0]] + //out_NG_Pings_Y := [out_NG_Pings_Y,PingValue[1]] + //out_NG_Pings_Num := out_NG_Pings_Num + 1 + continue; + } + + CopyObj(ho_SortedRegions2, &ho_AdegLeft, 1, 1); + CopyObj(ho_SortedRegions2, &ho_AdegRight, 2, 1); + + //测试显示用 + if (0 != (int(HTuple(hv_in_Parameter[5]) == 2))) + { + PaintRegion(ho_AdegLeft, ho_in_ImageDraw, &ho_in_ImageDraw, 255, "fill"); + PaintRegion(ho_AdegRight, ho_in_ImageDraw, &ho_in_ImageDraw, 255, "fill"); + } + + //边缘异常,视为不合格 + if (0 != 0) + { + RegionFeatures(ho_ObjectsSelected2, (HTuple("row").Append("column")), &hv_Value); + (*hv_out_NG_Pings_X) = (*hv_out_NG_Pings_X).TupleConcat(HTuple(hv_PingValue[0])); + (*hv_out_NG_Pings_Y) = (*hv_out_NG_Pings_Y).TupleConcat(HTuple(hv_PingValue[1])); + (*hv_out_NG_Pings_Num) += 1; + } + else + { + + DistanceRrMin(ho_AdegLeft, ho_LineIntersection, &hv_MinDistanceLeft, &hv_RowLeft1, + &hv_ColumnLeft1, &hv_RowLeft2, &hv_ColumnLeft2); + GenRegionLine(&ho_RegionLeft, hv_RowLeft1, hv_ColumnLeft1, hv_RowLeft2, + hv_ColumnLeft2); + DistanceRrMin(ho_AdegRight, ho_LineIntersection, &hv_MinDistanceRight, + &hv_RowRight1, &hv_ColumnRight1, &hv_RowRight2, &hv_ColumnRight2); + GenRegionLine(&ho_RegionRight, hv_RowRight1, hv_ColumnRight1, hv_RowRight2, + hv_ColumnRight2); + + //测试显示用 + if (0 != (int(HTuple(hv_in_Parameter[5]) == 2))) + { + PaintRegion(ho_RegionLeft, ho_in_ImageDraw, &ho_in_ImageDraw, 255, "fill"); + PaintRegion(ho_RegionRight, ho_in_ImageDraw, &ho_in_ImageDraw, 255, "fill"); + } + + hv_DistanceMin = (((hv_MinDistanceLeft.TupleConcat(hv_MinDistanceRight)).TupleMax()).TupleReal()) - 15; + + //大小ping阈值不同 + if (0 != (int((hv_Index % 2) == 0))) + { + if (0 != (int(HTuple(hv_EvenTuple[hv_Index4 - 1]) == 1))) + { + if (0 != (int((hv_DistanceMin * HTuple(hv_in_Parameter[3])) > (HTuple(hv_in_Parameter[4]) * 1.2)))) + { + (*hv_out_NG_Pings_X) = (*hv_out_NG_Pings_X).TupleConcat(HTuple(hv_PingValue[0])); + (*hv_out_NG_Pings_Y) = (*hv_out_NG_Pings_Y).TupleConcat(HTuple(hv_PingValue[1])); + (*hv_out_NG_Pings_Num) += 1; + } + } + else + { + if (0 != (int((hv_DistanceMin * HTuple(hv_in_Parameter[3])) > HTuple(hv_in_Parameter[4])))) + { + (*hv_out_NG_Pings_X) = (*hv_out_NG_Pings_X).TupleConcat(HTuple(hv_PingValue[0])); + (*hv_out_NG_Pings_Y) = (*hv_out_NG_Pings_Y).TupleConcat(HTuple(hv_PingValue[1])); + (*hv_out_NG_Pings_Num) += 1; + } + } + + } + else if (0 != (int((hv_Index % 2) == 1))) + { + if (0 != (int(HTuple(hv_OddTuple[hv_Index4 - 1]) == 1))) + { + if (0 != (int((hv_DistanceMin * HTuple(hv_in_Parameter[3])) > (HTuple(hv_in_Parameter[4]) * 1.2)))) + { + (*hv_out_NG_Pings_X) = (*hv_out_NG_Pings_X).TupleConcat(HTuple(hv_PingValue[0])); + (*hv_out_NG_Pings_Y) = (*hv_out_NG_Pings_Y).TupleConcat(HTuple(hv_PingValue[1])); + (*hv_out_NG_Pings_Num) += 1; + } + } + else + { + if (0 != (int((hv_DistanceMin * HTuple(hv_in_Parameter[3])) > HTuple(hv_in_Parameter[4])))) + { + (*hv_out_NG_Pings_X) = (*hv_out_NG_Pings_X).TupleConcat(HTuple(hv_PingValue[0])); + (*hv_out_NG_Pings_Y) = (*hv_out_NG_Pings_Y).TupleConcat(HTuple(hv_PingValue[1])); + (*hv_out_NG_Pings_Num) += 1; + } + } + } + } + } + } + (*hv_out_Pings_X) = (*hv_out_Pings_X).TupleConcat(hv_PingsRow); + (*hv_out_Pings_Y) = (*hv_out_Pings_Y).TupleConcat(hv_PingsCol); + (*hv_out_Pings_Num) += hv_PingsNumber; + } + + //测试显示用 + if (0 != (int(HTuple(hv_in_Parameter[5]) == 2))) + { + if (HDevWindowStack::IsOpen()) + hv_WindowHandle = HDevWindowStack::GetActive(); + GenRectangle1(&ho_RectangleOK, (*hv_out_Pings_X) - 40, (*hv_out_Pings_Y) - 40, + (*hv_out_Pings_X) + 40, (*hv_out_Pings_Y) + 40); + PaintRegion(ho_RectangleOK, ho_in_ImageDraw, &ho_in_ImageDraw1, 0, "margin"); + PaintRegion(ho_RectangleOK, ho_in_ImageDraw, &ho_in_ImageDraw2, 255, "margin"); + PaintRegion(ho_RectangleOK, ho_in_ImageDraw, &ho_in_ImageDraw3, 0, "margin"); + + if (0 != (int(((*hv_out_NG_Pings_X).TupleLength()) != 0))) + { + GenRectangle1(&ho_RectangleNG, (*hv_out_NG_Pings_X) - 40, (*hv_out_NG_Pings_Y) - 40, + (*hv_out_NG_Pings_X) + 40, (*hv_out_NG_Pings_Y) + 40); + PaintRegion(ho_RectangleNG, ho_in_ImageDraw1, &ho_in_ImageDraw1, 255, "margin"); + PaintRegion(ho_RectangleNG, ho_in_ImageDraw2, &ho_in_ImageDraw2, 0, "margin"); + PaintRegion(ho_RectangleNG, ho_in_ImageDraw3, &ho_in_ImageDraw3, 0, "margin"); + } + + Compose3(ho_in_ImageDraw1, ho_in_ImageDraw2, ho_in_ImageDraw3, &ho_in_ImageDraw + ); + + GetImageTime(ho_in_ImageDraw, &hv_MSecond, &hv_Second, &hv_Minute, &hv_Hour, + &hv_Day, &hv_YDay, &hv_Month, &hv_Year); + FileExists((hv_in_ShapePath + "/Result") + HTuple(hv_in_Parameter[0]), &hv_FileExists); + if (0 != (int(hv_FileExists != 1))) + { + MakeDir((hv_in_ShapePath + "/Result") + HTuple(hv_in_Parameter[0])); + } + WriteImage(ho_in_ImageDraw, "bmp", 0, (((((((hv_in_ShapePath + "/Result") + HTuple(hv_in_Parameter[0])) + "/") + hv_Day) + hv_Hour) + hv_Minute) + hv_Second) + hv_MSecond); + if (HDevWindowStack::IsOpen()) + DispObj(ho_in_ImageDraw, HDevWindowStack::GetActive()); + } + *ho_IMG_INS = ho_in_ImageDraw; + if (0 != (int(((*hv_out_NG_Pings_X).TupleLength()) == 0))) + { + (*hv_out_NG_Pings_X) = 0; + (*hv_out_NG_Pings_Y) = 0; + } + + } + // catch (Exception) + catch (HException& HDevExpDefaultException) + { + HDevExpDefaultException.ToHTuple(&hv_Exception); + std::string exception; + exception = hv_Exception.ToString(); + (*hv_out_Flag) = 99999; + (*hv_out_Pings_X) = HTuple(); + (*hv_out_Pings_Y) = HTuple(); + (*hv_out_NG_Pings_X) = HTuple(); + (*hv_out_NG_Pings_Y) = HTuple(); + (*hv_out_Pings_Num) = 0; + (*hv_out_NG_Pings_Num) = 0; + } + + return; +} + void Pings_Inspection_1_Front (HObject ho_in_Image, HTuple hv_in_ShapePath, HTuple hv_in_Parameter, HTuple *hv_out_Pings_X, HTuple *hv_out_Pings_Y, HTuple *hv_out_NG_Pings_X, HTuple *hv_out_NG_Pings_Y, HTuple *hv_out_Pings_Num, HTuple *hv_out_NG_Pings_Num, HTuple *hv_out_Flag, HObject* ho_IMG_INS) @@ -1592,12 +2212,6 @@ void Pings_Inspection_2_Front_New(HObject ho_in_Image, HTuple hv_in_ShapePath, H try { - ////定位 - // - //// Pings_ROI_Rec2(ho_in_Image, hv_in_ShapePath, hv_in_Parameter, &hvec_out_ROI_Row, - // &hvec_out_ROI_Col, &(*hv_out_Flag)); - //HTuple ExpTmpOutVar_0;HTuple ExpTmpOutVar_1; - int x = 3444.74084, y = 1928.88794, w = 503.440155, h = 566.725; HTuple rows, cols; HTuple in_imageWidth, in_imageHeight; GetImageSize(ho_in_Image, &in_imageWidth, &in_imageHeight); @@ -2361,6 +2975,538 @@ void Pings_Inspection_2_Front (HObject ho_in_Image, HTuple hv_in_ShapePath, HTup return; } +void Pings_Inspection_3_Front_New(HObject ho_in_Image, HTuple hv_in_ShapePath, HTuple hv_in_Parameter, + HTuple* hv_out_Pings_X, HTuple* hv_out_Pings_Y, HTuple* hv_out_NG_Pings_X, HTuple* hv_out_NG_Pings_Y, + HTuple* hv_out_Pings_Num, HTuple* hv_out_NG_Pings_Num, HTuple* hv_out_Flag, HObject* ho_IMG_INS) +{ + + // Local iconic variables + HObject ho_in_ImageDraw, ho_ROIRegion, ho_ROI; + HObject ho_Skeleton1, ho_RegionDilation2, ho_ROI_0, ho_ObjectsSelected; + HObject ho_Skeleton, ho_Contours1, ho_ContoursSplit, ho_ObjectSelected1; + HObject ho_Line, ho_LineIntersection, ho_RegionROI, ho_Rectangle; + HObject ho_RegionDilation, ho_RegionIntersection, ho_RegionDifference; + HObject ho_ConnectedRegions, ho_PingRegion, ho_ObjectsSelected1; + HObject ho_Partitioned, ho_RegionErosion1, ho_ObjectsConcat; + HObject ho_SelectedRegions, ho_RegionDilation1, ho_ImageReduced2; + HObject ho_ScaleInspection, ho_ObjectsSelected2, ho_RegionMoved; + HObject ho_ImageReduced1, ho_ImageMean, ho_RegionDynThresh; + HObject ho_RegionOpening1, ho_ConnectedRegions1, ho_SelectedRegions3; + HObject ho_ObjectsSelected3, ho_RegionTrans1, ho_Region1; + HObject ho_RegionErosion, ho_ConnectedRegions2, ho_RegionDifference1; + HObject ho_ConnectedRegions3, ho_RegionUnion1, ho_RegionTrans; + HObject ho_RegionDilation3, ho_RegionErosion2, ho_RegionDifference2; + HObject ho_ConnectedRegions4, ho_SortedRegions, ho_ObjectsSelected4; + HObject ho_RegionUnion, ho_Contours, ho_RegionLines, ho_SelectedRegions1; + HObject ho_SortedRegions2, ho_AdegLeft, ho_AdegRight, ho_RegionLeft; + HObject ho_RegionRight, ho_RectangleOK, ho_in_ImageDraw1; + HObject ho_in_ImageDraw2, ho_in_ImageDraw3, ho_RectangleNG; + + // Local control variables + HTuple hv_Num, hv_Index, hv_Number1, hv_EvenFirstOffset; + HTuple hv_EvenOffset, hv_EvenTime, hv_OddFirstOffset, hv_OddOffset; + HTuple hv_OddTime, hv_Length, hv_Indices, hv_RowBegin; + HTuple hv_ColBegin, hv_RowEnd, hv_ColEnd, hv_Nr, hv_Nc; + HTuple hv_Dist, hv_RowCenter, hv_ColCenter, hv_Phi, hv_LineLength; + HTuple hv_RowStart, hv_ColStart, hv_RowCenter1, hv_ColCenter1; + HTuple hv_Length1, hv_Phi1, hv_Rows, hv_Columns, hv_Index1; + HTuple hv_Number2, hv_Index2, hv_Value1, hv_PingsRow, hv_PingsCol; + HTuple hv_PingsNumber1, hv_PingsNumber2, hv_AbsoluteHisto; + HTuple hv_RelativeHisto, hv_Histo_0to240, hv_GraySum, hv_Area1; + HTuple hv__, hv_GrayMean, hv_Index4, hv_Height, hv_Area; + HTuple hv_Row, hv_Column, hv_PingValue, hv_Number, hv_Value; + HTuple hv_RegionCol, hv_Indices1, hv_Area2, hv_Row1, hv_Column1; + HTuple hv_DistanceMin, hv_H, hv_Number3, hv_Area3, hv_Row2; + HTuple hv_Column2, hv_Value2, hv_MinDistanceLeft, hv_RowLeft1; + HTuple hv_ColumnLeft1, hv_RowLeft2, hv_ColumnLeft2, hv_MinDistanceRight; + HTuple hv_RowRight1, hv_ColumnRight1, hv_RowRight2, hv_ColumnRight2; + HTuple hv_WindowHandle, hv_MSecond, hv_Second, hv_Minute; + HTuple hv_Hour, hv_Day, hv_YDay, hv_Month, hv_Year, hv_FileExists; + HTuple hv_Exception; + HTupleVector hvec_out_ROI_Row(1), hvec_out_ROI_Col(1); + + (*hv_out_Flag) = 1; + (*hv_out_Pings_X) = HTuple(); + (*hv_out_Pings_Y) = HTuple(); + (*hv_out_NG_Pings_X) = HTuple(); + (*hv_out_NG_Pings_Y) = HTuple(); + (*hv_out_Pings_Num) = 0; + (*hv_out_NG_Pings_Num) = 0; + ho_in_ImageDraw = ho_in_Image; + + try + { + //定位 + /*Pings_ROI_Rec2(ho_in_Image, hv_in_ShapePath, hv_in_Parameter, &hvec_out_ROI_Row, + &hvec_out_ROI_Col, &(*hv_out_Flag));*/ + HTuple rows, cols; + HTuple in_imageWidth, in_imageHeight; + GetImageSize(ho_in_Image, &in_imageWidth, &in_imageHeight); + /*cols.Append(x - w); rows.Append(y - h); + cols.Append(x + w); rows.Append(y - h); + cols.Append(x + w); rows.Append(y + h); + cols.Append(x - w); rows.Append(y + h); + cols.Append(x - w); rows.Append(y - h);*/ + cols.Append(1); rows.Append(5); + cols.Append(in_imageWidth - 1); rows.Append(10); + cols.Append(in_imageWidth - 1); rows.Append(in_imageHeight - 1); + cols.Append(1); rows.Append(in_imageHeight - 10); + cols.Append(1); rows.Append(5); + hvec_out_ROI_Row[0].T() = rows; + hvec_out_ROI_Col[0].T() = cols; + + hvec_out_ROI_Row[1].T() = rows; + hvec_out_ROI_Col[1].T() = cols; + GenEmptyRegion(&ho_ROIRegion); + hv_Num = (HTuple(hvec_out_ROI_Row.Length()).TupleInt()) - 1; + { + HTuple end_val15 = hv_Num; + HTuple step_val15 = 1; + for (hv_Index = 0; hv_Index.Continue(end_val15, step_val15); hv_Index += step_val15) + { + GenRegionPolygon(&ho_ROI, hvec_out_ROI_Row[hv_Index].T(), hvec_out_ROI_Col[hv_Index].T()); + FillUp(ho_ROI, &ho_ROI); + Skeleton(ho_ROI, &ho_Skeleton1); + DilationRectangle1(ho_Skeleton1, &ho_RegionDilation2, 90, 1); + Union2(ho_ROIRegion, ho_RegionDilation2, &ho_ROIRegion); + } + } + + Connection(ho_ROIRegion, &ho_ROI_0); + SortRegion(ho_ROI_0, &ho_ROI_0, "first_point", "true", "column"); + CountObj(ho_ROI_0, &hv_Number1); + + //百分比间隔和长度(右至左) + + if (0 != (HTuple(int(HTuple(hv_in_Parameter[1]) == 5)).TupleOr(int(HTuple(hv_in_Parameter[1]) == 6)))) + { + //大Ping盒 + //偶数列 + hv_EvenFirstOffset = 8.5; + hv_EvenOffset = 12.05; + hv_EvenTime = 8; + //奇数列 + hv_OddFirstOffset = 6; + hv_OddOffset = 12.05; + hv_OddTime = 8; + } + else + { + //小Ping盒 + //偶数列 + hv_EvenFirstOffset = 17.5; + hv_EvenOffset = 25.05; + hv_EvenTime = 4; + //奇数列 + hv_OddFirstOffset = 11.7; + hv_OddOffset = 25.05; + hv_OddTime = 4; + } + + { + HTuple end_val51 = hv_Number1; + HTuple step_val51 = 1; + for (hv_Index = 1; hv_Index.Continue(end_val51, step_val51); hv_Index += step_val51) + { + CopyObj(ho_ROI_0, &ho_ObjectsSelected, hv_Index, 1); + //基准线 + Skeleton(ho_ObjectsSelected, &ho_Skeleton); + GenContoursSkeletonXld(ho_Skeleton, &ho_Contours1, 1, "filter"); + SegmentContoursXld(ho_Contours1, &ho_ContoursSplit, "lines_circles", 5, 4, + 2); + + LengthXld(ho_ContoursSplit, &hv_Length); + TupleSortIndex(hv_Length, &hv_Indices); + SelectObj(ho_ContoursSplit, &ho_ObjectSelected1, HTuple(hv_Indices[(hv_Length.TupleLength()) - 1]) + 1); + FitLineContourXld(ho_ObjectSelected1, "tukey", -1, 0, 5, 2, &hv_RowBegin, &hv_ColBegin, + &hv_RowEnd, &hv_ColEnd, &hv_Nr, &hv_Nc, &hv_Dist); + GenRegionLine(&ho_Line, hv_RowBegin, hv_ColBegin, hv_RowEnd, hv_ColEnd); + LinePosition(hv_RowBegin, hv_ColBegin, hv_RowEnd, hv_ColEnd, &hv_RowCenter, + &hv_ColCenter, &hv_Length, &hv_Phi); + hv_LineLength = 3000; + hv_RowStart = hv_RowCenter - (((hv_Phi + 1.5708).TupleCos()) * hv_LineLength); + hv_ColStart = hv_ColCenter - (((hv_Phi + 1.5708).TupleSin()) * hv_LineLength); + hv_RowEnd = hv_RowCenter - (((hv_Phi - 1.5708).TupleCos()) * hv_LineLength); + hv_ColEnd = hv_ColCenter - (((hv_Phi - 1.5708).TupleSin()) * hv_LineLength); + GenRegionLine(&ho_Line, hv_RowStart, hv_ColStart, hv_RowEnd, hv_ColEnd); + Intersection(ho_Line, ho_ObjectsSelected, &ho_LineIntersection); + LinePosition(hv_RowStart, hv_ColStart, hv_RowEnd, hv_ColEnd, &hv_RowCenter1, + &hv_ColCenter1, &hv_Length1, &hv_Phi1); + GetRegionPoints(ho_LineIntersection, &hv_Rows, &hv_Columns); + + //偶数 + if (0 != (int((hv_Index % 2) == 0))) + { + GenEmptyRegion(&ho_RegionROI); + { + HTuple end_val77 = hv_EvenTime - 1; + HTuple step_val77 = 1; + for (hv_Index1 = 0; hv_Index1.Continue(end_val77, step_val77); hv_Index1 += step_val77) + { + GenRectangle2(&ho_Rectangle, HTuple(hv_Rows[(((HTuple(hv_Rows.TupleLength()).TupleReal()) * (hv_EvenFirstOffset + (hv_EvenOffset * hv_Index1))) * 0.01).TupleInt()]), + HTuple(hv_Columns[(((HTuple(hv_Columns.TupleLength()).TupleReal()) * (hv_EvenFirstOffset + (hv_EvenOffset * hv_Index1))) * 0.01).TupleInt()]), + hv_Phi1 + (HTuple(90).TupleRad()), 40, 120); + Union2(ho_RegionROI, ho_Rectangle, &ho_RegionROI); + } + } + Connection(ho_RegionROI, &ho_RegionROI); + //奇数 + } + else + { + GenEmptyRegion(&ho_RegionROI); + { + HTuple end_val85 = hv_OddTime - 1; + HTuple step_val85 = 1; + for (hv_Index1 = 0; hv_Index1.Continue(end_val85, step_val85); hv_Index1 += step_val85) + { + GenRectangle2(&ho_Rectangle, HTuple(hv_Rows[(((HTuple(hv_Rows.TupleLength()).TupleReal()) * (hv_OddFirstOffset + (hv_OddOffset * hv_Index1))) * 0.01).TupleInt()]), + HTuple(hv_Columns[(((HTuple(hv_Columns.TupleLength()).TupleReal()) * (hv_OddFirstOffset + (hv_OddOffset * hv_Index1))) * 0.01).TupleInt()]), + hv_Phi1 + (HTuple(90).TupleRad()), 40, 120); + Union2(ho_RegionROI, ho_Rectangle, &ho_RegionROI); + } + } + Connection(ho_RegionROI, &ho_RegionROI); + } + + DilationRectangle1(ho_RegionROI, &ho_RegionDilation, 101, 1); + Intersection(ho_RegionDilation, ho_ObjectsSelected, &ho_RegionIntersection); + Difference(ho_ObjectsSelected, ho_RegionDilation, &ho_RegionDifference); + Connection(ho_RegionDifference, &ho_ConnectedRegions); + + CountObj(ho_RegionIntersection, &hv_Number2); + GenEmptyRegion(&ho_PingRegion); + { + HTuple end_val99 = hv_Number2; + HTuple step_val99 = 1; + for (hv_Index2 = 1; hv_Index2.Continue(end_val99, step_val99); hv_Index2 += step_val99) + { + CopyObj(ho_RegionIntersection, &ho_ObjectsSelected1, hv_Index2, 1); + RegionFeatures(ho_ObjectsSelected1, (HTuple("width").Append("height")), &hv_Value1); + PartitionRectangle(ho_ObjectsSelected1, &ho_Partitioned, HTuple(hv_Value1[0]), + HTuple(hv_Value1[1]) / 2); + ErosionRectangle1(ho_Partitioned, &ho_RegionErosion1, 1, 41); + Union2(ho_PingRegion, ho_RegionErosion1, &ho_PingRegion); + } + } + Connection(ho_PingRegion, &ho_PingRegion); + + ConcatObj(ho_PingRegion, ho_ConnectedRegions, &ho_ObjectsConcat); + SelectShape(ho_ObjectsConcat, &ho_SelectedRegions, "height", "and", 30, 99999); + SortRegion(ho_SelectedRegions, &ho_RegionROI, "first_point", "true", "row"); + + RegionFeatures(ho_RegionROI, "row", &hv_PingsRow); + RegionFeatures(ho_RegionROI, "column", &hv_PingsCol); + + CountObj(ho_ConnectedRegions, &hv_PingsNumber1); + CountObj(ho_PingRegion, &hv_PingsNumber2); + + //测试显示用 + if (0 != (int(HTuple(hv_in_Parameter[5]) == 2))) + { + PaintRegion(ho_LineIntersection, ho_in_ImageDraw, &ho_in_ImageDraw, 255, + "fill"); + } + + //检测 + DilationRectangle1(ho_LineIntersection, &ho_RegionDilation1, 120, 1); + GrayHisto(ho_RegionDilation1, ho_in_Image, &hv_AbsoluteHisto, &hv_RelativeHisto); + TupleRemove(hv_AbsoluteHisto, (((((((((((((((HTuple(241).Append(242)).Append(243)).Append(244)).Append(245)).Append(246)).Append(247)).Append(248)).Append(249)).Append(250)).Append(251)).Append(252)).Append(253)).Append(254)).Append(255)).Append(256)), + &hv_Histo_0to240); + hv_GraySum = 0; + { + HTuple end_val128 = (hv_Histo_0to240.TupleLength()) - 1; + HTuple step_val128 = 1; + for (hv_Index1 = 0; hv_Index1.Continue(end_val128, step_val128); hv_Index1 += step_val128) + { + hv_GraySum = (hv_Index1 * HTuple(hv_Histo_0to240[hv_Index1])) + hv_GraySum; + } + } + AreaCenter(ho_RegionDilation1, &hv_Area1, &hv__, &hv__); + hv_GrayMean = hv_GraySum / hv_Area1; + ReduceDomain(ho_in_Image, ho_RegionDilation1, &ho_ImageReduced2); + ScaleImage(ho_ImageReduced2, &ho_ScaleInspection, (HTuple(255).TupleReal()) / hv_GrayMean, + -120); + + //单独ping检测 + { + HTuple end_val137 = hv_PingsNumber1; + HTuple step_val137 = 1; + for (hv_Index4 = 1; hv_Index4.Continue(end_val137, step_val137); hv_Index4 += step_val137) + { + CopyObj(ho_ConnectedRegions, &ho_ObjectsSelected2, hv_Index4, 1); + if (0 != (HTuple(int((hv_Index % 2) == 1)).TupleAnd(int(hv_Index4 == hv_PingsNumber1)))) + { + RegionFeatures(ho_ObjectsSelected2, "height", &hv_Height); + if (0 != (int(hv_Height > 70))) + { + MoveRegion(ho_ObjectsSelected2, &ho_RegionMoved, 70 - hv_Height, 0); + Intersection(ho_ObjectsSelected2, ho_RegionMoved, &ho_ObjectsSelected2 + ); + } + } + + DilationRectangle1(ho_ObjectsSelected2, &ho_ObjectsSelected2, 31, 1); + AreaCenter(ho_ObjectsSelected2, &hv_Area, &hv_Row, &hv_Column); + RegionFeatures(ho_ObjectsSelected2, (HTuple("row").Append("column")), &hv_PingValue); + ReduceDomain(ho_ScaleInspection, ho_ObjectsSelected2, &ho_ImageReduced1); + MeanImage(ho_ImageReduced1, &ho_ImageMean, 21, 5); + DynThreshold(ho_ImageReduced1, ho_ImageMean, &ho_RegionDynThresh, 51, "light"); + + if (0 != (HTuple(HTuple(int(hv_PingsNumber1 < 7)).TupleAnd(HTuple(int((hv_Index % 2) == 1)).TupleAnd(HTuple(int(hv_Index4 == 1)).TupleOr(int(hv_Index4 == 5))))).TupleOr(HTuple(int(hv_PingsNumber1 > 7)).TupleAnd(HTuple(HTuple(int((hv_Index % 2) == 1)).TupleAnd(HTuple(int(hv_Index4 == 1)).TupleOr(int(hv_Index4 == 9)))).TupleOr(HTuple(int((hv_Index % 2) == 0)).TupleAnd(int(hv_Index4 == 9))))))) + { + //短ping + OpeningRectangle1(ho_RegionDynThresh, &ho_RegionOpening1, 1, 8); + Connection(ho_RegionOpening1, &ho_ConnectedRegions1); + SelectShape(ho_ConnectedRegions1, &ho_SelectedRegions3, ((HTuple("height").Append("width")).Append("convexity")), + "and", ((HTuple(10).Append(0)).Append(0.8)), ((HTuple(99999).Append(15)).Append(1))); + } + else + { + //长ping + OpeningRectangle1(ho_RegionDynThresh, &ho_RegionOpening1, 1, 30); + Connection(ho_RegionOpening1, &ho_ConnectedRegions1); + SelectShape(ho_ConnectedRegions1, &ho_SelectedRegions3, ((HTuple("height").Append("width")).Append("convexity")), + "and", ((HTuple(50).Append(0)).Append(0.8)), ((HTuple(99999).Append(15)).Append(1))); + } + + CountObj(ho_SelectedRegions3, &hv_Number); + //未找到边缘,视为不合格 + if (0 != (int(hv_Number == 0))) + { + RegionFeatures(ho_ObjectsSelected2, (HTuple("row").Append("column")), &hv_Value); + (*hv_out_NG_Pings_X) = (*hv_out_NG_Pings_X).TupleConcat(HTuple(hv_PingValue[0])); + (*hv_out_NG_Pings_Y) = (*hv_out_NG_Pings_Y).TupleConcat(HTuple(hv_PingValue[1])); + (*hv_out_NG_Pings_Num) += 1; + continue; + } + + RegionFeatures(ho_SelectedRegions3, "column", &hv_RegionCol); + TupleSortIndex((hv_RegionCol - hv_Column).TupleAbs(), &hv_Indices1); + CopyObj(ho_SelectedRegions3, &ho_ObjectsSelected3, HTuple(hv_Indices1[0]) + 1, + 1); + + ShapeTrans(ho_ObjectsSelected3, &ho_RegionTrans1, "rectangle1"); + AreaCenter(ho_RegionTrans1, &hv_Area2, &hv_Row1, &hv_Column1); + + + //测试显示用 + if (0 != (int(HTuple(hv_in_Parameter[5]) == 2))) + { + PaintRegion(ho_RegionTrans1, ho_in_ImageDraw, &ho_in_ImageDraw, 255, "fill"); + } + + //边缘异常,视为不合格 + if (0 != 0) + { + RegionFeatures(ho_ObjectsSelected2, (HTuple("row").Append("column")), &hv_Value); + (*hv_out_NG_Pings_X) = (*hv_out_NG_Pings_X).TupleConcat(HTuple(hv_PingValue[0])); + (*hv_out_NG_Pings_Y) = (*hv_out_NG_Pings_Y).TupleConcat(HTuple(hv_PingValue[1])); + (*hv_out_NG_Pings_Num) += 1; + } + else + { + DistancePr(ho_LineIntersection, hv_Row1, hv_Column1, &hv_DistanceMin, &hv__); + + if (0 != (int((hv_DistanceMin * HTuple(hv_in_Parameter[3])) > HTuple(hv_in_Parameter[4])))) + { + (*hv_out_NG_Pings_X) = (*hv_out_NG_Pings_X).TupleConcat(HTuple(hv_PingValue[0])); + (*hv_out_NG_Pings_Y) = (*hv_out_NG_Pings_Y).TupleConcat(HTuple(hv_PingValue[1])); + (*hv_out_NG_Pings_Num) += 1; + } + } + } + } + (*hv_out_Pings_X) = (*hv_out_Pings_X).TupleConcat(hv_PingsRow); + (*hv_out_Pings_Y) = (*hv_out_Pings_Y).TupleConcat(hv_PingsCol); + (*hv_out_Pings_Num) += hv_PingsNumber1; + + //成对ping检测 + { + HTuple end_val210 = hv_PingsNumber2; + HTuple step_val210 = 1; + for (hv_Index4 = 1; hv_Index4.Continue(end_val210, step_val210); hv_Index4 += step_val210) + { + CopyObj(ho_PingRegion, &ho_ObjectsSelected2, hv_Index4, 1); + RegionFeatures(ho_ObjectsSelected2, "height", &hv_Height); + hv_H = 60; + RegionFeatures(ho_ObjectsSelected2, (HTuple("row").Append("column")), &hv_PingValue); + ReduceDomain(ho_ScaleInspection, ho_ObjectsSelected2, &ho_ImageReduced1); + Threshold(ho_ImageReduced1, &ho_Region1, 0, 30); + OpeningRectangle1(ho_Region1, &ho_RegionOpening1, 1, 20); + Connection(ho_RegionOpening1, &ho_ConnectedRegions1); + + ErosionRectangle1(ho_ObjectsSelected2, &ho_RegionErosion, 21, 1); + SelectShapeProto(ho_ConnectedRegions1, ho_RegionErosion, &ho_ConnectedRegions2, + "overlaps_rel", 80, 100); + Difference(ho_ObjectsSelected2, ho_RegionErosion, &ho_RegionDifference1); + SelectShapeProto(ho_ConnectedRegions1, ho_RegionDifference1, &ho_ConnectedRegions3, + "overlaps_rel", 20, 100); + CountObj(ho_ConnectedRegions3, &hv_Number3); + if (0 != (int(hv_Number3 != 0))) + { + Union1(ho_ConnectedRegions3, &ho_RegionUnion1); + ShapeTrans(ho_RegionUnion1, &ho_RegionTrans, "rectangle1"); + DilationRectangle1(ho_RegionTrans, &ho_RegionDilation3, 11, 1); + ErosionRectangle1(ho_RegionDilation3, &ho_RegionErosion2, 1, 11); + Difference(ho_RegionErosion2, ho_RegionTrans, &ho_RegionDifference2); + Connection(ho_RegionDifference2, &ho_ConnectedRegions4); + SortRegion(ho_ConnectedRegions4, &ho_SortedRegions, "first_point", "true", + "column"); + AreaCenter(ho_RegionTrans, &hv_Area3, &hv_Row2, &hv_Column2); + if (0 != (int(hv_Column2 >= HTuple(hv_PingValue[1])))) + { + CopyObj(ho_SortedRegions, &ho_ObjectsSelected4, 1, 1); + } + else + { + CopyObj(ho_SortedRegions, &ho_ObjectsSelected4, 2, 1); + } + GrayFeatures(ho_ObjectsSelected4, ho_ImageReduced1, "mean", &hv_Value2); + if (0 != (int(hv_Value2 > 80))) + { + ho_ConnectedRegions1 = ho_ConnectedRegions2; + } + } + + SelectShape(ho_ConnectedRegions1, &ho_SelectedRegions3, ((HTuple("area").Append("height")).Append("width")), + "and", (HTuple(50).TupleConcat(hv_H * 0.5)).TupleConcat(8), ((HTuple(99999).Append(99999)).Append(99999))); + Union1(ho_SelectedRegions3, &ho_RegionUnion); + ShapeTrans(ho_RegionUnion, &ho_RegionTrans1, "rectangle1"); + GenContourRegionXld(ho_RegionTrans1, &ho_Contours, "border"); + + SegmentContoursXld(ho_Contours, &ho_ContoursSplit, "lines_circles", 5, 4, + 2); + FitLineContourXld(ho_ContoursSplit, "tukey", -1, 0, 5, 2, &hv_RowBegin, &hv_ColBegin, + &hv_RowEnd, &hv_ColEnd, &hv_Nr, &hv_Nc, &hv_Dist); + GenRegionLine(&ho_RegionLines, hv_RowBegin, hv_ColBegin, hv_RowEnd, hv_ColEnd); + SelectShape(ho_RegionLines, &ho_SelectedRegions1, (HTuple("width").Append("height")), + "and", HTuple(0).TupleConcat(hv_H * 0.5), (HTuple(15).Append(300))); + + SortRegion(ho_SelectedRegions1, &ho_SortedRegions2, "first_point", "true", + "column"); + CountObj(ho_SortedRegions2, &hv_Number); + + //未找到边缘,视为合格 + if (0 != (int(hv_Number == 0))) + { + //region_features (ObjectsSelected2, ['row','column'], Value) + //out_NG_Pings_X := [out_NG_Pings_X,PingValue[0]] + //out_NG_Pings_Y := [out_NG_Pings_Y,PingValue[1]] + //out_NG_Pings_Num := out_NG_Pings_Num + 1 + continue; + } + + CopyObj(ho_SortedRegions2, &ho_AdegLeft, 1, 1); + CopyObj(ho_SortedRegions2, &ho_AdegRight, 2, 1); + + //测试显示用 + if (0 != (int(HTuple(hv_in_Parameter[5]) == 2))) + { + PaintRegion(ho_AdegLeft, ho_in_ImageDraw, &ho_in_ImageDraw, 255, "fill"); + PaintRegion(ho_AdegRight, ho_in_ImageDraw, &ho_in_ImageDraw, 255, "fill"); + } + + //边缘异常,视为不合格 + if (0 != 0) + { + RegionFeatures(ho_ObjectsSelected2, (HTuple("row").Append("column")), &hv_Value); + (*hv_out_NG_Pings_X) = (*hv_out_NG_Pings_X).TupleConcat(HTuple(hv_PingValue[0])); + (*hv_out_NG_Pings_Y) = (*hv_out_NG_Pings_Y).TupleConcat(HTuple(hv_PingValue[1])); + (*hv_out_NG_Pings_Num) += 1; + } + else + { + DistanceRrMin(ho_AdegLeft, ho_LineIntersection, &hv_MinDistanceLeft, &hv_RowLeft1, + &hv_ColumnLeft1, &hv_RowLeft2, &hv_ColumnLeft2); + GenRegionLine(&ho_RegionLeft, hv_RowLeft1, hv_ColumnLeft1, hv_RowLeft2, + hv_ColumnLeft2); + DistanceRrMin(ho_AdegRight, ho_LineIntersection, &hv_MinDistanceRight, + &hv_RowRight1, &hv_ColumnRight1, &hv_RowRight2, &hv_ColumnRight2); + GenRegionLine(&ho_RegionRight, hv_RowRight1, hv_ColumnRight1, hv_RowRight2, + hv_ColumnRight2); + + //测试显示用 + if (0 != (int(HTuple(hv_in_Parameter[5]) == 2))) + { + PaintRegion(ho_RegionLeft, ho_in_ImageDraw, &ho_in_ImageDraw, 255, "fill"); + PaintRegion(ho_RegionRight, ho_in_ImageDraw, &ho_in_ImageDraw, 255, "fill"); + } + + hv_DistanceMin = (((hv_MinDistanceLeft.TupleConcat(hv_MinDistanceRight)).TupleMax()).TupleReal()) - 20; + if (0 != (int((hv_DistanceMin * HTuple(hv_in_Parameter[3])) > HTuple(hv_in_Parameter[4])))) + { + (*hv_out_NG_Pings_X) = (*hv_out_NG_Pings_X).TupleConcat(HTuple(hv_PingValue[0])); + (*hv_out_NG_Pings_Y) = (*hv_out_NG_Pings_Y).TupleConcat(HTuple(hv_PingValue[1])); + (*hv_out_NG_Pings_Num) += 1; + } + } + } + } + (*hv_out_Pings_X) = (*hv_out_Pings_X).TupleConcat(hv_PingsRow); + (*hv_out_Pings_Y) = (*hv_out_Pings_Y).TupleConcat(hv_PingsCol); + (*hv_out_Pings_Num) += hv_PingsNumber1; + } + } + + //测试显示用 + if (0 != (int(HTuple(hv_in_Parameter[5]) == 2))) + { + if (HDevWindowStack::IsOpen()) + hv_WindowHandle = HDevWindowStack::GetActive(); + GenRectangle1(&ho_RectangleOK, (*hv_out_Pings_X) - 40, (*hv_out_Pings_Y) - 40, + (*hv_out_Pings_X) + 40, (*hv_out_Pings_Y) + 40); + PaintRegion(ho_RectangleOK, ho_in_ImageDraw, &ho_in_ImageDraw1, 0, "margin"); + PaintRegion(ho_RectangleOK, ho_in_ImageDraw, &ho_in_ImageDraw2, 255, "margin"); + PaintRegion(ho_RectangleOK, ho_in_ImageDraw, &ho_in_ImageDraw3, 0, "margin"); + + if (0 != (int(((*hv_out_NG_Pings_X).TupleLength()) != 0))) + { + GenRectangle1(&ho_RectangleNG, (*hv_out_NG_Pings_X) - 40, (*hv_out_NG_Pings_Y) - 40, + (*hv_out_NG_Pings_X) + 40, (*hv_out_NG_Pings_Y) + 40); + PaintRegion(ho_RectangleNG, ho_in_ImageDraw1, &ho_in_ImageDraw1, 255, "margin"); + PaintRegion(ho_RectangleNG, ho_in_ImageDraw2, &ho_in_ImageDraw2, 0, "margin"); + PaintRegion(ho_RectangleNG, ho_in_ImageDraw3, &ho_in_ImageDraw3, 0, "margin"); + } + + Compose3(ho_in_ImageDraw1, ho_in_ImageDraw2, ho_in_ImageDraw3, &ho_in_ImageDraw + ); + + GetImageTime(ho_in_ImageDraw, &hv_MSecond, &hv_Second, &hv_Minute, &hv_Hour, + &hv_Day, &hv_YDay, &hv_Month, &hv_Year); + FileExists((hv_in_ShapePath + "/Result") + HTuple(hv_in_Parameter[0]), &hv_FileExists); + if (0 != (int(hv_FileExists != 1))) + { + MakeDir((hv_in_ShapePath + "/Result") + HTuple(hv_in_Parameter[0])); + } + //WriteImage(ho_in_ImageDraw, "bmp", 0, (((((((hv_in_ShapePath + "/Result") + HTuple(hv_in_Parameter[0])) + "/") + hv_Day) + hv_Hour) + hv_Minute) + hv_Second) + hv_MSecond); + } + *ho_IMG_INS = ho_in_ImageDraw; + if (0 != (int(((*hv_out_NG_Pings_X).TupleLength()) == 0))) + { + (*hv_out_NG_Pings_X) = 0; + (*hv_out_NG_Pings_Y) = 0; + } + + } + // catch (Exception) + catch (HException& HDevExpDefaultException) + { + HDevExpDefaultException.ToHTuple(&hv_Exception); + std::string exception; + exception = hv_Exception.ToString(); + (*hv_out_Flag) = 99999; + (*hv_out_Pings_X) = HTuple(); + (*hv_out_Pings_Y) = HTuple(); + (*hv_out_NG_Pings_X) = HTuple(); + (*hv_out_NG_Pings_Y) = HTuple(); + (*hv_out_Pings_Num) = 0; + (*hv_out_NG_Pings_Num) = 0; + } + + return; +} + void Pings_Inspection_3_Front (HObject ho_in_Image, HTuple hv_in_ShapePath, HTuple hv_in_Parameter, HTuple *hv_out_Pings_X, HTuple *hv_out_Pings_Y, HTuple *hv_out_NG_Pings_X, HTuple *hv_out_NG_Pings_Y, HTuple *hv_out_Pings_Num, HTuple *hv_out_NG_Pings_Num, HTuple *hv_out_Flag, HObject* ho_IMG_INS) diff --git a/HanddleAI/HandleAiUi-new/uiModule/uiModule_switchProduct.h b/HanddleAI/HandleAiUi-new/uiModule/uiModule_switchProduct.h index 07753895..c197186e 100644 --- a/HanddleAI/HandleAiUi-new/uiModule/uiModule_switchProduct.h +++ b/HanddleAI/HandleAiUi-new/uiModule/uiModule_switchProduct.h @@ -8,8 +8,8 @@ class switchProductWidget : public QWidget Q_OBJECT public: QLabel* staticLabel = new QLabel(this); - std::vectorproductName ={"asr1006","asr1009","cs9600","MDS9710"}; - std::vectorproductCode = { 1,2,3,4}; + std::vectorproductName ={"asr1006","asr1009","cs9600","MDS9710","MDS9706","C9504"}; + std::vectorproductCode = { 1,2,3,4,5,6}; int* currentProductIndexPtr; QVBoxLayout* layout = new QVBoxLayout(this); fancyButtonText* switchBtn = new fancyButtonText(100, 60, "修改", "修改当前机型");