コード例 #1
0
    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)
コード例 #2
0
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
コード例 #3
0
    def get_hist_array(self, img):
        img_buf = pilimg_to_buf(img)
        hist = self._stub.GetHistArray(
            imageprocess_pb2.ImgRequest(imgobj=img_buf))

        hist_arr = []
        for data in hist:
            hist_arr.append(data.y)
        return hist_arr
コード例 #4
0
def FoxitReader_WaitConnect(stub, timeout=10):
    for i in range(timeout):
        img = GetReaderImg()
        img_buf = pilimg_to_buf(img)
        hist = stub.GetHistArray(imageprocess_pb2.ImgRequest(imgobj=img_buf))
        hist_arr = []
        for data in hist:
            hist_arr.append(data.y)
        if hist_arr[255] != 255:
            time.sleep(1)
            print('Connect Wait.')
        else:
            print('Connect OK.')
            return True

    return False
コード例 #5
0
    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)
コード例 #6
0
 def ocr_text(self, img):
     img_buf = pilimg_to_buf(img)
     ocr_txt = self._stub.OCR(imageprocess_pb2.ImgRequest(imgobj=img_buf))
     txt = (ocr_txt.txt).encode('utf8')
     return txt