Example of measuring screws wire nails Measure_screw notes
Last Update:2018-07-26
Source: Internet
Author: User
* This program inspects the dimensions of a screw
*
Dev_update_off ()
* Screws Grain measurement
* Step:acquire Image
*
Read_image (image, ' Screw_thread ')
Get_image_pointer1 (image, Pointer, Type, Width, Height)
Dev_close_window ()
Dev_open_window (0, 0, WIDTH/2, HEIGHT/2, ' light gray ', windowid)
Dev_set_part (0, 0, Height-1, Width-1)
Dev_set_line_width (2)
Dev_set_color (' Blue ')
Dev_set_draw (' margin ')
Dev_display (Image)
Set_display_font (Windowid, +, ' courier ', ' true ', ' false ')
Disp_continue_message (Windowid, ' black ', ' true ')
Stop ()
*
* Step:initialize Visualization
*
Dev_set_draw (' Fill ')
Dev_set_line_width (2)
Dev_set_color (' black ')
*
* Step:get orientation via region processing
*
* Binary Value
Threshold (Image, region, 0, 100)
* Regional Direction
Orientation_region (region, Orientationregion)
* Regional center point and area
Area_center (region, area, Rowcenter, Columncenter)
*
* Step:rotate screw region to become vertical
* Transform the target into a positive
Vector_angle_to_rigid (Rowcenter, Columncenter, Orientationregion, Rowcenter, Columncenter, Rad), HomMat2DRotate)
Affine_trans_region (Region, Regionaffinetrans, Hommat2drotate, ' false ')
Dev_clear_window ()
Disp_message (Windowid, ' Region (transformed) ', ' window ',-1,-1, ' black ', ' false ')
Dev_display (Regionaffinetrans)
Disp_continue_message (Windowid, ' black ', ' true ')
Stop ()
*
* Step:get width of the screw via region processing
*
* Closed operation, the function of filling
Closing_circle (Regionaffinetrans, regiontoprocess, 4.5)
Dev_clear_window ()
Disp_message (Windowid, ' Region (transformed) ', ' window ',-1,-1, ' black ', ' false ')
Dev_display (regiontoprocess)
* Query the scan width code of an area, return each row corresponding to the column start Columnbegin and end point Columnend, the row is stored in rowregionruns
Get_region_runs (regiontoprocess, Rowregionruns, Columnbegin, Columnend)
Numberlines: = | rowregionruns|
* Take the middle area.
columnbeginselected: = columnbegin[90: (NumberLines-90)]
columnendselected: = columnend[90: (NumberLines-90)]
* Length
Diameter: = columnendselected-columnbeginselected+1
*
* Statistics
* Average
Meandiameter: = Mean (Diameter)
* Minimum value
Mindiameter: = min (Diameter)
* Maximum Value
Maxdiameter: = Max (Diameter)
*
* Visualization
Dev_set_color (' white ')
Gen_region_line (ScanLine1, rowregionruns[90], columnbegin[90], rowregionruns[90], columnend[90])
Gen_region_line (ScanLine2, rowregionruns[numberlines-90], columnbegin[numberlines-90], rowregionruns[ NUMBERLINES-90], columnend[numberlines-90])
Dev_display (SCANLINE1)
Dev_display (ScanLine2)
Disp_cross (Windowid, rowregionruns[90], columnbegin[90], 20, 0)
Disp_cross (Windowid, rowregionruns[90], columnend[90], 20, 0)
Disp_cross (Windowid, rowregionruns[numberlines-90], columnbegin[numberlines-90], 20, 0)
Disp_cross (Windowid, rowregionruns[numberlines-90], columnend[numberlines-90], 20, 0)
Disp_message (Windowid, ' Width of object ', ' image ', ten, 720, ' black ', ' false ')
Disp_message (Windowid, ' per row (between ', ' image ', Max, 720, ' black ', ' false ')
Disp_message (Windowid, ' The White Lines): ', ' image ', ' A ', ' 720 ', ' black ', ' false ')
Disp_message (Windowid, ' mean width: ' +meandiameter + ' pixels ', ' image ',, 720, ' black ', ' false ')
Disp_message (Windowid, ' minimum width: ' +mindiameter + ' pixels ', ' image ', 260, 720, ' black ', ' false ')
Disp_message (Windowid, ' Maximum width: ' +maxdiameter + ' pixels ', ' image ', 310, 720, ' black ', ' false ')
Disp_continue_message (Windowid, ' black ', ' true ')
Stop ()
*
* Step:get transformed contours and corresponding regression lines
*
* Create ROI
Sub-pixel Contour method calculation **********************
* Border
Boundary (region, Regionborder, ' inner_filled ')
* Expansion
Dilation_circle (Regionborder, regiondilation, 7.5)
* Cut Pictures
Reduce_domain (Image, regiondilation, imagereduced)
Dev_clear_window ()
Dev_display (imagereduced)
Disp_message (Windowid, ' ROI for contour extraction ', ' windows ',-1,-1, ' White ', ' false ')
Disp_continue_message (Windowid, ' black ', ' true ')
Stop ()
*
* Extract contours and regression lines using Laplace
Sigma: = 3
* Gaussian derivative filter used as smoothing filter (using watershed algorithm watershed to get contours)
Derivate_gauss (imagereduced, Derivgauss, Sigma, ' Laplace ')
* Extract 0 intersections from an image based on subpixel accuracy
Zero_crossing_sub_pix (Derivgauss, Edges)
* Select Xld
Select_contours_xld (Edges, selectededges, ' contour_length ', 3000, 99999,-0.5, 0.5)
* Transform
Affine_trans_contour_xld (Selectededges, Contoursaffintrans, Hommat2drotate)
* Calculate the bounding rectangle of each area's coordinates (Continuous/column)
Smallest_rectangle1_xld (Contoursaffintrans, ROW11, Column11, Row21, Column21)
* Shear XLD
Clip_contours_xld (Contoursaffintrans, clippedcontours, row11+90, 0, row21-90, Width)
* Straight line segment Contour fitting line
FIT_LINE_CONTOUR_XLD (clippedcontours, ' regression ',-1, 0, 5, 2, Rowbegin, Colbegin, Rowend, Colend, Nr, Nc, Dist1)
Dev_clear_window ()
Dev_display (clippedcontours)
Disp_message (Windowid, ' contours (transformed and clipped) ', ' window ',-1,-1, ' black ', ' false ')
Disp_continue_message (Windowid, ' black ', ' true ')
Stop ()
*
* Step:get deviations of the contours from the regression lines
*
* Generate Right XLD segment
GEN_CONTOUR_POLYGON_XLD (RegressContour0, [rowbegin[0], rowend[0]], [colbegin[0], colend[0]])
* Select Right Object
Select_obj (Clippedcontours, EdgeContour0, 1)
* Query Xld coordinate points
Get_contour_xld (EdgeContour0, ROWEDGE0, COLEDGE0)
* Calculates the maximum minimum value with the edge, average.
DISTANCE_PC (RegressContour0, RowEdge0, ColEdge0, DistanceMin0, DistanceMax0)
MinDistance0: = min (DistanceMin0)
MaxDistance0: = Max (DistanceMin0)
MeanDistance0: = Mean (DistanceMin0)
*
GEN_CONTOUR_POLYGON_XLD (RegressContour1, [rowbegin[1], rowend[1]], [colbegin[1], colend[1]])
Select_obj (Clippedcontours, EDGECONTOUR1, 2)
Get_contour_xld (EdgeContour1, RowEdge1, ColEdge1)
DISTANCE_PC (RegressContour1, RowEdge1, ColEdge1, DistanceMin1, DISTANCEMAX1)
MinDistance1: = min (DistanceMin1)
MaxDistance1: = Max (DistanceMin1)
MeanDistance1: = Mean (DistanceMin1)
Dev_clear_window ()
*
* Numerical visualization
Dev_set_color (' Gray ')
Dev_display (EDGECONTOUR0)
Dev_display (EDGECONTOUR1)
Dev_set_color (' black ')
Disp_message (Windowid, ' contours (transformed and clipped) ', ' image ', ten, ' black ', ' false ')
Dev_display (REGRESSCONTOUR0)
Dev_display (REGRESSCONTOUR1)
Disp_message (Windowid, ' Maximum distances ', ' image ', ten, 720, ' black ', ' false ')
Disp_message (Windowid, ' between contours ', ' image ', ' 720 ', ' black ', ' false ')
Disp_message (Windowid, ' and regression lines: ', ' image ', ' A ', ' 720 ', ' black ', ' false ')
*
Disp_message (Windowid, ' Max (Contour/edge 0): ', ' image ', 720, ' black ', ' false ')
Disp_message (Windowid, maxdistance0$ '. 4 ' + ' pixels ', ' image ', 260, 720, ' black ', ' false ')
*
Disp_message (Windowid, ' Max (Contour/edge 1): ', ' image ', 720, ' black ', ' false ')
Disp_message (Windowid, maxdistance1$ '. 4 ' + ' pixels ', ' image ', 410, 720, ' black ', ' false ')
*
Disp_message (Windowid, ' 0 ', ' image ', rowend[0] +, colend[0]-9, ' black ', ' false ')
Disp_message (Windowid, ' 1 ', ' image ', rowend[0] +, colend[0]-9, ' black ', ' false ')
*
* Graphical visualization in Zoom window
Dev_set_color (' white ')
Dev_set_draw (' margin ')
Gen_rectangle1 (RECTANGLE1, 500, 620, 550, 680)
Dev_display (Rectangle1)
Dev_open_window (0, width/2+2, +, ' light gray ', windowhandlezoom)
Dev_set_part (500, 620, 550, 680)
Dev_set_color (' black ')
Dev_display (EDGECONTOUR0)
Dev_display (REGRESSCONTOUR0)
Get_contour_xld (RegressContour0, RowContour0, ColContour0)
For I: = 950 by 1
PROJECTION_PL (Rowedge0[i], coledge0[i], rowcontour0[0], colcontour0[0], rowcontour0[1], colcontour0[1], RowProj0, COLPROJ0)
GEN_CONTOUR_POLYGON_XLD (contour, [rowedge0[i], RowProj0], [Coledge0[i], ColProj0])
Dev_display (Contour)
ENDfor
Disp_continue_message (Windowid, ' black ', ' true ')
Stop ()
Dev_close_window ()
Dev_set_window (Windowid)
*
* Step:get distance between the regression lines
*
DISTANCE_PP (Rowbegin[1], colbegin[1], rowend[0], colend[0], Distance1)
DISTANCE_PP (Rowbegin[0], colbegin[0], rowend[1], colend[1], Distance2)
if (ABS (DISTANCE1-DISTANCE2) <1)
*
* Visualization
Dev_clear_window ()
Dev_set_color (' Gray ')
Dev_display (EDGECONTOUR0)
Dev_display (EDGECONTOUR1)
Dev_set_color (' black ')
Disp_message (Windowid, ' contours (transformed and clipped) ', ' image ',-1,-1, ' black ', ' false ')
Dev_display (REGRESSCONTOUR0)
Dev_display (REGRESSCONTOUR1)
Disp_message (Windowid, ' Mean distance ', ' image ', ten, 720, ' black ', ' false ')
Disp_message (Windowid, ' between regression ', ' image ', ' 720 ', ' black ', ' false ')
Disp_message (Windowid, ' lines: ', ' image ', ' 720 ', ' black ', ' false ')
Disp_message (Windowid, ((DISTANCE1+DISTANCE2)/2) $ '. 4 ' + ' pixels ', ' image ',, 720, ' black ', ' false ')
Dev_set_draw (' Fill ')
Dev_set_color (' white ')
Disp_arrow (Windowid, rowend[1] +100, colend[1], rowbegin[0] +100, colbegin[0], 2)
Disp_arrow (Windowid, rowbegin[0] +100, colbegin[0], rowend[1] +100, colend[1], 2)
Else
Dev_set_color (' black ')
Disp_message (Windowid, ' contours (transformed and clipped) ', ' image ',-1,-1, ' black ', ' false ')
Dev_display (REGRESSCONTOUR0)
Dev_display (REGRESSCONTOUR1)
Disp_message (Windowid, ' regresscontours ', ' image ', ten, 720, ' black ', ' false ')
Disp_message (Windowid, ' is not parallel ', ' image ', ' 720 ', ' black ', ' false ')
endif