1+ import cv2
12import numpy as np
23
34from ....data_process .utils import cv_utils
@@ -10,12 +11,35 @@ def __init__(self, args, msg_queue):
1011 super (DetPostNode , self ).__init__ (args , msg_queue )
1112 self .text_detector = None
1213 self .task_type = self .args .task_type
14+ self .is_concat = self .args .is_concat
1315
1416 def init_self_args (self ):
1517 self .text_detector = TextDetector (self .args )
1618 self .text_detector .init (preprocess = False , model = False , postprocess = True )
1719 super ().init_self_args ()
1820
21+ def concat_crops (self , crops : list ):
22+ """
23+ Concatenates the list of cropped images horizontally after resizing them to have the same height.
24+
25+ Args:
26+ crops (list): A list of cropped images represented as numpy arrays.
27+
28+ Returns:
29+ numpy.ndarray: A horizontally concatenated image array.
30+ """
31+ max_height = max (crop .shape [0 ] for crop in crops )
32+ resized_crops = []
33+ for crop in crops :
34+ h , w , c = crop .shape
35+ new_h = max_height
36+ new_w = int ((w / h ) * new_h )
37+
38+ resized_img = cv2 .resize (crop , (new_w , new_h ), interpolation = cv2 .INTER_LINEAR )
39+ resized_crops .append (resized_img )
40+ crops = np .concatenate (resized_crops , axis = 1 )
41+ return crops
42+
1943 def process (self , input_data ):
2044 if input_data .skip :
2145 self .send_to_next_module (input_data )
@@ -39,6 +63,8 @@ def process(self, input_data):
3963 for box in infer_res_list :
4064 sub_image = cv_utils .crop_box_from_image (image , np .array (box ))
4165 sub_image_list .append (sub_image )
66+ if self .is_concat :
67+ sub_image_list = [self .concat_crops (sub_image_list )]
4268 input_data .sub_image_list = sub_image_list
4369
4470 input_data .data = None
0 commit comments