Esempio n. 1
0
 def __init__(self):
     self.drawing = False  # true if mouse is pressed
     self.mode = True  # 如果是True, 就画矩形. 键盘按 'm' 键就切换到曲线
     self.ix, self.iy = -1, -1
     subprocess.call(
         'adb shell /system/bin/screencap -p /data/local/tmp/screenshot.png'
     )
     time.sleep(1)
     cmd1 = 'cd ' + InitParam()._screenshotpath
     # cmd1 = "cd "+ os.path.abspath(os.path.dirname(os.getcwd())) + '/screenshot'
     cmd2 = "adb pull /data/local/tmp/screenshot.png"
     cmd = cmd1 + " && " + cmd2
     print(cmd)
     subprocess.call(cmd, shell=True)
     time.sleep(3)
     print(InitParam()._screenshotpath + '\\' + InitParam()._defaultpicname)
     self.img = cv2.imread(InitParam()._screenshotpath + '\\' +
                           InitParam()._defaultpicname)
     cv2.namedWindow('image')
     cv2.setMouseCallback('image', self.draw_circle)
     subprocess.call("adb shell rm /data/local/tmp/screenshot.png")
     while (1):
         cv2.imshow('image', self.img)
         k = cv2.waitKey(1) & 0xFF
         if k == ord('m'):  # 切换模式
             self.mode = not self.mode
         elif k == 27:  # Mei Xiu 20200225 esc键ASCII值为27,按ESC键退出
             break
     cv2.destroyAllWindows()
Esempio n. 2
0
    def draw_circle(self, event, x, y, flags, param):
        # global ix, iy, drawing, mode  # 指定这些变量为全局变量
        if event == cv2.EVENT_LBUTTONDOWN:  # 鼠标左键按下事件
            self.drawing = True
            self.ix, self.iy = x, y

        elif event == cv2.EVENT_MOUSEMOVE:  # 鼠标移动事件
            if self.drawing == True:
                if self.mode == True:
                    pass
                    # cv2.rectangle(img, (ix, iy), (x, y), (0, 255, 0), 1)#z注释后为不填充的矩形,不注释就是填充的
                else:
                    cv2.circle(self.img, (x, y), 5, (130, 66, 130), 1)

        elif event == cv2.EVENT_LBUTTONUP:  # 鼠标左键松开事件
            self.drawing = False
            if self.mode == True:
                cv2.rectangle(self.img, (self.ix, self.iy), (x, y),
                              (0, 255, 0), 1)
                with open(InitParam().roi_yaml_filepath, 'a') as f:
                    data = {
                        "key": {
                            "ix": self.ix,
                            "iy": self.iy,
                            "x": x,
                            "y": y,
                        }
                    }
                    yaml.dump(data, f)
                    f.close()
                print(self.ix, self.iy), (x, y)
            else:
                cv2.circle(self.img, (x, y), 5, (0, 0, 255), -1)
Esempio n. 3
0
 def ROI_picture_match(self, pic, row):
     tm = time.strftime("%Y%m%d_%H%M%S")
     image_path = path + "/screenshot/" + pic + ".png"
     srcImg = cv2.imread(image_path)
     self.driver.get_screenshot_as_file('filename.png')
     match = cv2.imread('filename.png')
     
     with open(InitParam().roi_yaml_filepath) as f:
         data = yaml.load(f) 
         roi = data['key'+pic]
     img_roi = srcImg[roi['iy']:(roi['iy']+roi['y']), roi['ix']:(roi['ix']+roi['x'])]
     match_roi = match[roi['iy']:(roi['iy']+roi['y']), roi['ix']:(roi['ix']+roi['x'])]
     cv2.imwrite(os.getcwd()+"/img_roi.png", img_roi)
     cv2.imwrite(os.getcwd()+"/match_roi.png", match_roi)
     PIC_roi = cv2.imread(os.getcwd()+"/img_roi.png")
     match_roi = cv2.imread(os.getcwd()+"/match_roi.png")
     grayA = cv2.cvtColor(PIC_roi, cv2.COLOR_BGR2GRAY)
     grayB = cv2.cvtColor(match_roi, cv2.COLOR_BGR2GRAY)
 
     (score, diff) = compare_ssim(grayA, grayB, full=True)
     print("SSIM: {}".format(score))
     if score < 0.95:
         os.rename(os.path.join(os.getcwd(),'filename.png'),os.path.join(path,tm+str(row)+".png"))
         return None
     return score
Esempio n. 4
0
 def vedio(self):
     cap = cv2.VideoCapture(1)  
     while(1):#连续捕捉
         ret,frame = cap.read()#cap.read()会返回一个结果
         #第一个参数ret的值为TRUE/FALSE,代表没有读到图片
         #第二个参数是frame,是当前截取一帧的图片
         if not ret: continue#解决官方程序报错的关键,因为很多摄像头返回的第一帧都无效
     #     gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)#转换成灰度图
         cv2.imshow('cap', frame)
         if cv2.waitKey(1)&0xFF == 32:
             cv2.imwrite(InitParam()._screenshotpath + InitParam()._", frame)
             Start_Thread(self.DrowROI)
         if cv2.waitKey(1)&0xFF == 27:
             cv2.imwrite(InitParam()._screenshotpath + "/screenshot.png", frame)
             break
     cap.release()#释放摄像头 
     cv2.destroyAllWindows()
Esempio n. 5
0
 def ROIqueding(self):
     name2 = self.nameinput2.get()
     print(name2)
     with open(InitParam().roi_yaml_filepath, 'r+') as fr:
         data = yaml.load(fr)
         y1 = data['key']['iy']
         x1 = data['key']['ix']
         y = data['key']['y']
         x = data['key']['x']
         data1 = {
             'key' + name2: {
                 "ix": x1,
                 "iy": y1,
                 "x": x,
                 "y": y,
             }
         }
         yaml.dump(data1, fr)
     os.rename(
         os.path.join(InitParam()._screenshotpath, 'screenshot.png'),
         os.path.join(InitParam()._screenshotpath + '\ROI\\',
                      name2 + ".png"))
Esempio n. 6
0
 def DrowROI(self):
     time.sleep(1)
     self.img = cv2.imread(InitParam()._screenshotpath + "/screenshot.png")
     cv2.namedWindow('a')
     cv2.setMouseCallback('a',self.draw_circle)
     while(1):
         cv2.imshow('a',self.img)
         k = cv2.waitKey(1) & 0xFF
         if k == ord('m'): # 切换模式
             mode = not mode
         elif k == 27:
             break
     cv2.destroyAllWindows()
Esempio n. 7
0
 def queding(self):
     name1 = self.nameinput1.get()
     print(name1)
     name_list = os.listdir(InitParam()._screenshotpath)
     if name1 + '.png' in name_list:
         tkinter.messagebox.showinfo('Error', '图片名字冲突,请重命名')
     else:
         os.rename(
             os.path.join(
                 os.path.abspath(os.path.dirname(os.getcwd())) +
                 '\screenshot', "screenshot.png"),
             os.path.join(
                 os.path.abspath(os.path.dirname(os.getcwd())) +
                 '\screenshot', name1 + ".png"))
Esempio n. 8
0
 def clearPIC(self):
     with open(InitParam().roi_yaml_filepath, 'w') as fr:
         fr.truncate()
     fr.close()
     self.del_files('../main_word')
Esempio n. 9
0
from driver.use_driver import GetByLocal
import time
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By   # By类:定位元素
import os
from common.write_user_command import WriteUserCommand
import yaml
import cv2
import common.log_confige as log
import subprocess
from common.read_config import ReadIni
from skimage.measure import compare_ssim
from common.common_param import InitParam

path = InitParam()._errorshotpath

# path = os.path.abspath(os.path.dirname(os.getcwd()))+'\error_screenshot'

class ActionMethod():
    
    def __init__(self):
        base_driver = BaseDriver()
        self.driver = base_driver.desired_setting(0)
        self.WebDriverWait = WebDriverWait
        self.EC = EC
        self.By = By
        self.get = GetByLocal(self.driver, self.WebDriverWait, self.EC, self.By)
        self.WF = WriteUserCommand()
        self.read = ReadIni()