@@ -159,43 +159,51 @@ int16_t ItemPrinterMaterialDetector::read_number(
159159int8_t ItemPrinterMaterialDetector::find_happiny_dust_row_index (
160160 VideoStream& stream, ProControllerContext& context
161161) const {
162- int8_t value_68_row_index ;
162+ int8_t happiny_dust_row_index = - 1 ;
163163 for (size_t c = 0 ; c < 30 ; c++){
164164 context.wait_for_all_requests ();
165- std::vector<int8_t > value_68_row_index_list = find_material_value_row_index (stream, context, 68 );
166- for (size_t i = 0 ; i < value_68_row_index_list.size (); i++){
167- value_68_row_index = value_68_row_index_list[i];
168- if (detect_material_name (stream, context, value_68_row_index) == " happiny-dust" ){
169- // found screen and row number with Happiny dust.
170- // std::cout << "Happiny dust found. Row number: " << std::to_string(value_68_row_index) << std::endl;
171- return value_68_row_index;
172- }
173- }
165+ VideoSnapshot snapshot = stream.video ().snapshot ();
166+ int8_t total_rows = 10 ;
174167
168+ SpinLock lock;
169+ GlobalThreadPools::normal_inference ().run_in_parallel (
170+ [&](size_t index){
171+ std::string material_name = detect_material_name (stream, snapshot, context, (int8_t )index);
172+ if (" happiny-dust" == material_name){
173+ WriteSpinLock lg (lock);
174+ happiny_dust_row_index = (int8_t )index;
175+ }
176+ },
177+ 0 , total_rows, 1
178+ );
179+
180+ if (happiny_dust_row_index != -1 ){
181+ // found screen and row number with Happiny dust.
182+ // std::cout << "Happiny dust found. Row number: " << std::to_string(value_68_row_index) << std::endl;
183+ return happiny_dust_row_index;
184+ }
185+
175186 // keep searching for Happiny dust
176187 pbf_press_dpad (context, DPAD_RIGHT, 20 , 30 );
177188 }
178189
179190 OperationFailedException::fire (
180191 ErrorReport::SEND_ERROR_REPORT,
181- " Failed to find Happiny dust after 10 tries ." ,
192+ " Failed to find Happiny dust after multiple attempts ." ,
182193 stream
183194 );
184195
185196}
186197
187- // detects the material name at the given row_index
188- // MaterialNameReader has a very limited dictionary,
189- // so it can only reliably read the material names with 68% value
190- // (i.e. Ditto Goo, Happiny Dust, Magby Hair, Beldum Claw)
191198std::string ItemPrinterMaterialDetector::detect_material_name (
192199 VideoStream& stream,
200+ const ImageViewRGB32& screen,
193201 ProControllerContext& context,
194202 int8_t row_index
195203) const {
196- VideoSnapshot snapshot = stream. video (). snapshot ();
204+
197205 ImageFloatBox material_name_box = m_box_mat_name[row_index];
198- ImageViewRGB32 material_name_image = extract_box_reference (snapshot , material_name_box);
206+ ImageViewRGB32 material_name_image = extract_box_reference (screen , material_name_box);
199207 const auto ocr_result = MaterialNameReader::instance ().read_substring (
200208 stream.logger (), m_language,
201209 material_name_image, OCR::BLACK_OR_WHITE_TEXT_FILTERS ()
@@ -250,15 +258,13 @@ std::vector<int8_t> ItemPrinterMaterialDetector::find_material_value_row_index(
250258
251259}
252260
253- // detect the quantity of material at the given row number
254261int16_t ItemPrinterMaterialDetector::detect_material_quantity (
255262 VideoStream& stream,
263+ const ImageViewRGB32& screen,
256264 ProControllerContext& context,
257265 int8_t row_index
258266) const {
259- context.wait_for_all_requests ();
260- VideoSnapshot snapshot = stream.video ().snapshot ();
261- int16_t value = read_number (stream.logger (), snapshot, m_box_mat_quantity[row_index], row_index);
267+ int16_t value = read_number (stream.logger (), screen, m_box_mat_quantity[row_index], row_index);
262268 return value;
263269}
264270
0 commit comments