Esempio n. 1
0
    def get_answer(self, *args, **kwargs):
        image = getCurrentImage()
        genre = get_genre(image)

        q, qsim, qcontent = get_ques(image, genre)
        if(q!=None):
            print "answer:", q["answer"]
Esempio n. 2
0
def judge_panel_color(num, image = None):
    if(image == None):
        image = getCurrentImage()
        image = get_normalized_image(image)
    
    image = crop_box_left_down(panel_rects[num], image)

    is_red = False
    is_blue = False
    is_yellow = False

    for i, dic in enumerate(panel_dictionaries):
        key = recog.recognize(
                image,
                recog.match_rgb,
                0.0,
                dic
                )
        if(key == "red"):
            is_red = True
        elif(key == "yellow"):
            is_yellow = True
        elif(key == "blue"):
            is_blue = True
    color_size = 0
    if(is_red):
        color_size += 1
    if(is_yellow):
        color_size += 1
    if(is_blue):
        color_size += 1

    return color_size, (1 if is_red else 0, 1 if is_yellow else 0, 1 if is_blue else 0)
Esempio n. 3
0
def judge_reido_scene(image = None):
    """
    戦闘・非戦闘状態関係なくレイドの場面を判断する.
    """
    if(image == None):
        image = getCurrentImage()
        image = get_normalized_image(image)

    non_key, non_sim = recognize(
            image,
            recog.match_rgb,
            0.80,
            scene_reido_dictionary
            )
    non_sim = non_sim * 0.75 / 0.80

    battle_key, battle_sim = recog.recognize(
            input_image = image,
            match = calc_sim_b,
            threshold = 0.75,
            dictionary = dictionary_scene
            )
    if(battle_sim >= non_sim):
        return battle_key
    return non_key
Esempio n. 4
0
def judge_scene_color(image=None):
    if (image == None):
        image = getCurrentImage()
        image = get_normalized_image(image)

    key, sim = recog.recognize(image, recog.match_rgb, 0.92,
                               scene_color_dictionary)
    return key
Esempio n. 5
0
def judge_erratum(image=None):
    # 正解か不正解かを判定する.
    if (image == None):
        image = getCurrentImage()
        image = get_normalized_image(image)

    key, sim = recog.recognize(image, recog.match_answer_erratum, 0.0,
                               erratum_dictionary)
    return key
Esempio n. 6
0
def judge_panels(image = None):
    if(image == None):
        image = getCurrentImage()
        image = get_normalized_image(image)
    
    ret = [None] * 4
    for i in range(len(ret)):
        ret[i] = judge_panel_color(i, image)

    return ret
Esempio n. 7
0
def judge_ans_num(image = None):
    if(image == None):
        image = getCurrentImage()
        image = get_normalized_image(image)

    key, sim = recognize(
            image,
            recog.match_rgb,
            0.76,
            ans_select_dictionary
            )
    return key
Esempio n. 8
0
def judge_non_battle_scene(image = None):
    if(image == None):
        image = getCurrentImage()
        image = get_normalized_image(image)

    key, sim = recognize(
            image,
            recog.match_rgb,
            0.82,
            scene_reido_dictionary
            )
    return key
Esempio n. 9
0
def judge_scene(image=None):
    # クエスト時における現在の状態を判別する
    # ジャンル選択、問題、などがある.
    if (image == None):
        image = getCurrentImage()
        image = get_normalized_image(image)

    key, sim = recog.recognize(input_image=image,
                               match=calc_sim_b,
                               threshold=0.75,
                               dictionary=dictionary_scene)
    return key
Esempio n. 10
0
def judge_scene_color(image = None):
    if(image == None):
        image = getCurrentImage()
        image = get_normalized_image(image)

    key, sim = recog.recognize(
            image,
            recog.match_rgb,
            0.92,
            scene_color_dictionary
            )
    return key
Esempio n. 11
0
def judge_erratum(image = None):
    # 正解か不正解かを判定する.
    if(image == None):
        image = getCurrentImage()
        image = get_normalized_image(image)

    key, sim = recog.recognize(
            image,
            recog.match_answer_erratum,
            0.0,
            erratum_dictionary
            )
    return key
Esempio n. 12
0
def judge_scene(image = None):
    # クエスト時における現在の状態を判別する
    # ジャンル選択、問題、などがある.
    if(image == None):
        image = getCurrentImage()
        image = get_normalized_image(image)

    key, sim = recog.recognize(
            input_image = image,
            match = calc_sim_b,
            threshold = 0.75,
            dictionary = dictionary_scene
            )
    return key
Esempio n. 13
0
def judge_is_non_battle_scene(image = None):
    if(image == None):
        image = getCurrentImage()
        image = get_normalized_image(image)

    key, sim = recognize(
            image,
            recog.match_rgb,
            0.84,
            is_nonbattle_mode_dictionary
            )
    if(key == None):
        return False
    return key == "is_nonbattle"
Esempio n. 14
0
def judge_ansnum(image=None):
    # 問題の答えを画像から判定する.
    if (image == None):
        image = getCurrentImage()
        image = get_normalized_image(image)

    key, sim = recog.recognize(image, recog.match_rgb, 0.0, ansnum_dictionary)
    if (key == None):
        return -1
    if (key == "num1"):
        return 1
    if (key == "num2"):
        return 2
    if (key == "num3"):
        return 3
    if (key == "num4"):
        return 4
    return -1
Esempio n. 15
0
def judge_ansnum(image = None):
    # 問題の答えを画像から判定する.
    if(image == None):
        image = getCurrentImage()
        image = get_normalized_image(image)

    key, sim = recog.recognize(
            image,
            recog.match_rgb,
            0.0,
            ansnum_dictionary
            )
    if(key == None):
        return -1
    if(key == "num1"):
        return 1
    if(key == "num2"):
        return 2
    if(key == "num3"):
        return 3
    if(key == "num4"):
        return 4
    return -1
Esempio n. 16
0
    def loop(self, default_image=None):
        scene_key = judge_scene(default_image)

        # select genre
        if (scene_key == "is_genre"):
            logger.debug("genre select")
            panels = judge_panels(default_image)

            # 色が青・赤、または色が一番多いパネルを選択
            max_size = -1
            max_num = -1
            for i, v in enumerate(panels):
                # If color is red, select it.
                if (v[1][0] == 1 or v[1][0] == 0):
                    click_panel_num = i
                    break
                if (v[0] > max_size):
                    max_size = v[0]
                    max_num = i
            if (click_panel_num == -1):
                click_panel_num = max_num

            clickAt(SELECT_GENRE_POS[click_panel_num])
            self.select_panel = panels[click_panel_num]

        # select question answer
        elif (scene_key == "is_question"):
            logger.debug("question select")

            image = getCurrentImage()
            genre = get_genre(image)
            choices = get_choices(image)
            time.sleep(2.2)

            image = getCurrentImage()

            panel = None
            if (self.select_panel != None):
                if (self.select_panel[0] == 1):
                    panel = u"1色"
                if (self.select_panel[0] == 2):
                    panel = u"2色"
                if (self.select_panel[0] == 3):
                    panel = u"3色"
                else:
                    panel = None
            q, qsim, qcontent = get_ques(image, genre, panel)

            if (q != None):
                logger.debug(q["question"])

            print "qsim:", qsim
            if (qsim < 0.3):
                clickAt(SELECT_ANSWER_POS[random.randint(0, 3)])
                time.sleep(1)
                ansnum = judge_ansnum()
                if (ansnum != -1):
                    print "answer nubmer:", ansnum
                else:
                    print "answer number:", "読み取り不能"

            else:
                print "answer:", q["answer"]
                choice = get_answer(image, q, choices)
                if (choice == -1):
                    logger.debug("Unknown question...")
                else:
                    logger.debug("Known question!!!")

                clickAt(SELECT_ANSWER_POS[choice])
                time.sleep(1)

                erratum_key = judge_erratum()
                if (erratum_key == "is_seikai"):
                    print("正解!")
                elif (erratum_key == "is_hazure"):
                    print("不正解...")
                else:
                    print("判別不能")
        time.sleep(0.5)
Esempio n. 17
0
    def loop(self, default_image=None):
        scene_key = judge_scene(default_image)

        # select genre
        if(scene_key == "is_genre"):
            logger.debug("genre select")
            panels = judge_panels(default_image)

            # 色が青・赤、または色が一番多いパネルを選択
            max_size = -1
            max_num = -1
            for i, v in enumerate(panels):
                # If color is red, select it.
                if(v[1][0] == 1 or v[1][0] == 0):
                    click_panel_num = i
                    break
                if(v[0] > max_size):
                    max_size = v[0]
                    max_num = i
            if(click_panel_num == -1):
                click_panel_num = max_num

            clickAt(SELECT_GENRE_POS[click_panel_num])
            self.select_panel = panels[click_panel_num]

        # select question answer
        elif(scene_key == "is_question"):
            logger.debug("question select")

            image = getCurrentImage()
            genre = get_genre(image)
            choices = get_choices(image)
            time.sleep(2.2)

            image = getCurrentImage()

            panel = None
            if(self.select_panel != None):
                if(self.select_panel[0] == 1):
                    panel = u"1色"
                if(self.select_panel[0] == 2):
                    panel = u"2色"
                if(self.select_panel[0] == 3):
                    panel = u"3色"
                else:
                    panel = None 
            q, qsim, qcontent = get_ques(image, genre, panel)
            
            if(q!=None):
                logger.debug(q["question"])

            print "qsim:", qsim
            if(qsim < 0.3):
                clickAt(SELECT_ANSWER_POS[random.randint(0, 3)])
                time.sleep(1)
                ansnum = judge_ansnum()
                if(ansnum != -1):
                    print "answer nubmer:", ansnum
                else:
                    print "answer number:", "読み取り不能"

            else:
                print "answer:", q["answer"]
                choice = get_answer(image, q, choices)
                if(choice == -1):
                    logger.debug("Unknown question...")
                else:
                    logger.debug("Known question!!!")

                clickAt(SELECT_ANSWER_POS[choice])
                time.sleep(1)

                erratum_key = judge_erratum()
                if(erratum_key == "is_seikai"):
                    print("正解!")
                elif(erratum_key == "is_hazure"):
                    print("不正解...")
                else:
                    print("判別不能")
        time.sleep(0.5)
Esempio n. 18
0
    def loop(self, default_image=None):
        activate()
        scene_key = judge_reido_scene(default_image)
        
        if(scene_key != None):
            if(scene_key == "is_genre"):
                panels = judge_panels(default_image)
                max_size = -1
                max_num = -1

                click_panel_num = -1
                for i, v in enumerate(panels):
                    # If color is red, select it.
                    if(v[1][0] == 1):
                        click_panel_num = i
                        break
                    if(v[0] > max_size):
                        max_size = v[0]
                        max_num = i
                if(click_panel_num == -1):
                    click_panel_num = max_num
                clickAt(SELECT_GENRE_POS[click_panel_num])
                self.select_panel = panels[click_panel_num]
            elif(scene_key == "is_question"):
                ans_key = judge_ans_num(default_image)
                if(ans_key != None):
                    if(ans_key == "1"):
                        clickAt(SELECT_ANSWER_POS[0])
                    elif(ans_key == "2"):
                        clickAt(SELECT_ANSWER_POS[1])
                    elif(ans_key == "3"):
                        clickAt(SELECT_ANSWER_POS[2])
                    elif(ans_key == "4"):
                        clickAt(SELECT_ANSWER_POS[3])
                else:
                    image = getCurrentImage()
                    genre = get_genre(image)
                    choices = get_choices(image)

                    image = getCurrentImage()

                    panel = None
                    if(self.select_panel != None):
                        if(self.select_panel[0] == 1):
                            panel = u"1色"
                        if(self.select_panel[0] == 2):
                            panel = u"2色"
                        if(self.select_panel[0] == 3):
                            panel = u"3色"
                        else:
                            panel = None 
                    q, qsim, qcontent = get_ques(image, genre, panel)
                    
                    if(q!=None):
                        logger.debug(q["question"])

                    if(qsim < 0.3):
                        clickAt(SELECT_ANSWER_POS[random.randint(0, 3)])
                    else:
                        choice = get_answer(image, q, choices)
                        clickAt(SELECT_ANSWER_POS[choice])
            else:
                pos_box = scene_reido_dictionary[scene_key]["rec_box"]
                clickAt((pos_box[0], pos_box[1]))
                time.sleep(0.3)
                clickAt((pos_box[0]-5, pos_box[1]))
        time.sleep(0.5)