def clickChild(self, select_name): diff_img = self.afterimg.crop((self.diff_rect.x, \ self.diff_rect.y, \ self.diff_rect.x+self.diff_rect.w, \ self.diff_rect.y+self.diff_rect.h)) diff_img.save('popup_window.png') print(self.diff_rect) img_buf = pilimg_to_buf(diff_img) eles = self.stub.DetectElements(\ imageprocess_pb2.DetectImg(imgobj=img_buf, \ thresh=53, \ blur=imageprocess_pb2.Blur(x=self.detect_blur[0], y=self.detect_blur[1]), \ pre=imageprocess_pb2.PreProcess(enable=self.preprocess_enable, zoom=self.preprocess_zoom))) ele_rect = [] txt_pos_map = {} for ele in eles: e_r = (ele.x, ele.y, ele.w, ele.h) ele_rect.append(e_r) #print('x:%d, y:%d, w:%d, h:%d' % (ele.x, ele.y, ele.w, ele.h)) ele_img = diff_img.crop( (ele.x, ele.y, ele.x + ele.w, ele.y + ele.h)) #print(ele_img) img_buf = pilimg_to_buf(ele_img) ocr_txt = self.stub.OCR( imageprocess_pb2.ImgRequest(imgobj=img_buf)) txt = (ocr_txt.txt).encode('utf8') txt_pos_map[txt] = (ele.x, ele.y, ele.w, ele.h) print(txt) pos = self.getpos(txt_pos_map, select_name) ele_pos = (self.diff_rect.x + pos[0]+pos[2]/2, \ self.diff_rect.y + pos[1]+pos[3]/2) FoxitReader_ClickPos(ele_pos)
def FoxitReader_ParseUI(stub, user_rect=None): img = FoxitReader_GetImg(user_rect) img.save('tem.png') img_buf = pilimg_to_buf(img) eles = stub.DetectElements(\ imageprocess_pb2.DetectImg(imgobj=img_buf, \ thresh=123, \ blur=imageprocess_pb2.Blur(x=5, y=5), \ pre=imageprocess_pb2.PreProcess(enable=False, zoom=1))) ele_rect = [] txt_pos_map = {} for ele in eles: ## if ele.w > 100 or ele.h > 100: ## continue e_r = (ele.x, ele.y, ele.w, ele.h) ele_rect.append(e_r) #print('x:%d, y:%d, w:%d, h:%d' % (ele.x, ele.y, ele.w, ele.h)) ele_img = img.crop((ele.x, ele.y, ele.x + ele.w, ele.y + ele.h)) #print(ele_img) img_buf = pilimg_to_buf(ele_img) ocr_txt = stub.OCR(imageprocess_pb2.ImgRequest(imgobj=img_buf)) txt = (ocr_txt.txt).encode('utf8') txt_pos_map[txt] = (ele.x, ele.y, ele.w, ele.h) print(txt) #dr.rectangle(((ele.x, ele.y),(ele.x+ele.w, ele.y+ele.h)), outline = "red") #image.save('tem.png') return txt_pos_map
def detect_elements(self, img, thresh, blur_x=5, blur_y=5, filter=False, zoom=1, filter_core=25, debug=False): img_buf = pilimg_to_buf(img) eles = self._stub.DetectElements(\ imageprocess_pb2.DetectImg(imgobj=img_buf, \ thresh=thresh, \ blur=imageprocess_pb2.Blur(x=blur_x, y=blur_y), \ filter=imageprocess_pb2.FilterP(enable=filter, \ zoom=zoom, \ core=filter_core))) ele_l = [] for ele in eles: e_r = (ele.x, ele.y, ele.w, ele.h) ele_l.append(e_r) if debug: print(e_r) draw = ImageDraw.Draw(img) draw.rectangle([(ele.x, ele.y), (ele.x + ele.w, ele.y + ele.h)], outline='Red') if debug: img.show() return ele_l
def DebugDetectElements(img, thresh, blur_x=5, blur_y=5, preprocess=False, zoom=1): img_buf = pilimg_to_buf(img) eles = stub.DetectElements(\ imageprocess_pb2.DetectImg(imgobj=img_buf, \ thresh=thresh, \ blur=imageprocess_pb2.Blur(x=blur_x, y=blur_y), \ pre=imageprocess_pb2.PreProcess(enable=preprocess, zoom=zoom))) for ele in eles: e_r = (ele.x, ele.y, ele.w, ele.h) draw = ImageDraw.Draw(img) draw.rectangle([(ele.x, ele.y), (ele.x + ele.w, ele.y + ele.h)]) img.show()
def clickChild(self): menu_list = self.menu_name.split('-') for menu_n in menu_list[1:]: menu_img = self.afterimg.crop((self.menu_dropdown_rect.x, \ self.menu_dropdown_rect.y, \ self.menu_dropdown_rect.x+self.menu_dropdown_rect.w, \ self.menu_dropdown_rect.y+self.menu_dropdown_rect.h)) menu_img.save('menu_dropdown.png', quality=5) print(self.menu_dropdown_rect) img_buf = pilimg_to_buf(menu_img) eles = self.stub.DetectElements(\ imageprocess_pb2.DetectImg(imgobj=img_buf, \ thresh=10, \ blur=imageprocess_pb2.Blur(x=17, y=17), \ pre=imageprocess_pb2.PreProcess(enable=True, zoom=2.5))) ele_rect = [] txt_pos_map = {} for ele in eles: e_r = (ele.x, ele.y, ele.w, ele.h) ele_rect.append(e_r) #print('x:%d, y:%d, w:%d, h:%d' % (ele.x, ele.y, ele.w, ele.h)) ele_img = menu_img.crop( (ele.x, ele.y, ele.x + ele.w, ele.y + ele.h)) #print(ele_img) img_buf = pilimg_to_buf(ele_img) ocr_txt = self.stub.OCR( imageprocess_pb2.ImgRequest(imgobj=img_buf)) txt = (ocr_txt.txt).encode('utf8') txt_pos_map[txt] = (ele.x, ele.y, ele.w, ele.h) print(txt) ## abs_rect = (0, 25, 0, -25) pos = self.getpos(txt_pos_map, menu_n, False) # Click menu. menu_pos = (self.menu_offset[0]+pos[0]+pos[2]/2, \ self.menu_offset[1]+pos[1]+pos[3]/2) print(menu_pos) FoxitReader_ClickPos(menu_pos)