Exemple #1
0
 def get_diff_rect(self,
                   img0,
                   img1,
                   disparities=16,
                   blur_x=-1,
                   blur_y=-1,
                   filter_core=25,
                   debug=False):
     diff_rect = self._stub.GetDiffRect(\
         imageprocess_pb2.CmpImgRequest(orgimgobj=pilimg_to_buf(img0), \
                                        cmpimgobj=pilimg_to_buf(img1), \
                                        disparities = disparities, \
                                        blur=imageprocess_pb2.Blur(x=blur_x, y=blur_y), \
                                        filter_core=filter_core
                                        ))
     width, height = img0.size
     if width == diff_rect.w and height == diff_rect.h:
         return
     if debug:
         draw = ImageDraw.Draw(img0)
         draw.rectangle(
             [(diff_rect.x, diff_rect.y),
              (diff_rect.x + diff_rect.w, diff_rect.y + diff_rect.h)],
             outline='Black')
         img0.show()
     return diff_rect
Exemple #2
0
    def compare_color_hist(self, img0, img1):
        img0_buf = pilimg_to_buf(img0)
        img1_buf = pilimg_to_buf(img1)

        d_s = self._stub.CompareColorHist(\
            imageprocess_pb2.CmpImgRequest(orgimgobj=pilimg_to_buf(img0), \
                                           cmpimgobj=pilimg_to_buf(img1)))
        return d_s.data
Exemple #3
0
 def detect_similarity(self,
                       img0,
                       img1,
                       matching_distance=0.75,
                       debug=False):
     if debug:
         ret = self._stub.DrawSimilarity(\
             imageprocess_pb2.CmpImgRequest(orgimgobj=pilimg_to_buf(img0), \
                                            cmpimgobj=pilimg_to_buf(img1), \
                                            feature_matching_distance = matching_distance))
         img = Image.open(StringIO.StringIO(ret.imgobj))
         img.show()
         return None
     match = self._stub.DetectSimilarity(\
     imageprocess_pb2.CmpImgRequest(orgimgobj=pilimg_to_buf(img0), \
                                    cmpimgobj=pilimg_to_buf(img1), \
                                    feature_matching_distance = matching_distance))
     match_pos = []
     for m in match:
         match_pos.append((m.x0, m.x1, m.x1, m.y1))
     return match_pos
    def clickMain(self):
        main_select = self.select_name  #select_list[0]

        self.preimg = FoxitReader_GetImg()
        self.preimg.save('orgimg.png')

        FoxitReader_SelectUI(self.stub, main_select)
        FoxitReader_WaitWindow()

        self.afterimg = FoxitReader_GetImg()
        self.afterimg.save('afterimg.png')

        self.diff_rect = self.stub.GetDiffRect(\
                imageprocess_pb2.CmpImgRequest(orgimgobj=pilimg_to_buf(self.preimg), \
                                               cmpimgobj=pilimg_to_buf(self.afterimg)))
def DebugGetDiffRect(img0, img1, blur_x=-1, blur_y=-1, filter_core=30):
    diff_rect = stub.GetDiffRect(\
        imageprocess_pb2.CmpImgRequest(orgimgobj=pilimg_to_buf(img0), \
                                       cmpimgobj=pilimg_to_buf(img1), \
                                       blur=imageprocess_pb2.Blur(x=blur_x, y=blur_y), \
                                       filter_core=filter_core
                                       ))
    width, height = img0.size
    if width == diff_rect.w and height == diff_rect.h:
        return

    draw = ImageDraw.Draw(img0)
    draw.rectangle([(diff_rect.x, diff_rect.y),
                    (diff_rect.x + diff_rect.w, diff_rect.y + diff_rect.h)])
    img0.show()
def FoxitReader_SelectUI(stub, ui_name, selected=-1, dropdown=False):
    template = Image.open('img/ReaderLite/Ubuntu/%s.png' % (ui_name))
    ##    template = Image.open('/home/xiaoxia_yu/Desktop/colorchage.png')
    template = template.convert('RGB')
    img = FoxitReader_GetImg()
    img.save('ReaderLite.png')
    template.save('emplate.png')
    pos = GetElementPosByImg(stub, img, template)
    ele_img = img.crop(pos)
    ele_img = ele_img.convert('RGB')
    ele_img.save('select.png')
    match = stub.DetectSimilarity(\
        imageprocess_pb2.CmpImgRequest(orgimgobj=pilimg_to_buf(ele_img), \
                                       cmpimgobj=pilimg_to_buf(template)))
    match_l = []
    for m in match:
        print(m)
        match_l.append(m)
    print('==========')
    print(match_l)
    print('==========')
    #if compareImg(ele_img, template) != 0:
    if len(match_l) < 3:
        if selected == 1:
            return
        if ui_name.find('-') == -1:
            template = seleced_color_change(template, 0)
        else:
            template = seleced_color_change(template, 1)
            template.save('template_color.png')
        print('color chage')
        template.save('template_change.png')
        pos = GetElementPosByImg(stub, img, template)

    mid_pos = (pos[0] + (pos[2] - pos[0]) / 2, pos[1] + (pos[3] - pos[1]) / 2)
    if pos != None:
        print('click:', mid_pos)
        FoxitReader_ClickPos(mid_pos)
    def clickMain(self):
        menu_list = self.menu_name.split('-')
        main_menu = menu_list[0]

        # Get Menu Bar.
        abs_rect = (0, 0, 0, 25)
        menu_map = FoxitReader_ParseUI(self.stub, abs_rect)

        pos = self.getpos(menu_map, main_menu)

        # Get Image before click main menu.
        self.menu_offset = (pos[0], 25, 0.3, -25)
        ##        print('Orgimge Rect:', user_rect)
        img0 = FoxitReader_GetImg(self.menu_offset, 'LA')
        img0.save('orgimg.png', quality=5)

        # Click main menu.
        menu_pos = (pos[0]+pos[2]/2, \
                    pos[1]+pos[3]/2)
        print("POs:", pos)
        print("MenuPOs:", menu_pos)
        FoxitReader_ClickPos(menu_pos)

        time.sleep(1)

        # Get image after click main menu.
        ##        abs_rect = (0, 25, 0.3, -25)
        img1 = FoxitReader_GetImg(self.menu_offset, 'LA')
        img1.save('afterimg.png', quality=5)
        self.afterimg = img1.copy()

        self.menu_dropdown_rect = self.stub.GetDiffRect(\
            imageprocess_pb2.CmpImgRequest(orgimgobj=pilimg_to_buf(img0), \
                                           cmpimgobj=pilimg_to_buf(img1)))
        if self.menu_dropdown_rect.x == -1:
            return self.clickMain()
def DebugDetectSimilarity(img0, img1, blur_x=-1, blur_y=-1, filter_core=30):
    ret = stub.DrawSimilarity(\
        imageprocess_pb2.CmpImgRequest(orgimgobj=pilimg_to_buf(img0), \
                                       cmpimgobj=pilimg_to_buf(img1)))
    img = Image.open(StringIO.StringIO(ret.imgobj))
    img.show()