当前位置: 首页 > news >正文

Excel为数据绘制拆线图,并将均值线叠加在图上,以及整个过程的区域录屏python脚本

Excel为数据绘制拆线图,并将均值线叠加在图上,以及整个过程的区域录屏python脚本

  • 1.演示动画
    • A.视频
    • B.gif动画
  • 2.跟踪鼠标区域的录屏脚本

Excel中有一组数据,希望画出曲线,并且能把均值线也绘制在图上,以下动画演示了整个过程,并且提供了区域录屏脚本,原理如下:
为节约空间,避免剪辑,只记录有效区域【仅记录鼠标区域且图像变化的图片】

1.演示动画

A.视频

Excel为数据绘制拆线图,并将均值线叠加在图上

B.gif动画

请添加图片描述

2.跟踪鼠标区域的录屏脚本

import cv2
import numpy as np
import mss
import time
import threading
import pyautogui
import datetime
from skimage.metrics import structural_similarity as ssim
from pynput import mousedef compute_ssim(imageA, imageB):"""计算两幅图像的结构相似性指数(SSIM)"""grayA = cv2.cvtColor(imageA, cv2.COLOR_BGR2GRAY)grayB = cv2.cvtColor(imageB, cv2.COLOR_BGR2GRAY)(score, diff) = ssim(grayA, grayB, full=True)return scoredef resize_and_pad(image, size=(640, 640)):"""等比缩放并填充图像"""h, w = image.shape[:2]scale = min(size[0] / w, size[1] / h)new_w, new_h = int(w * scale), int(h * scale)resized_image = cv2.resize(image, (new_w, new_h))# 创建黑色背景top = (size[1] - new_h) // 2bottom = size[1] - new_h - topleft = (size[0] - new_w) // 2right = size[0] - new_w - leftpadded_image = cv2.copyMakeBorder(resized_image, top, bottom, left, right, cv2.BORDER_CONSTANT, value=[0, 0, 0])return padded_imageis_mouse_pressed=False
def on_click(x, y, button, pressed):global is_mouse_pressedis_mouse_pressed = presseddef capture_screen(stop_event):layout_w=720layout_h=1280mouse_listener = mouse.Listener(on_click=on_click)mouse_listener.start()with mss.mss() as sct:# 初始化第一帧monitor = sct.monitors[1]print(monitor)frame1 = Nonescreen_width = monitor["width"]screen_height = monitor["height"]fourcc = cv2.VideoWriter_fourcc(*'XVID')out = cv2.VideoWriter('output.avi', fourcc, 3.0, (layout_w, layout_h))area=Nonewhile not stop_event.is_set():mouse_x, mouse_y = pyautogui.position()    if area:if mouse_x<area['left'] or mouse_x>area['left']+layout_w or mouse_y<area['top'] or mouse_y>area['top']+layout_h:area=Noneif area is None and is_mouse_pressed:                    # 计算截取区域,以鼠标为中心640x640,同时进行边界检查left = max(0, min(screen_width - layout_w, mouse_x - layout_w // 2))top = max(0, min(screen_height - layout_h, mouse_y - layout_h // 2))area = {'top': top, 'left': left, 'width': layout_w, 'height': layout_h}if area:frame2 = np.array(sct.grab(area))frame2 = cv2.cvtColor(frame2, cv2.COLOR_BGRA2BGR)# 在 frame2 上绘制一个小圆点标记鼠标位置relative_mouse_x = mouse_x - area['left']relative_mouse_y = mouse_y - area['top']cv2.circle(frame2, (relative_mouse_x, relative_mouse_y), 5, (0, 0, 255), -1)  # 红色小圆点frame2=resize_and_pad(frame2,(layout_w,layout_h))if frame1 is None:frame1 = frame2.copy()continuescore = compute_ssim(frame1, frame2)if score<1.0:out.write(frame2)frame1 = frame2.copy()# 适量的延时,防止过高的CPU使用率time.sleep(0.1)out.release()if __name__ == '__main__':stop_event = threading.Event()# 启动屏幕捕捉的线程capture_thread = threading.Thread(target=capture_screen, args=(stop_event,))capture_thread.start()# 等待用户输入'q'以停止捕捉while True:if input().strip().lower() == 'q':stop_event.set()break# 等待屏幕捕捉线程结束capture_thread.join()print("捕获已结束并退出。")from moviepy.editor import VideoFileClip# 定义视频文件路径和输出GIF文件路径input_video_path = 'output.avi'output_gif_path = 'output.gif'# 加载视频文件clip = VideoFileClip(input_video_path)clip = clip.subclip(3, -2)clip = clip.resize(0.4)# 将视频剪辑转换为GIFclip.write_gif(output_gif_path, fps=2)print(f"GIF文件保存到 {output_gif_path}")
http://www.lryc.cn/news/391324.html

相关文章:

  • 易保全推动区块链应用与AI融合创新发展
  • C++(Python)肥皂泡沫普拉托边界膜曲面模型算法
  • VBA打开其他Excel文件
  • 模拟 ADC 的前端
  • tls各个版本的安全性介绍
  • PHP家政服务预约单开版微信小程序系统源码
  • 数据增强:目标检测算法中的性能提升利器
  • KVB交易平台 :市场迎来新热潮!铜价会持续上涨吗?
  • React@16.x(44)路由v5.x(9)源码(1)- path-to-regexp
  • C#面:String str=new String(“a“)和String str = “a“有什么区别
  • CS算法(二)—— 斜视SAR点目标仿真
  • 2024亚洲国际餐饮展览会(北京餐饮展|火锅展|预制菜展会)
  • 【RabbitMQ问题踩坑】RabbitMQ设置手动ack后,消息队列有多条消息,只能消费一条,就不继续消费了,这是为什么 ?
  • 深度解码:需求跟踪的艺术与实战应用
  • 数据结构——树的基础概念
  • TimerManager和Timer
  • 手写Spring-MVC之前后置处理器与异常处理、数据库框架
  • 学习笔记(linux高级编程)11
  • vite+vue3+nginx配置统一公共前缀
  • android 国内下载Gradle源
  • mysql8一键安装脚本(linux) 拿走即用
  • C# 开发Winform DataGridView的增删改查实战
  • CentOS 7镜像列表服务下线,还想继续使用该怎么办?
  • 代码随想录训练营第二十八天 122买卖股票的最佳时间II 55跳跃游戏 45跳跃游戏II 1005K次取反后最大化的数组和
  • 在node环境使用MySQL
  • spdlog一个非常好用的C++日志库(四): 源码分析之logger类
  • 逻辑这回事(七)---- 器件基础
  • 中俄汽车产业链合作前景广阔,东方经济论坛助力双边合作与创新
  • 第六篇:精通Docker Compose:打造高效的多容器应用环境
  • C++视觉开发 一.OpenCV环境配置