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; }
bool gvVisionImage_botcap_front::_insp_loc( Hobject image_src, Hobject *outRegion_loc) { // Local iconic variables Hobject ImageMean, region_thre, region_fillup; Hobject region_erosion, region_dilation, region_conn, region_sel; // Local control variables Hlong numRegions; gen_empty_obj(&(*outRegion_loc)); mean_image(image_src, &ImageMean, 31, 31); dyn_threshold(image_src, ImageMean, ®ion_thre, 5, "light"); fill_up(region_thre, ®ion_fillup); erosion_circle(region_fillup, ®ion_erosion, 5.5); dilation_circle(region_erosion, ®ion_dilation, 5.5); connection(region_dilation, ®ion_conn); select_shape(region_conn, ®ion_sel, "area", "and", m_minarea, 999999); count_obj(region_sel, &numRegions); if ( 1 == numRegions ) { disp_obj(ho_Image,hl_WindowID); disp_obj(region_sel,hl_WindowID); copy_obj(region_sel, &(*outRegion_loc), 1, 1); return true; } return false; }
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; } }
int main(int argc, char *argv[]) { sequence *seq; /* pointer to input sequence data structure */ image **imgs; /* pointer to input sequence array of images */ image *out; /* pointer the output image */ char seq_in[100], /* input sequence name */ seq_out[100], /* output sequence name */ file_out[100]; /* output file name */ int length; /* length of the sequence */ int i; /* loop index */ /* Process input arguments */ if(argc != 3) { fprintf(stderr,"Usage: %s [input PGM sequence name] [output PGM sequence name]\n", argv[0]); exit(0); } else { strcpy(seq_in, argv[1]); strcpy(seq_out, argv[2]); } /* Load the input sequence */ seq = load_sequence(seq_in); /* Get a pointer to the sequence images */ imgs = get_sequence_images(seq); /* Get sequence length */ length = get_sequence_length(seq); /* Check if sequence is long enough */ if(length < 2) { fprintf(stderr, "sequence is too short\n"); exit(1); } /* Clone the first image to store results */ out = clone_image(imgs[0]); /* Loop through the sequence and write the mean sequence */ /* i.e. for each image of the input sequence, write the image */ /* resulting from the mean between the current image and */ /* the next one. */ for(i = 0; i < length - 1; i++) { /* Compute the mean between the current picture and the next one */ mean_image(imgs[i], imgs[i+1], out); /* Now write out the output image */ sprintf(file_out, "%s%03d.pgm", seq_out, i); printf("Writing out %s\n",file_out); pgm_write_image(out, file_out); } /* We must deallocate the memory the sequence and for the image before */ /* we finish */ free_image(out); free_sequence(seq); return(EXIT_SUCCESS); }