@@ -115,44 +115,27 @@ def __init__(self, grids, templates, template_area=(40, 21, 89, 70), amount_area
115115 self .price_ocr = PRICE_OCR
116116 self .counter_area = counter_area
117117
118- def predict (self , image , shop_index = None , scroll_pos = None ) -> List [OSShopItem ]:
118+ def predict (self , image , counter = False , shop_index = None , scroll_pos = None ) -> List [OSShopItem ]:
119119 """
120120 Args:
121121 image (np.ndarray):
122+ counter (bool): If predict item counter.
122123 shop_index (bool): If predict shop index.
123124 scroll_pos (bool): If predict scroll position.
124125
125126 Returns:
126127 list[Item]:
127128 """
128- self ._load_image (image )
129- amount_list = [item .crop (self .amount_area ) for item in self .items ]
130- amount_list = self .amount_ocr .ocr (amount_list , direct_ocr = True )
131- counter_list = [item .crop (self .counter_area ) for item in self .items ]
132- counter_list = self .counter_ocr .ocr (counter_list , direct_ocr = True )
133- name_list = [self .match_template (item .image ) for item in self .items ]
134- cost_list = [self .match_cost_template (item ) for item in self .items ]
135- price_list = [item .crop (self .price_area ) for item in self .items ]
136- price_list = self .price_ocr .ocr (price_list , direct_ocr = True )
137- ignore = 0
138- items = []
139-
140- for i , a , t , n , c , p in zip (self .items , amount_list , counter_list , name_list , cost_list , price_list ):
141- if (p <= 0 ):
142- ignore += 1
143- continue
144- i .amount = a
145- i .count , i .total_count = t
146- i .name = n
147- i .cost = c
148- i .price = p
149- if isinstance (shop_index , int ):
129+ super ().predict (image , name = True , amount = True , cost = True , price = True )
130+ if counter and len (self .items ):
131+ counter_list = [item .crop (self .counter_area ) for item in self .items ]
132+ counter_list = self .counter_ocr .ocr (counter_list , direct_ocr = True )
133+ for i , t in zip (self .items , counter_list ):
134+ i .count , i .total_count = t
135+
136+ if isinstance (shop_index , int ) and isinstance (scroll_pos , float ) and len (self .items ):
137+ for i in self .items :
150138 i .shop_index = shop_index
151- if isinstance (scroll_pos , float ):
152139 i .scroll_pos = scroll_pos
153- items .append (i )
154140
155- if ignore > 0 :
156- logger .warning (f'Ignore { ignore } items, because price <= 0' )
157-
158- return items
141+ return self .items
0 commit comments