def step_impl(context): # read ads watch time and program time cam = context.cam context.frame = get_frame_name(context, f"{WORK_DIR}/_frame.png") start = time.time() success = 0 while True and time.time() < start + 180: press(context, keys.KEY_DOWN) # to show progress bar assert 200 == cam.get_frame(context.frame) region = Region(x=900, y=640, right=1110, bottom=720) ads = ocr(cv2.imread(context.frame), region, grayscale=True, invert_grayscale=True) debug(f"ads: {ads}") region = Region(x=1110, y=640, right=1280, bottom=720) counter = ocr(cv2.imread(context.frame), region, grayscale=True, invert_grayscale=True) debug(f"counter: {counter}") debug(f"ads/counter: {ads} / {counter}\n") if "Ad" not in ads and ":" not in counter: success += 1 if success > 3: return assert False, "ads is still playing"
def find_selection_text(frame, left_bk, right_bk=None, x_offset=0, y_offset=5, region=Region(x=0, y=0, right=1280, bottom=720), convert_to_grayscale=True, match_parameter=None): print(f"find_selection_text: region {region}") debug("search for left bracket") if match_parameter is None: match_parameter = get_default_match_parameter() l_result = match(frame, left_bk, region=region, match_parameter=match_parameter) if l_result[0] is False: debug("Error: fail to search left bracket") return None, None if right_bk is None: region = Region(x=l_result[1].x + x_offset, y=l_result[1].y + y_offset, right=l_result[1].right - x_offset, bottom=l_result[1].bottom - y_offset) else: debug("search for right bracket") r_result = match(frame, right_bk, region=region, match_parameter=match_parameter) if r_result[0] is False: debug("Error: fail to search right bracket") return None, None if l_result[1].right + x_offset > r_result[1].x - x_offset: return None, None region = Region(x=l_result[1].x + x_offset, y=l_result[1].y + y_offset, right=r_result[1].right - x_offset, bottom=r_result[1].bottom - y_offset) print(f"find_selection_text: search text in {region}") if convert_to_grayscale is True: text = ocr(frame=cv2.cvtColor( frame[region.y:region.bottom, region.x:region.right], cv2.COLOR_BGR2GRAY)) else: text = ocr(frame=frame[region.y:region.bottom, region.x:region.right]) print(f"find_selection_text: found {text} in selected region") return text, region
def step_impl(context, image, region): print(f"ocr in region:{region}") where = list(map(int, region.split(","))) region = vudu_image.Region(where[0], where[1], where[2], where[3]) match_result = vudu_image.ocr(cv2.imread(context.image), region) print(f"match_result: {match_result}") context.match_result = match_result
def step_impl(context): cam = context.cam context.frame = get_frame_name(context, f"{WORK_DIR}/_frame.png") assert 200 == cam.get_frame(path=context.frame) region = Region(0, 0, 1000, 70) match_result = ocr(cv2.imread(context.frame), region) for tab in MENU_SCREEN_TABS: #assert tab in match_result, f"{tab} not found in menu tabs" if tab not in match_result: debug(f"error: {tab} not found in menu tabs") else: debug(f"{tab} found in menu tabs")
def step_impl(context): # read ads watch time and program time press(context, keys.KEY_DOWN) cam = context.cam context.frame = get_frame_name(context, f"{WORK_DIR}/_frame.png") assert 200 == cam.get_frame(context.frame) shoppable_ads_detected = False if detect_shoppable_ads is True: shoppable_ads_detected = detect_shoppable_ads() else: shoppable_ads_detected = False region = Region(x=950, y=640, right=1110, bottom=720) ads = ocr(cv2.imread(context.frame), region, grayscale=True, invert_grayscale=True) debug(f"ads: {ads}") region = Region(x=1110, y=640, right=1280, bottom=720) counter = ocr(cv2.imread(context.frame), region, grayscale=True, invert_grayscale=True) debug(f"counter: {counter}") debug(f"ads/counter: {ads} / {counter}\n") assert "Ad" in ads or ":" in counter, "no ads found" current_ads, total_ads, ads_min, ads_sec = parse_ads_and_counter( ads, counter) if detect_shoppable_ads is True and shoppable_ads_detected is False: assert 200 == cam.get_frame(context.frame) shoppable_ads_detected = detect_shoppable_ads() debug( f"current_ads:{current_ads}, total_ads:{total_ads}, ads_min:{ads_min}, ads_sec:{ads_sec}, shoppable_ads_detected:{shoppable_ads_detected}" )
def step_impl(context): # read watch time and program time press(context, keys.KEY_DOWN) cam = context.cam context.frame = get_frame_name(context, f"{WORK_DIR}/_frame.png") assert 200 == cam.get_frame(context.frame) counter = ocr(cv2.imread(context.frame), REGION_PROGRESS_BAR_TIME, grayscale=True, invert_grayscale=True, ocr_parameter='-c tessedit_char_whitelist=0123456789/:') debug(f"counter: {counter}\n") assert "/" in counter, "no counter found" play_time, program_time = parse_play_time_and_program_time(counter) debug(f"play time / program time: {play_time}/{program_time}") context.play_time = play_time context.program_time = program_time
def step_impl(context, result): cam = context.cam context.frame = get_frame_name(context, f"{WORK_DIR}/_frame.png") move_to_search_result(context) for count in range(3): # search_region = regions.REGION_SIDE_PANEL_DICT[consts.SEARCH] assert 200 == cam.get_frame(context.frame) frame = cv2.imread(context.frame) read_title = ocr(region=REGION_SEARCH_TITLE, frame=frame).replace('\n', " ").upper() debug("=== Read out text: {}".format(read_title)) if result in read_title: debug(f"Find result: {result}") return result else: debug(f"Didn't find the expected {result}. Move to next poster: ") press(context, keys.KEY_RIGHT, delay=2) assert False, f"Didn't find the expected {result}."
def thank_you_purchase_popup_title(context, frame): purchase_title = ocr(frame, region=REGION_THANK_YOU_PURCHASE_POPUP_TITLE) debug(f"thank you purchase popup tile:{purchase_title}") return purchase_title
def confirm_purchase_popup_title(context, frame): purchase_title = ocr(frame, region=REGION_CONFIRM_PURCHASE_POPUP_TITLE) purchase_title_1 = ocr(frame, region=REGION_CONFIRM_PURCHASE_POPUP_TITLE, grayscale=True, invert_grayscale=True) debug(f"confirm purchase popup tile:{purchase_title}") return purchase_title
def purchase_popup_movie_title(context, frame): purchase_title = ocr(frame, region=REGION_PURCHASE_POPUP_MOVIE_TITLE) debug(f"tile:{purchase_title}") return purchase_title
def title(context): cam = context.cam context.frame = get_frame_name(context, f"{WORK_DIR}/_frame.png") assert 200 == cam.get_frame(path=context.frame) frame = cv2.imread(context.frame) return ocr(frame, region=REGION_DETAILS_PAGE_TITLE)