@@ -209,7 +209,7 @@ def scanner_function(multiprocess_shared_dict):
209209 TYPES_LIST = find_type_in_tags_array (
210210 CELL_COLORS_ARRAY , array_of_tags_from_json ,
211211 array_of_maps_form_json ,
212- array_of_rotations_form_json , grid_dimensions_x , grid_dimensions_y )
212+ grid_dimensions_x , grid_dimensions_y )
213213
214214 # match the two
215215 OLD_CELL_COLORS_ARRAY = CELL_COLORS_ARRAY
@@ -553,7 +553,8 @@ def select_color_by_mean_value(mean_color_RGB):
553553##################################################
554554
555555
556- def find_type_in_tags_array (cellColorsArray , tagsArray , mapArray , rotations_from_settings , grid_dimensions_x , grid_dimensions_y ):
556+ def find_type_in_tags_array (cellColorsArray , tagsArray , mapArray ,
557+ grid_dimensions_x , grid_dimensions_y ):
557558 """Get the right brick type out of the list of JSON types.
558559
559560 Steps:
@@ -565,49 +566,67 @@ def find_type_in_tags_array(cellColorsArray, tagsArray, mapArray, rotations_from
565566 Returns an array of found types
566567 """
567568 scan_results_array = []
568-
569569 # create np colors array with table struct
570570 np_array_of_scanned_colors = np .reshape (
571571 cellColorsArray , (grid_dimensions_x * grid_dimensions_y , 16 ))
572572
573573 # go through the results
574574 for this_16_bits in np_array_of_scanned_colors :
575- rot_arr = brick_rotation_check (this_16_bits )
575+
576+ ''' Old method
576577 # look for this result in tags array from JSON
577578 # and return only where TRUE appears in results
578- #!for tag in tagsArray:
579- #! print(this_16_bits, tag, np.where(np.isin(tag, rot_arr)))
580-
581- whichTag = np .where ([
582- (this_16_bits == tag ).all ()
583- for tag in tagsArray
584- ])[0 ]
579+ # this_tag = np.where([
580+ # (this_16_bits == tag).all()
581+ # for tag in tagsArray
582+ # ])[0]
585583
586584 # if this tag is not found return -1
587- if whichTag . size == 0 :
585+ if this_tag == None :
588586 scan_results_array.append([-1, 0])
589587 # else return the tag location in the list
590588 else:
591- this_tag = int (whichTag [0 ])
592589 type_number = mapArray[this_tag]
593590 rotation_value = rotations_from_settings[this_tag]
594591 # finally add to array
595- scan_results_array .append ([int (type_number ), int (rotation_value )])
592+ '''
593+
594+ result_tag = brick_rotation_check (this_16_bits , tagsArray , mapArray )
595+ if result_tag == None :
596+ result_tag = [- 1 , - 1 ]
597+ else :
598+ scan_results_array .append (result_tag )
596599
597600 # finally, return this list to main program for UDP
598601 return scan_results_array
599602
600603##################################################
601604
602605
603- def brick_rotation_check (this_16_bits ):
604-
605- brk_4x4 = np .reshape (this_16_bits , (4 , 4 ))
606- brk_4x4_90 = np .reshape ((np .rot90 (np .rot90 (np .rot90 (brk_4x4 )))), 16 )
607- brk_4x4_270 = np .reshape ((np .rot90 (np .rot90 (brk_4x4 ))), 16 )
608- brk_4x4_180 = np .reshape ((np .rot90 (brk_4x4 )), 16 )
609- rot_array = [this_16_bits , brk_4x4_90 , brk_4x4_180 , brk_4x4_270 ]
610- return rot_array
606+ def brick_rotation_check (this_16_bits , tagsArray , mapArray ):
607+ tags_array_counter = 0
608+ for this_tag in tagsArray :
609+ # if this 16 bits equal the tag as is
610+ if np .array_equal (this_16_bits , this_tag ):
611+ return [tags_array_counter , 0 ]
612+ # convert list of 16 bits to 4x4 matrix for rotation
613+ brk_4x4 = np .reshape (this_16_bits , (4 , 4 ))
614+ # rotate once
615+ brk_4x4_270 = np .reshape ((np .rot90 (brk_4x4 )), 16 )
616+ if np .array_equal (brk_4x4_270 , this_tag ):
617+ return [tags_array_counter , 1 ]
618+ # rotate once
619+ brk_4x4_180 = np .reshape ((np .rot90 (np .rot90 (brk_4x4 ))), 16 )
620+ if np .array_equal (brk_4x4_180 , this_tag ):
621+ return [tags_array_counter , 2 ]
622+ # rotate once
623+ brk_4x4_90 = np .reshape ((np .rot90 (np .rot90 (np .rot90 (brk_4x4 )))), 16 )
624+ if np .array_equal (brk_4x4_90 , this_tag ):
625+ return [tags_array_counter , 3 ]
626+ else :
627+ # if no rotation was found go to next tag
628+ # in tag list
629+ tags_array_counter = tags_array_counter + 1
611630
612631
613632##################################################
0 commit comments