2023年2月

PIL系统截图、cv2图片匹配

from PIL import ImageGrab
import cv2
import numpy as np

from utils.windows import mouseMove, mouseClick


def mathc_img(Target, value = 0.9):
    try:
        im = np.array(ImageGrab.grab())
        img_gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
        template = cv2.imread(Target, 0)
        res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
        threshold = value
        loc = np.where(res >= threshold)
        return (int(loc[1][0]), int(loc[0][0]))
    except :
        raise Exception('未匹配到图片')


def imageSearchClick(Target, x_, y_):
    mouseMove(0, 0)
    x, y = mathc_img(Target)
    mouseMove(x + x_, y + y_)
    mouseClick()
    mouseMove(0, 0)



if __name__ == '__main__':
    # x, y = mathc_img(r'C:\Users\btc\Desktop\1.PNG')
    # mouseMove(x, y)
    imageSearchClick(r'C:\invoicePrint\images\tool0.PNG', 50, 30)

其中的 mouseClick和mouseMove是我自己定义的操作鼠标函数,采用pywin32写的

安装

汉化

1、ctrl+shift+P 组合键 启动命令模式

2、搜索

Configure display language

3、install add language packs

4、选择中文语言包安装,右下角提示用户更新语言,选择确定重启vscode

报错处理

Unable to install extension 'ms-ceintl.vscode-language-pack-zh-hans' as it is not compatible with VS Code '1.37.1'.

更换语言包版本版本就好了

Unable to install extension 'ms-ceintl.vscode-language-pack-zh-hans' as it is not compatible with VS Code '1.37.1'.

该情况是extension没有权限,更改目录权限就好 原博主链接

sudo chown -R 你的用户名 ~/.vscode/extensions

ubuntu主机名相关问题

1、修改hostname 文件

该文件中的内容是显示的主机名

sudo vim /etc/hostname

2、修改hosts 文件

如果执行sudo命令出现

sudo: unable to resolve host
(无法解析主机)

修改 hosts文件 将127.0.0.1 后的内容改为主机名

sudo vim /etc/hosts

内容:

127.0.0.1       localhost
				
# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

将localhost改为主机名

3、更改完后 重启主机

sudo reboot

连接成功host警告

Warning: Permanently added the RSA host key for IP address '13.229.188.59' to the list of known hosts.

解决办法

liunx

vim /etc/hosts
添加 13.229.188.59 github.com

windows

C:\Windows\System32\drivers\etc\hosts  
添加 13.229.188.59 github.com

测试:

ssh -T git@github.com

终端自动显示分支

vi ~/.bashrc

### 显示git分支

function git_branch {  
   branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"  
   if [ "${branch}" != "" ];then  
       if [ "${branch}" = "(no branch)" ];then  
           branch="(`git rev-parse --short HEAD`...)"  
       fi  
       echo " ($branch)"  
   fi  
}  

export PS1='\u@\h \[\033[01;36m\]\W\[\033[01;32m\]$(git_branch)\[\033[00m\] \$ '  

刷新bash

sourc e .bashrc