import ddddocr
import cv2
ocr = ddddocr.DdddOcr()

def fuhuo(image):
    image = image[603:641, 460:577]
    image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
    # 将裁剪后的图像编码成二进制格式
    _, img_encoded = cv2.imencode('.png', image)
    # 将图像编码结果转换为字节流
    img_bytes = img_encoded.tobytes()
    result = ocr.classification(img_bytes)
    print(result)
    if result == "记录点复活" or result == "记灵点复活":
        return True
    else:
        return False


def jieshu(image):
    image=image[623:623+41, 472:472+167]
    image=cv2.cvtColor(image,cv2.COLOR_RGB2BGR)
    # 将裁剪后的图像编码成二进制格式
    _, img_encoded = cv2.imencode('.png', image)
    # 将图像编码结果转换为字节流
    img_bytes = img_encoded.tobytes()
    result = ocr.classification(img_bytes)
    if result=="结束挑战":
        return True
    else:
        return False

def tiaozhan(image):
    image = image[576:614, 1023:1138]
    image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
    # 将裁剪后的图像编码成二进制格式
    _, img_encoded = cv2.imencode('.png', image)
    # 将图像编码结果转换为字节流
    img_bytes = img_encoded.tobytes()
    result = ocr.classification(img_bytes)
    if result == "开启挑战":
        return True
    else:
        return False


def tuichu(image):
    image = image[24:58, 569:669]
    image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
    # 将裁剪后的图像编码成二进制格式
    _, img_encoded = cv2.imencode('.png', image)
    # 将图像编码结果转换为字节流
    img_bytes = img_encoded.tobytes()
    result = ocr.classification(img_bytes)
    print(result)
    if result[1:] == "出挑战" or result[0:2] == "退出"  :
        return True
    else:
        return False


def tuwai(image):
    image = image[59:93, 1226:1275]
    image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
    # 将裁剪后的图像编码成二进制格式
    _, img_encoded = cv2.imencode('.png', image)
    # 将图像编码结果转换为字节流
    img_bytes = img_encoded.tobytes()
    result = ocr.classification(img_bytes)
    print(result)
    if result == "tap" or result=='tqp' or result=='top':
        return True
    else:
        return False


def daoying(image):
    image = image[260:289, 570:628]
    image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
    # 将裁剪后的图像编码成二进制格式
    _, img_encoded = cv2.imencode('.png', image)
    # 将图像编码结果转换为字节流
    img_bytes = img_encoded.tobytes()
    result = ocr.classification(img_bytes)
    print(result)
    if result == "倒影" or result=="到影" :
        return True
    else:
        return False

def shuzi(image):
    image=image[50:91,610:666]
    image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
    # 将裁剪后的图像编码成二进制格式
    _, img_encoded = cv2.imencode('.png', image)
    # 将图像编码结果转换为字节流
    img_bytes = img_encoded.tobytes()
    result = ocr.classification(img_bytes)
    print(result)
    if result=="40":
        return True

def test(image):
    # 将裁剪后的图像编码成二进制格式
    _, img_encoded = cv2.imencode('.png', image)
    # 将图像编码结果转换为字节流
    img_bytes = img_encoded.tobytes()
    result = ocr.classification(img_bytes)
    print(result)


if __name__ == '__main__':
    image=cv2.imread('10.21_820.jpg')
    shuzi(image)
    test(image)
