目录
原图
矫正后的图像
编辑
示例代码
原图
矫正后的图像
示例代码
找ROI部分代码暂无法分享
HomMat2DInvert := []Row_T := []Col_T := []region_features (ROI, 'rectangularity', Value)if (Value > RectY)HomMat2DInvert := []smallest_rectangle1 (ROI, Row_T, Col_T, Row2, Column2)reduce_domain (Image, ROI, ImageReduced)crop_domain (ImageReduced, ImagePart)move_region (ROI, ROIM, -Row_T, -Col_T)else* 矫正boundary (ROI, RegionBorder, 'inner')gen_contour_region_xld (RegionBorder, Contours, 'border')segment_contours_xld (Contours, ContoursSplit, 'lines', 15, 4, 2)area_center (ROI, Area, Row, Column)select_shape_xld (ContoursSplit, XLD1, 'rect2_phi', 'and', rad(-20), rad(20))* 标记UT := 0DT := 0LT := 0RT := 0* 上select_shape_xld (XLD1, XLD, 'row1', 'and', -1, Row)length_xld (XLD, Length)tuple_median (Length, Median)select_shape_xld (XLD, XLD, 'contlength', 'and', max2(200,Median), 999999999)count_obj (XLD, Num)if (Num == 1)copy_obj (XLD, XLDUp, 1, 1)fit_line_contour_xld (XLDUp, 'tukey', -1, 0, 5, 2, RowBeginUp, ColBeginUp, RowEndUp, ColEndUp, Nr, Nc, Dist)elseUT := 1sort_contours_xld (XLD, SortedContours, 'upper_left', 'true', 'column')select_obj (SortedContours, XLDUp_1, 1)select_obj (SortedContours, XLDUp_2, Num)fit_line_contour_xld (XLDUp_1, 'tukey', -1, 0, 5, 2, RowBeginUp1, ColBeginUp1, RowEndUp1, ColEndUp1, Nr, Nc, Dist)fit_line_contour_xld (XLDUp_2, 'tukey', -1, 0, 5, 2, RowBeginUp2, ColBeginUp2, RowEndUp2, ColEndUp2, Nr, Nc, Dist)endif* 下select_shape_xld (XLD1, XLD, 'row1', 'and', Row, Row*3)length_xld (XLD, Length)tuple_median (Length, Median)select_shape_xld (XLD, XLD, 'contlength', 'and', max2(200,Median), 999999999)count_obj (XLD, Num)if (Num == 1)copy_obj (XLD, XLDDown, 1, 1)fit_line_contour_xld (XLDDown, 'tukey', -1, 0, 5, 2, RowBeginDown, ColBeginDown, RowEndDown, ColEndDown, Nr, Nc, Dist)elseDT := 1sort_contours_xld (XLD, SortedContours, 'upper_left', 'true', 'column')select_obj (SortedContours, XLDDown_1, 1)select_obj (SortedContours, XLDDown_2, Num)fit_line_contour_xld (XLDDown_1, 'tukey', -1, 0, 5, 2, RowBeginDown1, ColBeginDown1, RowEndDown1, ColEndDown1, Nr, Nc, Dist)fit_line_contour_xld (XLDDown_2, 'tukey', -1, 0, 5, 2, RowBeginDown2, ColBeginDown2, RowEndDown2, ColEndDown2, Nr, Nc, Dist)endifselect_shape_xld (ContoursSplit, XLD1, ['rect2_phi','rect2_phi'], 'or', [rad(70),rad(-110)], [rad(110),rad(-70)])* 左select_shape_xld (XLD1, XLD, 'column1', 'and', -1, Column)length_xld (XLD, Length)tuple_median (Length, Median)select_shape_xld (XLD, XLD, 'contlength', 'and', max2(200,Median), 999999999)count_obj (XLD, Num)if (Num == 1)copy_obj (XLD, XLDLeft, 1, 1)fit_line_contour_xld (XLDLeft, 'tukey', -1, 0, 5, 2, RowBeginLeft, ColBeginLeft, RowEndLeft, ColEndLeft, Nr, Nc, Dist)elseLT := 1sort_contours_xld (XLD, SortedContours, 'upper_left', 'true', 'row')select_obj (SortedContours, XLDLeftUp, 1)select_obj (SortedContours, XLDLeftDown, Num)fit_line_contour_xld (XLDLeftUp, 'tukey', -1, 0, 5, 2, RowBeginLeft1, ColBeginLeft1, RowEndLeft1, ColEndLeft1, Nr, Nc, Dist)fit_line_contour_xld (XLDLeftDown, 'tukey', -1, 0, 5, 2, RowBeginLeft2, ColBeginLeft2, RowEndLeft2, ColEndLeft2, Nr, Nc, Dist)endif* 右select_shape_xld (XLD1, XLD, 'column1', 'and', Column, Column*3)length_xld (XLD, Length)tuple_median (Length, Median)select_shape_xld (XLD, XLD, 'contlength', 'and', max2(200,Median), 999999999)count_obj (XLD, Num)if (Num == 1)copy_obj (XLD, XLDRight, 1, 1)fit_line_contour_xld (XLDRight, 'tukey', -1, 0, 5, 2, RowBeginRight, ColBeginRight, RowEndRight, ColEndRight, Nr, Nc, Dist)elseRT := 1sort_contours_xld (XLD, SortedContours, 'upper_left', 'true', 'row')select_obj (SortedContours, XLDRight_1, 1)select_obj (SortedContours, XLDRight_2, Num)fit_line_contour_xld (XLDRight_1, 'tukey', -1, 0, 5, 2, RowBeginRight1, ColBeginRight1, RowEndRight1, ColEndRight1, Nr, Nc, Dist)fit_line_contour_xld (XLDRight_2, 'tukey', -1, 0, 5, 2, RowBeginRight2, ColBeginRight2, RowEndRight2, ColEndRight2, Nr, Nc, Dist)endif* 左上if (UT == 1)if (LT == 1)intersection_lines (RowBeginUp1, ColBeginUp1, RowEndUp1, ColEndUp1, RowBeginLeft1, ColBeginLeft1, RowEndLeft1, ColEndLeft1, LURow, LUCol, IsOverlapping)elseintersection_lines (RowBeginUp1, ColBeginUp1, RowEndUp1, ColEndUp1, RowBeginLeft, ColBeginLeft, RowEndLeft, ColEndLeft, LURow, LUCol, IsOverlapping)endifelseif (LT == 1)intersection_lines (RowBeginUp, ColBeginUp, RowEndUp, ColEndUp, RowBeginLeft1, ColBeginLeft1, RowEndLeft1, ColEndLeft1, LURow, LUCol, IsOverlapping)elseintersection_lines (RowBeginUp, ColBeginUp, RowEndUp, ColEndUp, RowBeginLeft, ColBeginLeft, RowEndLeft, ColEndLeft, LURow, LUCol, IsOverlapping)endifendif* 左下if (LT == 1)if (DT == 1)intersection_lines (RowBeginLeft2, ColBeginLeft2, RowEndLeft2, ColEndLeft2, RowBeginDown1, ColBeginDown1, RowEndDown1, ColEndDown1, LDRow, LDCol, IsOverlapping)elseintersection_lines (RowBeginLeft2, ColBeginLeft2, RowEndLeft2, ColEndLeft2, RowBeginDown, ColBeginDown, RowEndDown, ColEndDown, LDRow, LDCol, IsOverlapping)endifelseif (DT == 1)intersection_lines (RowBeginLeft, ColBeginLeft, RowEndLeft, ColEndLeft, RowBeginDown1, ColBeginDown1, RowEndDown1, ColEndDown1, LDRow, LDCol, IsOverlapping)elseintersection_lines (RowBeginLeft, ColBeginLeft, RowEndLeft, ColEndLeft, RowBeginDown, ColBeginDown, RowEndDown, ColEndDown, LDRow, LDCol, IsOverlapping)endifendif* 右下if (DT == 1)if (RT == 1)intersection_lines (RowBeginDown2, ColBeginDown2, RowEndDown2, ColEndDown2, RowBeginRight2, ColBeginRight2, RowEndRight2, ColEndRight2, RDRow, RDCol, IsOverlapping)elseintersection_lines (RowBeginDown2, ColBeginDown2, RowEndDown2, ColEndDown2, RowBeginRight, ColBeginRight, RowEndRight, ColEndRight, RDRow, RDCol, IsOverlapping)endifelseif (RT == 1)intersection_lines (RowBeginDown, ColBeginDown, RowEndDown, ColEndDown, RowBeginRight2, ColBeginRight2, RowEndRight2, ColEndRight2, RDRow, RDCol, IsOverlapping)elseintersection_lines (RowBeginDown, ColBeginDown, RowEndDown, ColEndDown, RowBeginRight, ColBeginRight, RowEndRight, ColEndRight, RDRow, RDCol, IsOverlapping)endifendif* 右上if (UT == 1)if (RT == 1)intersection_lines (RowBeginUp2, ColBeginUp2, RowEndUp2, ColEndUp2, RowBeginRight1, ColBeginRight1, RowEndRight1, ColEndRight1, RURow, RUCol, IsOverlapping)elseintersection_lines (RowBeginUp2, ColBeginUp2, RowEndUp2, ColEndUp2, RowBeginRight, ColBeginRight, RowEndRight, ColEndRight, RURow, RUCol, IsOverlapping)endifelseif (RT == 1)intersection_lines (RowBeginUp, ColBeginUp, RowEndUp, ColEndUp, RowBeginRight1, ColBeginRight1, RowEndRight1, ColEndRight1, RURow, RUCol, IsOverlapping)elseintersection_lines (RowBeginUp, ColBeginUp, RowEndUp, ColEndUp, RowBeginRight, ColBeginRight, RowEndRight, ColEndRight, RURow, RUCol, IsOverlapping)endifendif* 左上 左下 右下 右上RP := [LURow,LDRow,RDRow,RURow]CP := [LUCol,LDCol,RDCol,RUCol]gen_cross_contour_xld (Cross, RP, CP, 20, 0.785398)* 上边长distance_pp (LURow, LUCol, RURow, RUCol, DistUp)* 下边长distance_pp (LDRow, LDCol, RDRow, RDCol, DistDown)* 左边长distance_pp (LURow, LUCol, LDRow, LDCol, DistLeft)* 右边长distance_pp (RURow, RUCol, RDRow, RDCol, DistRight)Hei := (DistLeft + DistRight)/2.0Wid := (DistUp + DistDown)/2.0RQ := [0,Hei,Hei,0]CQ := [0,0,Wid,Wid]Xabs := abs(DistUp - DistDown)Yabs := abs(DistLeft - DistRight)if (abs(DistUp - DistDown) >= 20 or abs(DistLeft - DistRight) >= 20)hom_vector_to_proj_hom_mat2d (RP, CP, [1,1,1,1], RQ, CQ, [1,1,1,1], 'normalized_dlt', HomMat2D)projective_trans_image (Image, ImageP, HomMat2D, 'bilinear', 'false', 'false')projective_trans_region (ROI, ROIP, HomMat2D, 'bilinear')hom_mat2d_invert (HomMat2D, HomMat2DInvert)smallest_rectangle1 (ROIP, Row_T, Col_T, Row2, Column2)reduce_domain (ImageP, ROIP, ImageReduced)crop_domain (ImageReduced, ImagePart)move_region (ROIP, ROIM, -Row_T, -Col_T)elseHomMat2DInvert := []smallest_rectangle1 (ROI, Row_T, Col_T, Row2, Column2)reduce_domain (Image, ROI, ImageReduced)crop_domain (ImageReduced, ImagePart)move_region (ROI, ROIM, -Row_T, -Col_T)endif