def show_pre_res(self): res = '' if 'train1' in self.model_path: res = test1.test(self.pic_path_pro, self.model_path) elif 'train2' in self.model_path: res = test2.test(self.pic_path_pro, self.model_path) elif 'train3' in self.model_path: res = test3.test(self.pic_path_pro, self.model_path) self.show_res_text.setText(res)
def imgT(imgN): img = cv.imread(imgN) #[:, :, 0] img = np.array(img) start = time.clock() red = img[:, :, 2] print("Python: " + str(time.clock() - start) + "seconds") out = c.test(img, img) plt.imshow(np.real(out)) plt.show()
def real(n, m): arr = np.empty([n, m, 3]) count = 1 for i in range(n): for j in range(m): for k in range(3): arr[i, j, k] = count count += 1 print(arr) out = c.test(arr, arr, n)
def comp(n, m): arr = np.empty([n, m], dtype=np.complex64) count = 1 count1 = -1 for i in range(n): for j in range(m): arr[i, j] = count + 1j * count1 count += 1 count1 -= 1 print(arr) out = c.test(arr, arr, n)
import test3 as t3 t3.test() log = '' def test(log): log += 'lol' return log log = test(log) log = test(log) print log
def main(tehai: str = None, tehai1: list = None, dahai: int = None, is_number_only: bool = False, has_koyaku: bool = False) -> str: string = "" string_chiniisoo_chart = "" #input tehai if tehai1 == None: tehai_lower = tehai.lower() if tehai_lower in ("help", "帮助", "幫助", "ヘルプ"): return s.help elif tehai_lower in ("about", "关于"): return "胡祥又 Hu Xiangyou\nversion " + VERSION + "\n\nversion 0.0 December 17, 2018\nversion 1.0 February 9, 2019\nversion 1.1 February 20, 2019\nversion 1.2 March 20, 2019\nversion 2.0 April 14, 2019\nversion 2.1 June 6, 2019\nversion 3.0 July 1, 2019" elif tehai_lower in ("example", "examples", "举例", "舉例", "例", "例え", "test", "tests", "测试", "測試", "テスト"): tehai = test3.test() output = main(tehai=tehai, has_koyaku=has_koyaku) return tehai + "\n\n" + output[0], output[1] elif tehai_lower in ("random", "随机", "隨機", "ランダム"): tehai = test3.chiniisoo_random() output = main(tehai=tehai, has_koyaku=has_koyaku) return tehai + "\n\n" + output[0], output[1] elif tehai_lower in ("random14", "随机14", "隨機14", "ランダム14"): tehai = test3.chiniisoo_random14() output = main(tehai=tehai, has_koyaku=has_koyaku) return tehai + "\n\n" + output[0], output[1] for i in (' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~', ' ', '\n', '\r', '\t'): tehai = tehai.replace(i, '') if tehai == '': return '' #manage tehai tehai1 = [] shurui_now = None shurui_used = True invalid_inputs = [] has_0 = False has_0m = False has_0p = False has_0s = False #number only if tehai.isdecimal(): is_number_only = True if '0' in tehai: has_0 = True tehai1 = [int(i) if i != '0' else 5 for i in tehai] else: tehai = tehai[::-1] for tehai_i in tehai: if tehai_i in ('E', 'E', '東', '东'): tehai1.append(31) elif tehai_i in ('S', 'S', '南'): tehai1.append(32) elif tehai_i in ('W', 'W', '西'): tehai1.append(33) elif tehai_i in ('N', 'N', '北'): tehai1.append(34) elif tehai_i in ('P', 'D', 'P', 'D', '白'): tehai1.append(35) elif tehai_i in ('F', 'H', 'R', 'F', 'H', 'R', '發', '発', '发'): tehai1.append(36) elif tehai_i in ('C', 'C', '中'): tehai1.append(37) elif tehai_i in ('m', 'w', 'm', 'w', '万', '萬'): if not shurui_used: invalid_inputs.insert(0, ('m', 'p', 's', 'z')[shurui_now]) shurui_now = 0 shurui_used = False elif tehai_i in ('p', 'p', '筒', '饼', '餠', '餅'): if not shurui_used: invalid_inputs.insert(0, ('m', 'p', 's', 'z')[shurui_now]) shurui_now = 1 shurui_used = False elif tehai_i in ('s', 's', '索', '条', '條'): if not shurui_used: invalid_inputs.insert(0, ('m', 'p', 's', 'z')[shurui_now]) shurui_now = 2 shurui_used = False elif tehai_i in ('z', 'z', '字'): if not shurui_used: invalid_inputs.insert(0, ('m', 'p', 's', 'z')[shurui_now]) shurui_now = 3 shurui_used = False elif tehai_i.isdecimal(): if shurui_now != None: if tehai_i == '0' and shurui_now in (0, 1, 2): tehai1.append(5 + shurui_now * 10) if shurui_now == 0: has_0m = True elif shurui_now == 1: has_0p = True elif shurui_now == 2: has_0s = True elif tehai_i in ('0', '8', '9') and shurui_now == 3: invalid_inputs.insert(0, tehai_i + 'z') shurui_used = True else: tehai1.append(int(tehai_i) + shurui_now * 10) shurui_used = True else: invalid_inputs.insert(0, tehai_i) else: if not shurui_used: invalid_inputs.insert(0, ('m', 'p', 's', 'z')[shurui_now]) shurui_used = True invalid_inputs.insert(0, tehai_i) if shurui_used == False: invalid_inputs.insert(0, ('m', 'p', 's', 'z')[shurui_now]) if invalid_inputs: string += s.has_invalid_input + s.colon string += s.ideographic_comma.join(invalid_inputs) + "\n" if has_0: string += s.has_0 + "\n" elif has_0m: string += s.has_0m + "\n" elif has_0p: string += s.has_0p + "\n" elif has_0s: string += s.has_0s + "\n" tehai1.sort() #count tehai haisuu = len(tehai1) tehai9 = [0] * 38 for i in tehai1: tehai9[i] += 1 is_chiniisoo = False if 13 <= sum(tehai9) and (sum(tehai9) == sum(tehai9[1:10]) or sum(tehai9) == sum(tehai9[11:20]) or sum(tehai9) == sum(tehai9[21:30])): is_chiniisoo = True if haisuu == 0: return string #show tehai if not dahai: string += s.tehai + s.colon + output_hais( tehai1, is_number_only, jihai_in_kanji=True, end="\n\n") if any(i > 4 for i in tehai9): string += s.more_than_4.format( s.ideographic_comma.join([ output_hai(i, is_number_only) for i in range(10 if is_number_only else 38) if tehai9[i] > 4 ])) + "\n" if haisuu > 14: string += s.more_than_14.format(str(haisuu)) + "\n\n" if haisuu < 13: string += s.less_than_13.format(str(haisuu)) + "\n\n" mentsusuu = haisuu // 3 is_tenpai = False is_beginning_of_the_cosmos = False kouten = [] if haisuu == tehai9[35] == 18: is_beginning_of_the_cosmos = True did_tsumo = True elif haisuu % 3 == 2: did_tsumo = True elif haisuu % 3 == 1: did_tsumo = False haisuu += 1 agarihais = [] elif haisuu % 3 == 0: did_tsumo = None string += s.taapai_or_shaopai.format(str(haisuu)) return string for tsumohai in range(1, 10 if is_number_only else 38): if tsumohai % 10 == 0: continue is_karaten = False if did_tsumo == False: tehai9[tsumohai] += 1 if tehai9[tsumohai] == 5: is_karaten = True is_hoora = False hoorakeis = [] hansuu = [] #kokushimusou if haisuu == 14 and not any(tehai9[2:9]) and not any( tehai9[12:19] ) and not any(tehai9[22:29]) and tehai9[1] and tehai9[9] and tehai9[ 11] and tehai9[19] and tehai9[21] and tehai9[29] and all( tehai9[31:]): is_hoora = True hoorakeis.append( [['j', tehai9.index(2), tehai9.index(2), None]] + [['tp', i, None, None] for i in range(38) if tehai9[i] == 1]) hansuu_temp, string_temp = yaku_and_output(tehai9, hoorakeis[-1], did_tsumo, is_karaten, tsumohai, dahai, is_number_only, has_koyaku) hansuu.append(hansuu_temp) string += string_temp else: #chiitoitsu if haisuu == 14 and tehai9.count(2) == 7: is_hoora = True hoorakeis.append([['t', i, i, None] for i in range(10 if is_number_only else 38) if tehai9[i] == 2]) hansuu_temp, string_temp = yaku_and_output( tehai9, hoorakeis[-1], did_tsumo, is_karaten, tsumohai, dahai, is_number_only, has_koyaku) hansuu.append(hansuu_temp) string += string_temp #analyse tehai #jantou for jantou_i in range(10 if is_number_only else 38): if tehai9[jantou_i] >= 2: hoorakei_temp = [['j', jantou_i, jantou_i, None]] tehai9_temp = tehai9.copy() tehai9_temp[jantou_i] -= 2 else: continue #mentsu for mentsu_i in range(mentsusuu + 1): if tehai9_temp == None: break elif sum(tehai9_temp) == 0: is_hoora = True hoorakei_temp.sort() if hoorakei_temp not in hoorakeis: hoorakeis.append(hoorakei_temp) hansuu_temp, string_temp = yaku_and_output( tehai9, hoorakei_temp, did_tsumo, is_karaten, tsumohai, dahai, is_number_only, has_koyaku) hansuu.append(hansuu_temp) string += string_temp #if sanrenkoo then change to 3-shuntsu hoorakei_new_num = 1 while hoorakei_new_num: hoorakei_new_num_temp = hoorakei_new_num hoorakei_new_num = 0 for hoorakei_i in hoorakeis[ -hoorakei_new_num_temp:]: for mentsu_picked_i in hoorakei_i[1:]: if mentsu_picked_i[0] == 'k': kootsu_hai = mentsu_picked_i[1] if kootsu_hai % 10 <= 7 and kootsu_hai < 30 and [ 'k', kootsu_hai + 1, kootsu_hai + 1, kootsu_hai + 1 ] in hoorakei_i and [ 'k', kootsu_hai + 2, kootsu_hai + 2, kootsu_hai + 2 ] in hoorakei_i: hoorakei_temp = hoorakei_i.copy( ) hoorakei_temp.remove( mentsu_picked_i) hoorakei_temp.remove([ 'k', kootsu_hai + 1, kootsu_hai + 1, kootsu_hai + 1 ]) hoorakei_temp.remove([ 'k', kootsu_hai + 2, kootsu_hai + 2, kootsu_hai + 2 ]) hoorakei_temp.extend([[ 's', kootsu_hai, kootsu_hai + 1, kootsu_hai + 2 ]] * 3) hoorakei_temp.sort() if hoorakei_temp not in hoorakeis: hoorakeis.append( hoorakei_temp) hoorakei_new_num += 1 hansuu_temp, string_temp = yaku_and_output( tehai9, hoorakei_temp, did_tsumo, is_karaten, tsumohai, dahai, is_number_only, has_koyaku) hansuu.append(hansuu_temp) string += string_temp continue for hai_picked in range(10 if is_number_only else 38): if tehai9_temp[hai_picked] == 0: continue elif tehai9_temp[hai_picked] >= 3: #kootsu exists tehai9_temp[hai_picked] -= 3 hoorakei_temp.append( ['k', hai_picked, hai_picked, hai_picked]) break elif hai_picked < 28 and all( tehai9_temp[hai_picked:hai_picked + 3]): #shuntsu exists tehai9_temp[hai_picked] -= 1 tehai9_temp[hai_picked + 1] -= 1 tehai9_temp[hai_picked + 2] -= 1 hoorakei_temp.append([ 's', hai_picked, hai_picked + 1, hai_picked + 2 ]) break else: #neither kootsu nor shuntsu exists tehai9_temp = None break if did_tsumo == False and is_hoora: is_tenpai = True if not is_karaten: agarihais.append(tsumohai) if max(hansuu) >= 13: kouten.append(max(hansuu) // 13 * 13) if dahai and is_chiniisoo and tehai1[ 0] // 10 == tsumohai // 10: string_chiniisoo_chart += (str( max(hansuu) // 13 * 13))[:5].ljust(3).rjust(5) + "|" else: kouten.append(max(hansuu)) if dahai and is_chiniisoo and tehai1[ 0] // 10 == tsumohai // 10: string_chiniisoo_chart += (str( max(hansuu)))[:5].ljust(3).rjust(5) + "|" if did_tsumo == False and dahai and ( not is_hoora or is_karaten ) and is_chiniisoo and tehai1[0] // 10 == tsumohai // 10: string_chiniisoo_chart += " |" if did_tsumo and not is_hoora: if is_beginning_of_the_cosmos: string += s.hoora + " | 55z 5555z 5555z 5555z 5555z | " + s.beginning_of_the_cosmos + "(140" + s.fuu + "105" + s.han + " 90865195024359483499283685761351700" + s.ten + ")" + s.colon + s.tsuuiisoo + s.ideographic_comma + s.sanankoo + s.ideographic_comma + s.suukantsu + s.ideographic_comma + s.rinshankaihou + s.ideographic_comma + s.yakuhai_haku + "4" + s.ideographic_comma + s.dora + "72" + "\n" else: string += s.not_hoora + "\n" #dahai if is_chiniisoo: string_chiniisoo_chart += "\n打\\和 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |\n" for sutehai_i in range(10 if is_number_only else 38): if sutehai_i in tehai1: tehai1_new = tehai1.copy() tehai1_new.remove(sutehai_i) if is_chiniisoo: string_chiniisoo_chart += str( sutehai_i % 10) + " |" a, b = main(tehai1=tehai1_new, dahai=sutehai_i, is_number_only=is_number_only, has_koyaku=has_koyaku) string += a string_chiniisoo_chart += b + "\n" if did_tsumo: break if did_tsumo == False: tehai9[tsumohai] -= 1 #tenpai if not dahai and is_tenpai and agarihais: string += "\n" + s.tenpai + s.colon + "\n" if not is_number_only: agarihai_han = list(zip(agarihais, kouten)) agarihai_han.sort(key=lambda elem: (elem[1], elem[0])) for agarihai_han_i in range(len(agarihai_han)): string += output_hai(agarihai_han[agarihai_han_i][0], is_number_only) + " " if ( agarihai_han_i != len(agarihai_han) - 1 and agarihai_han[agarihai_han_i][1] != agarihai_han[agarihai_han_i + 1][1] ) or agarihai_han_i == len(agarihai_han) - 1 and haisuu <= 14: if agarihai_han[agarihai_han_i][1] >= 13: string += "(" + s.yakuman_level_list[ agarihai_han[agarihai_han_i][1] // 13] + ")\n" else: string += "(" + str( agarihai_han[agarihai_han_i][1]) + s.han + ")\n" else: for agarihai_i in agarihais: string += output_hai(agarihai_i, is_number_only) + " " string += "\n" #nooten if did_tsumo == False and not dahai and not is_tenpai: string += s.nooten return string, string_chiniisoo_chart