場合RECTのOpenCVのを検出するために、複数の四角形を検出した後、ベクターRECT組成物は、一部は、ものによって得られる悪いRECT分割領域であり、
これらの仕様の一部によると、矩形の矩形にまとめることができます。応じのX、Y、幅、高さ特性の例えば。
最初のソートによれば、座標xまたはy座標ができます。
// 按照X坐标排序 BOOL BOCR :: rect_rank_x(ベクトル<のRect>&vec_rects){ のRect vec_temp。 用(int型、L = 1であり、L <vec_rects.size(); L ++ ){ ため(INT M = vec_rects.size() - 1 ; M> = L; M-- ){ 場合(vec_rects [M] .X < vec_rects [M - 1 ] .X){ vec_temp = vec_rects [M - 1 ]。 vec_rects [M - 1 ] = vec_rects [M]。 vec_rects [M] = vec_temp。 } } } 戻り 真。 } // 按照X坐标排序 BOOL BOCR :: rect_rank_y(ベクトル<のRect>&vec_rects){ のRect vec_temp。 用(int型、L = 1であり、L <vec_rects.size(); L ++ ){ ため(INT M = vec_rects.size() - 1 ; M> = L; M-- ){ 場合(vec_rects [M]・Y < vec_rects [M - 1 ] .Y){ vec_temp = vec_rects [M - 1 ]。 vec_rects [M - 1 ] =vec_rects [M]; vec_rects [M] = vec_temp; } } } 戻り trueに; } / * RECT合わせ垂直 *パラメータ:vec_rects:入力すべてのセットRECT; * vec_rects_out:すべてが垂直出力合成セットをRECT ; * x_dif:上下合わせX差; y_dif:上下合わせY差; *幅:上下合わせ最大幅、高さ:垂直合成のための最大の高さ; width_rect:合成RECT値は、条件width_rectを満たすために幅よりも大きい * / BOOL BOCR :: rect_combine_uplow(ベクトル<のRect>&vec_rects、 ベクトル <のRect>&vec_rects_out、int型 x_dif、int型 y_dif、int型の幅、int型の高さ、 INT width_rect){ rect_rank_y(vec_rects)。 // 将上下部分分裂的、合并 int型 num_rect = vec_rects.size(); 用(INT J = 0 ; J <num_rect; J ++ ){ 場合(vec_rects [J] .width> 0 ){ のRect R。 用(int型のp = 0 ; p <num_rect; p ++ ){ もし、((vec_rects [P] .width> 0)&&(P> j個の|| pを< J)){ もし、((((ABS(vec_rects [P] .X - vec_rects [J] .X)<x_dif) || (ABS( vec_rects [P] .X + vec_rects [P] .width - vec_rects [J] .X - vec_rects [J] .width)< x_dif)) && ((ABS( vec_rects [P] .Y - (vec_rects [ J] .Y + vec_rects [J] .height)) < y_dif) || (ABS( vec_rects [J] .Y - (vec_rects [P] .Y + vec_rects [P] .height)) < y_dif)) &&(vec_rects [P] .height < 高さ) &&(vec_rects [J] .height < 高さ) &&(vec_rects [P]。幅< 幅) &&(vec_rects [J] .width < 幅))){ RX = 分(vec_rects [J] .X、vec_rects [P] .X)。 RY =分(vec_rects [J] .Y、vec_rects [P] .Y)。 r.width MAX( vec_rects [P] .X + vec_rects [P] .width - vec_rects [J] .X、 vec_rects [J] .X + vec_rects [J] .width - vec_rects [P] .X)。 r.height = MAX( vec_rects [J] .Y + vec_rects [J] .height - vec_rects [P] .Y、 vec_rects [P] .Y +vec_rects [P] .height -vec_rects [J] .Y)。 もし(vec_rects [P] .Y < vec_rects [J] .Y){ vec_rects [P] .width = 0 。 vec_rects [P] .X = 0 。 vec_rects [P] .height = 0 。 vec_rects [P] .Y = 0 。 vec_rects [J] = R。 } 他{ vec_rects [J] .width = 0 。 vec_rects [J] .X= 0 ; vec_rects [J] .height = 0 。 vec_rects [J] .Y = 0 。 vec_rects [P] = R。 } } } } } } のための(INT J = 0 ; J <num_rect; J ++ ){ 場合(vec_rects [J] .width> width_rect){ vec_rects_out.push_back(vec_rects [J])。 } } を返す 真。 } / * 周りRECTはマージ :*パラメータ 、入力画像:*ショー 、すべてのRECT入力セットを:* vec_rects * vec_rects_out:すべては、左と右の出力を組み合わせセットをRECT; * x_dif約合併のためにX差; y_dif:Y合成差分値について; *幅:約組み合わせ幅の最大、高さ合わせ左右の最大高さ; * RATE1:1の最小アスペクト比をRECT;にrate2:RECT 2の最小値のアスペクト比; * width_rect:条件を満たすために組み合わさwidth_rectより大きい幅のRECT値 * / BOOL BOCR :: rect_combine_leftright(マット&表示、ベクトル<RECT>&vec_rects、 ベクトル <RECT>&vec_rects_out、INT x_dif、int型の y_dif、int型の幅、int型の高さ、 ダブル RATE1、二重にrate2、INT width_rect){ int型 NUM = vec_rects.size()。 用(int型 J = 0 ; J <NUM - 1 ; J ++ ){ 場合(vec_rects [J] .width> 0 ){ ための(int型 Q = J + 1、Q <NUM; Q ++ ){ 場合(vec_rects [Q] .width> 0 ){ のRect R。 もし((MAX(vec_rects [Q] .X - x_dif、0 ) <分(vec_rects [J] .X +vec_rects [J] .width、 show.cols)) &&((ABS(vec_rects [Q] .Y - vec_rects [J] .Y)< y_dif) || (ABS( 分( vec_rects [Q] .Y + vec_rects [ Q] .height、 show.rows) - 分( vec_rects [J] .Y + vec_rects [J] .height、 show.rows)) < y_dif)) &&(vec_rects [Q] .width <幅) &&(vec_rects [J] .width < 幅) && (((vec_rects [Q] .height /(ダブル)vec_rects [Q] .width> RATE1) && (vec_rects [J] .height /(ダブル)vec_rects [ J] .width > にrate2)) || ((vec_rects [J] .height /(ダブル)vec_rects [J] .width > RATE1) && (vec_rects [Q] .height /(ダブル)vec_rects [Q] .width > にrate2)))){ もし、((vec_rects [J] .X + vec_rects [J] .width > show.cols / 10 * 8.5 ) &&(vec_rects [Q] .X> show.cols / 10 * 8.5 ) && ABS(vec_rects [J] .width -vec_rects [Q] .width) <4つの && ABS( vec_rects [J] .height - vec_rects [Q] .height)< 3 ){ 。 } 他{ RX = vec_rects [J] .X。 RY = 分(vec_rects [J] .Y、vec_rects [Q] .Y)。 r.width = vec_rects [Q] .X + vec_rects [Q] .width - vec_rects [J] .X。 r.height = MAX(vec_rects [J] .Y + vec_rects [J] .height、 vec_rects [Q] .Y + vec_rects [Q] .height) - RY。 vec_rects [Q] .width = 0 。 vec_rects [Q] .X = 0 。 vec_rects [J] = R。 } } } } } } のための(INT J = 0 ; J <NUM; J ++ ){ 場合(vec_rects [J] .width> width_rect){ vec_rects_out.push_back(vec_rects [J]); } } 戻り trueに; } ---------------- 免責事項:この記事は、元の記事のCSDNブロガー"待機繭"であり、CCをたどります4.0バイSAの著作権契約、複製、元のソースのリンクと、この文を添付してください。 オリジナルリンク:HTTPS:// blog.csdn.net/boon_228/article/details/51491789