void panTaskLogo::OnButtonClick( wxCommandEvent& event ) { Hobject region_loc, Image, TemplateImage, ModelContours; Hobject roi_loc; HTuple WindowHandle, ModelId, ModelRow, ModelColumn; HTuple ModelAngle, ModelScore, MatchingObjIdx, HomMat; roi_loc = c_pgvTask->gvTask_GetROI()->gvROI_GetROI(); Image = c_pgvVisionImage->gvIMG_GetImage(); if(c_pgvVisionImage->_insp_loc(Image,®ion_loc)) { set_system("border_shape_models", "false"); reduce_domain(Image, roi_loc, &TemplateImage); create_shape_model(TemplateImage, 4, HTuple(0).Rad(), HTuple(360).Rad(), HTuple(0.6824).Rad(), (HTuple("point_reduction_high").Append("no_pregeneration")), "use_polarity", ((HTuple(15).Append(19)).Append(6)), 4, &ModelId); get_shape_model_contours(&ModelContours, ModelId, 1); c_pgvTask->gvTask_SetModeId(ModelId); } else { wxMessageBox(wxT("未检测到产品,请调整产品位置后重新学习!")); } }
bool gvVisionTask_black::gvTask_inspect( Hobject image_src, Hobject *outRegion_defects ) { // Local iconic variables Hobject TMP_Region, Region1, RegionErosion1,ImageReduced; Hobject Image_meanSmall, Image_meanLarge, RegionDynThresh; Hobject ConnectedRegions, RegionFillUp, RegionErosion, ConnectedRegions1; Hobject SelectedRegions, RegionDilation1, RegionDilation; Hobject RegionDifference, obj_selected; // Local control variables HTuple Meancenter, Deviation, Meanouter, Deviation1; HTuple Index, Number; // reduce_domain(image_src, gvTask_GetROI()->gvROI_GetROI(), &ImageReduced); reduce_domain(image_src, gvTask_GetROI()->gvROI_GetROI(), &ImageReduced); threshold(ImageReduced, &Region1, 100, 255); fill_up(Region1, &Region1); erosion_circle(Region1, &RegionErosion1, 20); mean_image(ImageReduced, &Image_meanSmall, 2, 2); mean_image(ImageReduced, &Image_meanLarge, 20, 20); dyn_threshold(Image_meanSmall, Image_meanLarge, &RegionDynThresh, 5, "dark"); connection(RegionDynThresh, &ConnectedRegions); fill_up(ConnectedRegions, &RegionFillUp); erosion_circle(RegionFillUp, &RegionErosion, 1.5); connection(RegionErosion, &ConnectedRegions1); select_shape(ConnectedRegions1, &SelectedRegions, "area", "and", m_minBlackSpotArea, 5000); dilation_circle(SelectedRegions, &RegionDilation1, 2.5); intensity(RegionDilation1, Image_meanSmall, &Meancenter, &Deviation); dilation_circle(SelectedRegions, &RegionDilation, 5); difference(RegionDilation, SelectedRegions, &RegionDifference); intensity(RegionDifference, Image_meanSmall, &Meanouter, &Deviation1); gen_empty_obj(&(*outRegion_defects)); for (Index=0; Index<=(Meancenter.Num())-1; Index+=1) { select_obj(SelectedRegions, &obj_selected, Index+1); if (0 != ((HTuple(Meancenter[Index])-HTuple(Meanouter[Index]))<-30)) { concat_obj((*outRegion_defects), obj_selected, &(*outRegion_defects)); } } count_obj((*outRegion_defects), &Number); if(Number>m_maxBlackSpotCnt||Number<m_minBlackSpotCnt ) { return FALSE; } return TRUE; }
void panTaskColor::OnButton1Click( wxCommandEvent& event ) { Hobject image_src,region_loc,ImageReduced, Red, Green, Blue; HTuple Mean_red, Deviation, Mean_green,Mean_blue; image_src = c_pgvVisionImage->gvIMG_GetImage(); reduce_domain(image_src, c_pgvTask->gvTask_GetROI()->gvROI_GetROI(), &ImageReduced); decompose3(ImageReduced, &Red, &Green, &Blue); intensity(ImageReduced, Red, &Mean_red, &Deviation); intensity(ImageReduced, Green, &Mean_green, &Deviation); intensity(ImageReduced, Blue, &Mean_blue, &Deviation); m_actualblue->SetValue(Mean_blue[0].L()); m_actualred->SetValue(Mean_red[0].L()); m_actualgreen->SetValue(Mean_green[0].L()); }
void CDoProcess::DoProcess(CMData* pData,SubTestResult *testItem) { // Local iconic variables Hobject Image=pData->m_Image; Hlong m_thred_low1=m_Parameters.m_thred_low1; Hlong m_thred_high1=m_Parameters.m_thred_high1; Hlong m_thred_low2=m_Parameters.m_thred_low2; Hlong m_thred_high2=m_Parameters.m_thred_high2; Hlong m_thred; ///////// if (m_thred_low1>m_thred_high1) { m_thred=m_thred_low1; m_thred_low1=m_thred_high1; m_thred_high1=m_thred; } if (m_thred_low2>m_thred_high2) { m_thred=m_thred_low2; m_thred_low2=m_thred_high2; m_thred_high2=m_thred; } /////////////////////////////////////////////////////// // Local iconic variables Hobject Region, ConnectedRegions, SelectedRegions; Hobject RegionUnion, RegionFillUp, Contours, Rectangle1; Hobject Rectangle2, ImageReduced1, ImageReduced2, Region1; Hobject Region2, RegionDilation1, RegionErosion1, RegionDilation2; Hobject RegionErosion2; // Local control variables HTuple ModelID,Area;//Row1, Column1, Radius1; HTuple Row11, Column11, Row12, Column12; HTuple Row21, Column21, Row22, Column22; //////////////////////////////////////////////////////////// // Local control variables HTuple Row; HTuple Column; // dev_update_off(...); only in hdevelop try { ///Row_model_center = 237.659; //Column_model_center = 339.212; /*gen_circle(&Circle5, Row, Column,m_Parameters.radius_ext); gen_circle(&Circle6, Row, Column,m_Parameters.radius_inner); difference(Circle5, Circle6, &RegionDifference_median); reduce_domain(Image, RegionDifference_median, &ImageReduced_median); intensity(RegionDifference_median, Image, &Mean_median, &Deviation_median); fast_threshold(ImageReduced_median, &Region_median, m_Parameters.radius_inner_thred, 255, 1);//Mean_median*1.2 connection(Region_median, &ConnectedRegions_median); select_shape(ConnectedRegions_median, &SelectedRegions_median, "area", "and", m_Parameters.radius_ext_extract_size, 99999); union1(SelectedRegions_median, &RegionUnion_median); area_center(RegionUnion_median, &Area_baoChiJia, &Row_baoChiJia, &Column_baoChiJia);*/ //********************************************************** threshold(Image, &Region, 0, m_Parameters.radius_inner_thred); connection(Region, &ConnectedRegions); select_shape(ConnectedRegions, &SelectedRegions, "area", "and", m_Parameters.radius_ext_extract_size, 149999); union1(SelectedRegions, &RegionUnion); fill_up(RegionUnion, &RegionFillUp); area_center(RegionFillUp, &Area, &Row, &Column); /////////////////////////////////// /*if (!_access(m_Parameters.CenterOcrModelRegion.c_str(),0)) { wstring msg = _T("Set Region already Exit.OverWrite or Not?"); if (MessageBox(NULL,msg.c_str(),_T("ReadFile Error"),MB_OK||MB_CANCELTRYCONTINUE)==IDOK) { write_region(RegionFillUp,m_Parameters.CenterOcrModelRegion.c_str()); } } else*/ write_region(RegionFillUp,m_Parameters.CenterOcrModelRegion.c_str()); ///////////////////////////////////////// gen_contour_region_xld(RegionFillUp, &Contours, "border"); create_shape_model_xld(Contours, 1, -0.69, 0.79, "auto", "auto", "ignore_local_polarity", 5, &ModelID); //匹配数据 /*if (!_access(m_Parameters.CenterOcrModelName.c_str(),0)) { wstring msg = _T("Set Model already Exit.OverWrite or Not?"); if (MessageBox(NULL,msg.c_str(),_T("ReadFile Error"),MB_OK||MB_CANCELTRYCONTINUE)==IDOK) { write_shape_model(ModelID,m_Parameters.CenterOcrModelName.c_str()); } } else*/ write_shape_model(ModelID,m_Parameters.CenterOcrModelName.c_str()); //***************************************************************** Row11=m_Parameters.YMin1; Row12=m_Parameters.YMin1+m_Parameters.YMax1; Column11=m_Parameters.XMin1; Column12=m_Parameters.XMin1+m_Parameters.XMax1; Row21=m_Parameters.YMin2; Row22=m_Parameters.YMin2+m_Parameters.YMax2; Column21=m_Parameters.XMin2; Column22=m_Parameters.XMin2+m_Parameters.XMax2; gen_rectangle1(&Rectangle1, Row11, Column11, Row12, Column12); gen_rectangle1(&Rectangle2, Row21, Column21, Row22, Column22); reduce_domain(Image, Rectangle1, &ImageReduced1); reduce_domain(Image, Rectangle2, &ImageReduced2); threshold(ImageReduced1, &Region1, m_Parameters.m_thred_low1, m_Parameters.m_thred_high1); threshold(ImageReduced2, &Region2, m_Parameters.m_thred_low2, m_Parameters.m_thred_high2); dilation_circle(Region1, &RegionDilation1, 3.5); erosion_circle(RegionDilation1, &RegionErosion1, m_Parameters.region_erosion1_size); dilation_circle(Region2, &RegionDilation2, 3.5); erosion_circle(RegionDilation2, &RegionErosion2, m_Parameters.region_erosion2_size); //创建模板时 保存区域和区域图片。在提取区域时,因为正常运行时每次都要用,不能使用 /*if (!_access(m_Parameters.CenterOcrModelRegion1.c_str(),0)) { wstring msg = _T("Set Region already Exit.OverWrite or Not?"); if (MessageBox(NULL,msg.c_str(),_T("ReadFile Error"),MB_OK||MB_CANCELTRYCONTINUE)==IDOK) { write_region(RegionErosion1,m_Parameters.CenterOcrModelRegion1.c_str()); } } else*/ write_region(RegionErosion1,m_Parameters.CenterOcrModelRegion1.c_str()); /*if (!_access(m_Parameters.CenterOcrModelRegion2.c_str(),0)) { wstring msg = _T("Set Region already Exit.OverWrite or Not?"); if (MessageBox(NULL,msg.c_str(),_T("ReadFile Error"),MB_OK||MB_CANCELTRYCONTINUE)==IDOK) { write_region(RegionErosion2,m_Parameters.CenterOcrModelRegion2.c_str()); } } else*/ write_region(RegionErosion2,m_Parameters.CenterOcrModelRegion2.c_str()); ///////////////////////////////////////////////// // Number_QiPao=1; if (1) { //pData->m_isFail= false; //testItem->m_bFailSubTest = false; pData->m_center_y2=Row[0].D(); pData->m_center_x2=Column[0].D(); } else { //testItem->m_ErrorMsg = "Error No Find Center"; //testItem->m_ErrorY = 250; //testItem->m_ErrorX = 350; //testItem->m_ErrorR = 55; //set_color(pData->m_ShowHWindow,"red"); //disp_region(SelectedRegions_qiPao_extract,pData->m_ShowHWindow); //disp_circle(pData->m_ShowHWindow,Row_center,Column_center,85); } set_color(pData->m_ShowHWindow,"blue"); disp_obj(Contours,pData->m_ShowHWindow); set_color(pData->m_ShowHWindow,"green"); disp_region(Rectangle1,pData->m_ShowHWindow); disp_region(Rectangle2,pData->m_ShowHWindow); disp_region(RegionErosion1,pData->m_ShowHWindow); disp_region(RegionErosion2,pData->m_ShowHWindow); set_color(pData->m_ShowHWindow,"red"); /////// } catch (HException &except) { pData->m_isFail = true; testItem->m_bFailSubTest = true; pData->m_orientationPhi=0; //testItem->m_ErrorMsg = except.file; //testItem->m_ErrorMsg += " "; //testItem->m_ErrorMsg += except.line; //testItem->m_ErrorMsg += " "; //testItem->m_ErrorMsg += except.message; testItem->m_ErrorY = 1; testItem->m_ErrorX = 1; testItem->m_ErrorR = 4; } }
void CDoProcess::DoProcess(CMData* pData,SubTestResult *testItem) { try { Hobject image = pData->m_Image; Hobject ROI,Circle1,Circle2; if((pData->r_real+m_Parameters.Regional_Out-m_Parameters.ROIWidth)>0) { gen_circle(&Circle1, (pData->m_center_y), (pData->m_center_x), (pData->r_real+m_Parameters.Regional_Out)); gen_circle(&Circle2, (pData->m_center_y), (pData->m_center_x), pData->r_real+m_Parameters.Regional_Out-m_Parameters.ROIWidth); difference(Circle1, Circle2, &ROI); if (ShowObject&&pData->m_isDebug) { set_color(pData->m_ShowHWindow,"blue"); disp_obj(Circle1,pData->m_ShowHWindow); set_color(pData->m_ShowHWindow,"green"); disp_obj(Circle2,pData->m_ShowHWindow); } } else { gen_circle(&ROI, (pData->m_center_y), (pData->m_center_x), (pData->r_real+m_Parameters.Regional_Out)); if (ShowObject&&pData->m_isDebug) { set_color(pData->m_ShowHWindow,"blue"); disp_obj(ROI,pData->m_ShowHWindow); } } // Local iconic variables Hobject region_tai,BlackImageMean,WhiteImageMean; Hobject BlackPointDynThresh, BLACK_POINT, SeriousBlackPointDynThresh; Hobject SeriousBlackConnected, SERIOUS_BlackPoint; Hobject WhitePointDynThresh, WHITE_POINT, SeriousWhitePointDynThresh; Hobject SeriousWhiteConnected, SERIOUS_WhitePoint; Hlong Number; Hobject Dilation,ExpandedImage; reduce_domain(image, ROI, ®ion_tai); expand_domain_gray(region_tai, &ExpandedImage, 2); reduce_domain(ExpandedImage, ROI, ®ion_tai); //*=================================================================== //*找黑色划痕与污点 mean_image(region_tai, &BlackImageMean, m_Parameters.BlackMaskSize, m_Parameters.BlackMaskSize); //*找大范围黑缺陷,适用于缺陷浅以及数量比较多的情况,参数越细,误报越高 dyn_threshold(region_tai, BlackImageMean, &BlackPointDynThresh,m_Parameters.BlackPointDynThresh, "dark"); select_shape(BlackPointDynThresh, &BLACK_POINT, "area", "and", m_Parameters.BlackPointSize, 99999); count_obj(BLACK_POINT, &Number); if (Number) { //pData->m_ErrorRegist = BLACK_POINT; pData->m_isFail =true; testItem->m_bFailSubTest = true; //testItem->m_ErrorMsg = "BlackPoint error"; //return; if (pData->m_isDebug) { dilation_circle(BLACK_POINT,&Dilation,2.5); set_color(pData->m_ShowHWindow,"red"); disp_obj(Dilation,pData->m_ShowHWindow); } } //*找单一块极黑缺陷,适用于伤的比较深,污点比较黑的情况 dyn_threshold(region_tai, BlackImageMean, &SeriousBlackPointDynThresh,m_Parameters.SeriousBlackPointDynThresh, "dark"); connection(SeriousBlackPointDynThresh, &SeriousBlackConnected); select_shape(SeriousBlackConnected, &SERIOUS_BlackPoint, "area", "and",m_Parameters.SeriousBlackPointSize, 99999); count_obj(SERIOUS_BlackPoint, &Number); if (Number) { pData->m_isFail =true; testItem->m_bFailSubTest = true; if (pData->m_isDebug) { dilation_circle(SERIOUS_BlackPoint,&Dilation,2.5); set_color(pData->m_ShowHWindow,"red"); disp_obj(Dilation,pData->m_ShowHWindow); } } //*=================================================================== //*找白色划痕与污点 mean_image(region_tai, &WhiteImageMean, m_Parameters.WhiteMaskSize, m_Parameters.WhiteMaskSize); //*找大范围白缺陷 dyn_threshold(region_tai, WhiteImageMean, &WhitePointDynThresh, m_Parameters.WhitePointDynThresh, "light"); select_shape(WhitePointDynThresh, &WHITE_POINT, "area", "and", m_Parameters.WhitePointSize, 99999); count_obj(WHITE_POINT, &Number); if (Number) { //pData->m_ErrorRegist = WHITE_POINT; pData->m_isFail =true; testItem->m_bFailSubTest = true; //testItem->m_ErrorMsg = "WhitePoint error"; if (pData->m_isDebug) { dilation_circle(WHITE_POINT,&Dilation,2.5); set_color(pData->m_ShowHWindow,"yellow"); disp_obj(Dilation,pData->m_ShowHWindow); } } //*找单一块极白污点 dyn_threshold(region_tai, WhiteImageMean, &SeriousWhitePointDynThresh, m_Parameters.SeriousWhitePointDynThresh, "light"); connection(SeriousWhitePointDynThresh, &SeriousWhiteConnected); select_shape(SeriousWhiteConnected, &SERIOUS_WhitePoint, "area", "and",m_Parameters.SeriousWhitePointSize, 99999); count_obj(SERIOUS_WhitePoint, &Number); if (Number) { //pData->m_ErrorRegist = SERIOUS_WhitePoint; pData->m_isFail =true; testItem->m_bFailSubTest = true; //testItem->m_ErrorMsg = "SeriousWhitePoint error"; if (pData->m_isDebug) { dilation_circle(SERIOUS_WhitePoint,&Dilation,2.5); set_color(pData->m_ShowHWindow,"yellow"); disp_obj(Dilation,pData->m_ShowHWindow); } } Hobject RegionUnionBlack,RegionUnionWhite,RegionUnionWhole; union2(BLACK_POINT, SERIOUS_BlackPoint, &RegionUnionBlack); union2(WHITE_POINT, SERIOUS_WhitePoint, &RegionUnionWhite); union2(RegionUnionBlack, RegionUnionWhite, &RegionUnionWhole); //dilation_circle(RegionUnionWhole, &RegionDilation, 2.5); union2(RegionUnionWhole, pData->m_ErrorRegist, &RegionUnionWhole); pData->m_ErrorRegist=RegionUnionWhole; } catch (HException &except) { if (pData->m_isDebug) { set_color(pData->m_ShowHWindow,"green"); set_tposition( pData->m_ShowHWindow,25, 145); #ifdef _ENGLISH write_string(pData->m_ShowHWindow,"DynThreshed1.3 parameter values error,please re-adjust"); #else write_string(pData->m_ShowHWindow,"DynThreshed1.3程序参数值出错,请重新调节参数"); #endif } pData->m_isFail = true; testItem->m_bFailSubTest = true; } }
void CDoProcess::DoProcess(CMData* pData,SubTestResult *testItem) { try { Hobject FindImage,ImageReduced,EllipseObj; Hobject ModelRegions, ConnectedRegions, SelectedRegions,ModelImages,SelectedRegionsSize,RegionClosing,RegionUnion,RegionFillUp,RegionOpening; Hlong Contrast = m_Parameters.m_Contrast; HTuple Row2, Column2, Radius2; Hobject regional_Internal,regional_Out; get_image_size (pData->m_Image, &Column2, &Row2); gen_ellipse(&EllipseObj, Row2/2, Column2/2, 0, m_Parameters.LongAxis, m_Parameters.ShortAxis); if (ShowObject&&pData->m_isDebug) { set_color(pData->m_ShowHWindow,"yellow"); disp_obj(EllipseObj,pData->m_ShowHWindow); } reduce_domain(pData->m_Image, EllipseObj, &ImageReduced); inspect_shape_model(ImageReduced, &ModelImages, &ModelRegions, 1, Contrast); connection(ModelRegions, &ConnectedRegions); //**============================================================== // **选择区域这条更改,原来默认是700,现在我想改成可调的,我现在就设的40 select_shape(ConnectedRegions, &SelectedRegionsSize, "area", "and", m_Parameters.Select_Shape_Size, 99999); // ** 添加这句union1 closing_circle (SelectedRegionsSize, &RegionClosing, 400.5); union1(RegionClosing, &RegionUnion); fill_up (RegionUnion, &RegionFillUp); opening_circle (RegionFillUp, &RegionOpening, m_Parameters.OutlierRemover+0.5); Hlong TempNumber; count_obj(RegionOpening,&TempNumber); if (TempNumber<1) { pData->m_isFail = true; testItem->m_bFailSubTest = true; if (pData->m_isDebug) { set_color(pData->m_ShowHWindow,"green"); set_tposition( pData->m_ShowHWindow,120, 0); #ifdef _ENGLISH write_string(pData->m_ShowHWindow,"Shell center not found"); #else write_string(pData->m_ShowHWindow,"圆中心未找到"); #endif } //pData->m_center_x=50; //pData->m_center_y=50; //pData->r_real=40; //return; } //*============================================================== double CenterRow, CenterColumn, CenterRadius; smallest_circle(RegionOpening, &CenterRow, &CenterColumn, &CenterRadius); Hobject circle; if ((m_Parameters.XMin<CenterColumn)&&(CenterColumn<m_Parameters.XMax)&&(m_Parameters.YMin<CenterRow)&&(CenterRow<m_Parameters.YMax)&&(CenterRadius<m_Parameters.RMax)&&(CenterRadius>m_Parameters.RMin)) { pData->m_center_x=CenterColumn; pData->m_center_y=CenterRow; pData->r_real=CenterRadius; set_color(pData->m_ShowHWindow,"cyan"); gen_circle(&circle, pData->m_center_y, pData->m_center_x, pData->r_real); disp_obj(circle,pData->m_ShowHWindow); } else { pData->m_isFail = true; testItem->m_bFailSubTest = true; pData->m_center_x=50; pData->m_center_y=50; pData->r_real=40; set_color(pData->m_ShowHWindow,"red"); gen_circle(&circle, pData->m_center_y, pData->m_center_x, pData->r_real); disp_obj(circle,pData->m_ShowHWindow); if (pData->m_isDebug) { set_color(pData->m_ShowHWindow,"green"); set_tposition( pData->m_ShowHWindow,5, 145); #ifdef _ENGLISH write_string(pData->m_ShowHWindow,"Fitted shell center not match the qualifications"); #else write_string(pData->m_ShowHWindow,"拟合得到的圆的中心坐标及半径与限定条件不符"); #endif } //return; } //set_color(pData->m_ShowHWindow,"red"); //Hobject circle,ContCircle; //gen_circle(&circle, pData->m_center_y, pData->m_center_x, pData->r_real); //disp_obj(circle,pData->m_ShowHWindow); } catch (HException &except) { if (pData->m_isDebug) { set_color(pData->m_ShowHWindow,"green"); set_tposition( pData->m_ShowHWindow,25, 145); #ifdef _ENGLISH write_string(pData->m_ShowHWindow,"CenterHC23 parameter values error,please re-adjust"); #else write_string(pData->m_ShowHWindow,"CenterHC23程序参数值出错,请重新调节参数"); #endif } pData->m_isFail = true; testItem->m_bFailSubTest = true; pData->m_center_x=50; pData->m_center_y=50; pData->r_real=40; } }
void CDoProcess::DoProcess(CMData* pData,SubTestResult *testItem) { // Local iconic variables Hobject Image=pData->m_Image; Hlong m_contrast_low1=m_Parameters.m_contrast_low; Hlong m_contrast_high1=m_Parameters.m_contrast_high; Hlong m_thred; ///////// if (m_contrast_low1>m_contrast_high1) { m_thred=m_contrast_low1; m_contrast_low1=m_contrast_high1; m_contrast_high1=m_thred; } if (m_Parameters.radius_inner>m_Parameters.radius_ext) { m_thred=m_Parameters.radius_inner; m_Parameters.radius_inner=m_Parameters.radius_ext; m_Parameters.radius_ext=m_thred; } Hobject Circle5, Circle6, RegionDifference_median,ModelContours; Hobject ImageReduced_median, Region_median, ConnectedRegions_median; Hobject SelectedRegions_median, RegionUnion_median, ImageReduced_median_extract; Hobject ModelImages, ModelRegions; // Local control variables HTuple Mean_median, Deviation_median; HTuple Area_baoChiJia, Row_baoChiJia, Column_baoChiJia; HTuple ModelID, Row2, Column2, Angle2, Score2; // Local control variables HTuple Row=pData->m_center_y; HTuple Column= pData->m_center_x; // dev_update_off(...); only in hdevelop try { ///Row_model_center = 237.659; //Column_model_center = 339.212; gen_circle(&Circle5, Row, Column,m_Parameters.radius_ext); gen_circle(&Circle6, Row, Column,m_Parameters.radius_inner); difference(Circle5, Circle6, &RegionDifference_median); reduce_domain(Image, RegionDifference_median, &ImageReduced_median); intensity(RegionDifference_median, Image, &Mean_median, &Deviation_median); fast_threshold(ImageReduced_median, &Region_median, m_Parameters.radius_inner_thred, 255, 1);//Mean_median*1.2 connection(Region_median, &ConnectedRegions_median); select_shape(ConnectedRegions_median, &SelectedRegions_median, "area", "and", m_Parameters.radius_ext_extract_size, 99999); union1(SelectedRegions_median, &RegionUnion_median); area_center(RegionUnion_median, &Area_baoChiJia, &Row_baoChiJia, &Column_baoChiJia); //创建模板时 保存区域和区域图片。在提取区域时,因为正常运行时每次都要用,不能使用 /*if (!_access(m_Parameters.CenterOcrModelRegion.c_str(),0)) { wstring msg = _T("Set Region already Exit.OverWrite or Not?"); if (MessageBox(NULL,msg.c_str(),_T("ReadFile Error"),MB_OK||MB_CANCELTRYCONTINUE)==IDOK) { write_region(RegionUnion_median,m_Parameters.CenterOcrModelRegion.c_str()); } } else*/ write_region(RegionUnion_median,m_Parameters.CenterOcrModelRegion.c_str()); reduce_domain(Image, RegionUnion_median, &ImageReduced_median_extract); //write_image(ImageReduced_median_extract, "bmp", 0, "D:/SLACTST/CH1.101/模板字符区域图片.bmp"); // /*if (!_access(m_Parameters.CenterOcrModelPicture.c_str(),0)) { wstring msg = _T("Set Picture already Exit.OverWrite or Not?"); if (MessageBox(NULL,msg.c_str(),_T("ReadFile Error"),MB_OK||MB_CANCELTRYCONTINUE)==IDOK) { write_image(ImageReduced_median_extract, "bmp", 0,m_Parameters.CenterOcrModelPicture.c_str()); } } else write_image(ImageReduced_median_extract, "bmp", 0,m_Parameters.CenterOcrModelPicture.c_str()); */ //匹配数据 inspect_shape_model(ImageReduced_median_extract, &ModelImages, &ModelRegions, 1, 25); create_shape_model(ImageReduced_median_extract, 4, 0, HTuple(360).Rad(), "auto", "auto", "use_polarity", m_contrast_high1, m_contrast_low1, &ModelID); find_shape_model(Image, ModelID, 0, HTuple(360).Rad(), 0.5, 1, 0.5, "least_squares", 0, 0.9, &Row2, &Column2, &Angle2, &Score2); /*if (!_access(m_Parameters.CenterOcrModelName.c_str(),0)) { wstring msg = _T("Set Model already Exit.OverWrite or Not?"); if (MessageBox(NULL,msg.c_str(),_T("ReadFile Error"),MB_OK||MB_CANCELTRYCONTINUE)==IDOK) { write_shape_model(ModelID,m_Parameters.CenterOcrModelName.c_str()); } } else*/ write_shape_model(ModelID,m_Parameters.CenterOcrModelName.c_str()); //*查看模板提取效果 set_shape_model_origin(ModelID, -Row_baoChiJia, -Column_baoChiJia); get_shape_model_contours(&ModelContours, ModelID, 1); /////////////////////////////////////////////////*/ // Number_QiPao=1; if (1) { //pData->m_isFail= false; //testItem->m_bFailSubTest = false; pData->m_center_y2=Row_baoChiJia[0].D(); pData->m_center_x2=Column_baoChiJia[0].D(); } else { //testItem->m_ErrorMsg = "Error No Find Center"; //testItem->m_ErrorY = 250; //testItem->m_ErrorX = 350; //testItem->m_ErrorR = 55; //set_color(pData->m_ShowHWindow,"red"); //disp_region(SelectedRegions_qiPao_extract,pData->m_ShowHWindow); //disp_circle(pData->m_ShowHWindow,Row_center,Column_center,85); } set_color(pData->m_ShowHWindow,"blue"); disp_obj(ModelContours,pData->m_ShowHWindow); set_color(pData->m_ShowHWindow,"green"); disp_region(RegionUnion_median,pData->m_ShowHWindow); disp_region(Circle5,pData->m_ShowHWindow); disp_region(Circle6,pData->m_ShowHWindow); set_color(pData->m_ShowHWindow,"red"); /////// } catch (HException &except) { pData->m_isFail = true; testItem->m_bFailSubTest = true; pData->m_orientationPhi=0; //testItem->m_ErrorMsg = except.file; //testItem->m_ErrorMsg += " "; //testItem->m_ErrorMsg += except.line; //testItem->m_ErrorMsg += " "; //testItem->m_ErrorMsg += except.message; testItem->m_ErrorY = 1; testItem->m_ErrorX = 1; testItem->m_ErrorR = 4; } }
void CDoProcess::DoProcess(CMData* pData,SubTestResult *testItem) { //适当添加查找模板的匹配参数以及匹配度参数 //float m_white_para=m_Parameters.thred_high/100.0; Hobject Image=pData->m_Image; Hobject Circle7, ImageReduced3; // Local control variables HTuple Row_define, Column_define,Angle_define, Score_define; //************** HTuple Row_center=pData->m_center_y; HTuple Column_center= pData->m_center_x; //HTuple Row_model_center ;//=pData->m_center_y2 //HTuple Column_model_center ;//=pData->m_center_x2 //HTuple m_model_area; try { //参数是否正确!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!修改模板提取函数,添加中心点保存(参数不能保存?) //area_center(m_Parameters.RegionDilation_model,&m_model_area,&Row_model_center,&Column_model_center); //缩小区域 匹配图案 gen_circle(&Circle7, Row_center, Column_center, m_Parameters.radius_detect); reduce_domain(Image, Circle7, &ImageReduced3); find_shape_model(ImageReduced3, m_Parameters.ModelID, 0, HTuple(360).Rad(), m_Parameters.Minscore, 1, 0.5, "least_squares", 4, m_Parameters.Match_Greediness, &Row_define, &Column_define, &Angle_define, &Score_define); // Hlong length; tuple_length(Angle_define,&length); if(0==length) { pData->m_isFail =true; testItem->m_bFailSubTest = true; #ifdef _ENGLISH set_color(pData->m_ShowHWindow,"red"); HTuple msg = HTuple("Matching Fail"); set_tposition( pData->m_ShowHWindow, 55, 200); write_string(pData->m_ShowHWindow,msg); #else set_color(pData->m_ShowHWindow,"red"); HTuple msg = HTuple("匹配失败"); set_tposition( pData->m_ShowHWindow, 55, 200); write_string(pData->m_ShowHWindow,msg); #endif return; } //添加判断,满足条件时,再检测//图案中心点不一定是瓶盖中心点 //if (Score_define>0.65) //{ //set_color(pData->m_ShowHWindow,"green"); // disp_obj(ImageEmphasize_no_ocr, pData->m_ShowHWindow); // set_color(pData->m_ShowHWindow,"red"); // disp_obj(SelectedRegions_detect, pData->m_ShowHWindow); // 匹配位置 pData->m_center_x3=Column_define[0].D(); pData->m_center_y3=Row_define[0].D(); pData->m_orientationPhi3=Angle_define[0].D(); // // } // else // { // pData->m_isFail = true; // testItem->m_bFailSubTest = true; //} if (ShowObject) { set_color(pData->m_ShowHWindow,"green"); disp_obj(Circle7, pData->m_ShowHWindow); set_color(pData->m_ShowHWindow,"red"); } } catch (HException &except) { pData->m_isFail = true; testItem->m_bFailSubTest = true; /*//testItem->m_ErrorMsg = except.file; //testItem->m_ErrorMsg += " "; //testItem->m_ErrorMsg += except.line; //testItem->m_ErrorMsg += " "; //testItem->m_ErrorMsg += except.message; testItem->m_ErrorY = 1; testItem->m_ErrorX = 1; testItem->m_ErrorR = 4;*/ if (pData->m_isDebug) { set_tposition( pData->m_ShowHWindow, 55, 230); #ifdef _ENGLISH write_string(pData->m_ShowHWindow,"MatchingParaDefineDll parameter values error,please re-adjust"); #else write_string(pData->m_ShowHWindow,"MatchingParaDefineDll程序参数设置出错!"); #endif } } }
void CDoProcess::DoProcess(CMData* pData,SubTestResult *testItem) { Hlong m_radius_inner=m_Parameters.radius_inner; Hlong m_radius_ext=m_Parameters.radius_ext; Hlong m_thred; // dev_update_off(...); only in hdevelop //Hobject Image=pData->m_Image; ///////// if (m_Parameters.radius_inner>m_Parameters.radius_ext) { m_thred=m_Parameters.radius_inner; m_Parameters.radius_inner=m_Parameters.radius_ext; m_Parameters.radius_ext=m_thred; } if (m_Parameters.radius_inner2>m_Parameters.radius_ext2) { m_thred=m_Parameters.radius_inner2; m_Parameters.radius_inner2=m_Parameters.radius_ext2; m_Parameters.radius_ext2=m_thred; } // Local iconic variables Hobject Image=pData->m_Image; // Local iconic variables Hobject Circle1, Circle2, RegionDifference_ext; Hobject Circle3, Circle4, RegionDifference_inner, ImageReduced_ext; Hobject ImageReduced_inner, ImageEmphasize_inner, ImageEmphasize_ext; Hobject Region_ext, Region_inner, RegionUnion, ConnectedRegions; Hobject SelectedRegions; // Local control variables HTuple Mean_ext, Deviation_ext; HTuple Mean_inner, Deviation_inner, Number; // Local control variables try { HTuple Row=pData->m_center_y; HTuple Column= pData->m_center_x; if (pData->m_isFail ) { Row=250; Column=330; } gen_circle(&Circle1, Row, Column, m_Parameters.radius_ext); gen_circle(&Circle2, Row, Column, m_Parameters.radius_inner); difference(Circle1, Circle2, &RegionDifference_ext); gen_circle(&Circle3, Row, Column,m_Parameters.radius_ext2); gen_circle(&Circle4, Row, Column, m_Parameters.radius_inner2); difference(Circle3, Circle4, &RegionDifference_inner); ////////////////////////// set_color(pData->m_ShowHWindow,"green"); disp_region(Circle1,pData->m_ShowHWindow); disp_region(Circle2,pData->m_ShowHWindow); disp_region(Circle3,pData->m_ShowHWindow); disp_region(Circle4,pData->m_ShowHWindow); set_color(pData->m_ShowHWindow,"red"); /////////////////////////////// reduce_domain(Image, RegionDifference_ext, &ImageReduced_ext); reduce_domain(Image, RegionDifference_inner, &ImageReduced_inner); //*端面检测************** emphasize(ImageReduced_inner, &ImageEmphasize_inner, m_Parameters.radius_ext_empha_size, m_Parameters.radius_ext_empha_size, m_Parameters.radius_inner2_enhance); emphasize(ImageReduced_ext, &ImageEmphasize_ext, m_Parameters.radius_ext_empha_size, m_Parameters.radius_ext_empha_size, m_Parameters.radius_inner2_enhance); intensity(RegionDifference_ext, Image, &Mean_ext, &Deviation_ext); intensity(RegionDifference_inner, Image, &Mean_inner, &Deviation_inner); threshold(ImageEmphasize_ext, &Region_ext, 0,m_Parameters.radius_ext2_thred );//Mean_ext-30 fast_threshold(ImageReduced_inner, &Region_inner, 0,m_Parameters.radius_ext2_thred , 1);//Mean_inner-30 union2(Region_ext, Region_inner, &RegionUnion); connection(RegionUnion, &ConnectedRegions); select_shape(ConnectedRegions, &SelectedRegions, "area", "and", m_Parameters.ARMin, 99999); count_obj(SelectedRegions, &Number); /////////////////////////////////////////////////*/ // Number_QiPao=1; if ((Number<=0)) { ; //pData->m_isFail= false; //testItem->m_bFailSubTest = false; } else { pData->m_isFail = true; testItem->m_bFailSubTest = true; //testItem->m_ErrorMsg = "Error No Find Center"; //testItem->m_ErrorY = 250; //testItem->m_ErrorX = 350; //testItem->m_ErrorR = 55; set_color(pData->m_ShowHWindow,"red"); disp_region(SelectedRegions,pData->m_ShowHWindow); //disp_circle(pData->m_ShowHWindow,Row,Column,85); } } catch (HException &except) { pData->m_isFail = true; testItem->m_bFailSubTest = true; //testItem->m_ErrorMsg = except.file; //testItem->m_ErrorMsg += " "; //testItem->m_ErrorMsg += except.line; //testItem->m_ErrorMsg += " "; //testItem->m_ErrorMsg += except.message; testItem->m_ErrorY = 1; testItem->m_ErrorX = 1; testItem->m_ErrorR = 4; } }