参考这篇文章 如何使用 Python 在屏幕上绘制一个空矩形
机翻的大佬给出了两种方案
一种是创建矩形绘制器,然后刷新整个屏幕
import win32gui
import win32ui
from win32api import GetSystemMetrics
if __name__ == '__main__':
dc = win32gui.GetDC(0)
dcObj = win32ui.CreateDCFromHandle(dc)
hwnd = win32gui.WindowFromPoint((0, 0))
monitor = (0, 0, GetSystemMetrics(0), GetSystemMetrics(1))
while True:
m = win32gui.GetCursorPos()
dcObj.Rectangle((m[0], m[1], m[0] + 30, m[1] + 30))
win32gui.InvalidateRect(hwnd, monitor, True)
而另一种是绘制指定的像素点位置,然后刷新部分区域
import win32gui, win32ui, win32api, win32con
from win32api import GetSystemMetrics
dc = win32gui.GetDC(0)
dcObj = win32ui.CreateDCFromHandle(dc)
hwnd = win32gui.WindowFromPoint((0,0))
monitor = (0, 0, GetSystemMetrics(0), GetSystemMetrics(1))
red = win32api.RGB(255, 0, 0)
past_coordinates = monitor
while True:
m = win32gui.GetCursorPos()
rect = win32gui.CreateRoundRectRgn(*past_coordinates, 2 , 2)
win32gui.RedrawWindow(hwnd, past_coordinates, rect, win32con.RDW_INVALIDATE)
for x in range(10):
win32gui.SetPixel(dc, m[0]+x, m[1], red)
win32gui.SetPixel(dc, m[0]+x, m[1]+10, red)
for y in range(10):
win32gui.SetPixel(dc, m[0], m[1]+y, red)
win32gui.SetPixel(dc, m[0]+10, m[1]+y, red)
past_coordinates = (m[0]-20, m[1]-20, m[0]+20, m[1]+20)
import win32gui
import win32ui
import win32con
import win32api
from win32api import GetSystemMetrics
if __name__ == '__main__':
dc = win32gui.GetDC(0)
pen = win32gui.CreatePen(win32con.PS_GEOMETRIC, 1, win32api.RGB(255, 0, 0))
win32gui.SelectObject(dc, pen)
screen_w, screen_h = 1920, 1080
w_size, h_size = 10, 6
for x in range(0, screen_w, screen_w//w_size):
win32gui.MoveToEx(dc, x, 0)
win32gui.LineTo(dc, x, screen_h)
for y in range(0, screen_h, screen_h//h_size):
win32gui.MoveToEx(dc, 0, y)
win32gui.LineTo(dc, screen_w, y)
dcObj = win32ui.CreateDCFromHandle(dc)
hwnd = win32gui.WindowFromPoint((0, 0))
monitor = (0, 0, GetSystemMetrics(0), GetSystemMetrics(1))
red = win32api.RGB(255, 0, 0)
past_coordinates = monitor
while True:
m = win32gui.GetCursorPos()
import xml.dom.minidom
import cv2 as cv
ImgPath = 'C:/Users/49691/Desktop/gangjin/gangjin_test/JPEGImages/'
AnnoPath = 'C:/Users/49691/Desktop/gangjin/gangjin_test/Annotations/' #xml文件地址
save_path = ''
def draw_anchor(ImgPath,AnnoPath,save_path):
imagelist = os.listdi
def on_mouse(event, x, y, flags, param):
global imgMouse, point1, point2
img2 = imgMouse.copy()
if event == cv2.EVENT_LBUTTONDOWN: #左键
import cv2
#img=cv2.rectangle(img,(100,100),(500,500),(0,255,0),3)
'''边框的左上角的像素坐标是(100,100),右下角的像素坐标是(500,500),且一定要注意,像素坐标值都是正整数;
(0,255,0)表示边框颜色是绿色;
后面的3,表示边框的线宽度为3'''
def draw(img,left,right,color):
#img=cv2.imread(spath)
img=cv2.rectangle(img,
对api不熟,网上python实用代码也不多,截图虽然有直接的代码,但是描述不全。连猜带蒙终于搞定了用pywin32对win屏幕截图,并在所需要截图的位置画框。作为纪念,留个爪子,分享一下喜悦。如果有大神经过,觉得代码写的不好,不妨帮忙改改。def winsst(argw=0,argh=0,argtopleft=(0,0)):
'''截图,输出Bitmapsbits的列表
argw...
import matplotlib.pyplot as plt
list1=[1,2,1,2,0,0,1,0,0]#角度1
list2=[2,1,0,1,2,0,2,0,1]#角度2
list3=[1,2,1,1,2,0,2,0,2]#角度3
真正解决prometheus Error on ingesting samples that are too old or are too far into the future的问题
真正解决prometheus Error on ingesting samples that are too old or are too far into the future的问题
wdgde:
python 在屏幕上绘制方框
CSDN-Ada助手:
编译preload.ts为js到.quasar/electron下
CSDN-Ada助手:
真正解决prometheus Error on ingesting samples that are too old or are too far into the future的问题
firewalld_009:
真正解决prometheus Error on ingesting samples that are too old or are too far into the future的问题
君不见走马川行雪海边 平沙莽莽黄入天: