摄像头画面作为电脑桌面背景

2024-01-05 02:40

本文主要是介绍摄像头画面作为电脑桌面背景,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1. 创建文件main.pyw,文件内容

import base64
import io
import os
import threading
import tkinter as tkimport cv2
import pystray
import win32api
import win32con
import win32gui
from PIL import Image, ImageTk
from pystray import MenuItem, Menuclass Window:def __init__(self):self.window = tk.Tk()self.window.geometry("320x200")self.canvas = tk.Canvas(self.window, width=320, height=180)self.canvas.place(x=0, y=0)self.label_str = tk.StringVar()label = tk.Label(self.window, textvariable=self.label_str)label.place(x=0, y=180)self.top_label_str = tk.StringVar()top_label = tk.Label(self.window, textvariable=self.top_label_str)top_label.place(x=100, y=180)self.capture = Noneself.delay = 15self.show = True# 修改壁纸样式reg_key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, win32con.KEY_SET_VALUE)win32api.RegSetValueEx(reg_key, "WallpaperStyle", 0, win32con.REG_SZ, "2")win32api.RegSetValueEx(reg_key, "TileWallpaper", 0, win32con.REG_SZ, "0")def quit_window(self, icon: pystray.Icon):icon.stop()self.window.destroy()self.show = Falsedef show_window(self):self.window.deiconify()self.show = Truedef on_exit(self):self.window.withdraw()def set_topmost(self):topmost = self.window.attributes("-topmost")if topmost:self.window.attributes("-topmost", False)self.top_label_str.set("")else:self.show_window()self.window.attributes("-topmost", True)self.top_label_str.set("已置顶")def init_capture(self):try:self.label_str.set("摄像头加载中")self.capture = cv2.VideoCapture(0)self.capture.set(3, 1920)self.capture.set(4, 1080)self.update_canvas()self.label_str.set("摄像头加载完成")except:self.label_str.set("摄像头加载失败")def update_canvas(self):ret, frame = self.capture.read()if ret:file_path = os.getcwd() + "/1.png"cv2.imwrite(file_path, frame)# 设置壁纸win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, file_path, win32con.SPIF_SENDWININICHANGE)if self.show:img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)img = Image.fromarray(img)img = ImageTk.PhotoImage(img.resize((320, 180)))self.canvas.imgtk = imgself.canvas.create_image(0, 0, anchor=tk.NW, image=img)# 重复更新画布self.window.after(self.delay, self.update_canvas)def start(self):# 菜单menu = (MenuItem('显示', self.show_window, default=True),Menu.SEPARATOR,MenuItem('置顶', self.set_topmost),Menu.SEPARATOR,MenuItem('退出', self.quit_window))image_bytes = base64.b64decode("iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IArs4c6QAAHrZJREFUeF7tnXmcVNWVx3/nVTctyiYgYa2mEUSMRiMaMdFJJCaaqIkLLpmIgarqqsYkTBaXZDQYNXHG6EwSJwNd1V3VqDju4h41CZooiUYgUYkoEJuuZhVBsAHtpd6Z3ILXFJ1u+r1Xb7tdt/7Rz4e7nPM799v33ffOvZegfkoBpUCPCpDSRimgFOhZAQWIGh1KgYMooABRw0MpoABRY0ApYE8BNYPY003VKhEFFCAlEmjlpj0FFCD2dFO1SkQBBUiJBFq5aU8BBYg93VStElFAAVIigVZu2lNAAWJPNzO1KJuOjNI7eKRGZUcQcsN1HUOJMARMg6DRAGY+TAMOYaACQD8QQmAigHUAOQDtDLSC+UMi2k1AC4M+APH7ALZrOrYy5d4Nod+m0YnUe2aMUmWsKaAAsabXAaX/nowP1nL6FE3TjyLSJhJhAoPHEyPMwFgAXur7EYBmgJqYuVEjrGVgdRlCb41OpN4qws2SruplAKUWes0dsbEVFXwSwCcCdAKA4wCMl8IpQhsYbwB4DeAVOfCyqkTDK1LY7rORCpAeArCuLjZFy+mfZWingfjTBFT5HCunu28D4Y8AXgqBfz96SMvzdMmD4rFO/QoUUIDsE2NjMn5ojjq+pOt0FhHORN8D4uADn9DGOn4Lome1ED89LpZeq0jx9hk5cHo3NswaEmoPXQjGVwE+DxALZPXbp8CyfzxKPqpreGR8df2qUlWlJAdEU+3sGSDtMgIuKtXAW/KbsRRE9+b6ddxTNXvhDkt1JS9cMoA0JmcdrSE0m4ArAIyUPG4+mc8M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bTF4DoLDuOqjoBUYD5WT2kzfEyZb0Yz6UBpHNdEtBbdYsJQunU9W4noFOaSgeIcHx9XWyaznw7OFgXhzoVlD7XDmGpRnSVF3vIndZOSkAMEZqT0WsYuAVAyGlhVHuOKJAj4N/dPprHEUt7aERqQIRPm+tiVa0636T2lrg5TKy3LU48rNBonpuHulm3ynoN6QExXG5KRc4kna5T+0usDwJHazBeYI1/6tZZuY7aaqKxPgOI4ev6ZPRiHXw1QCeb8F8VcUwBflUD3ebGFQSOmWijoT4HSMGMcgmB5qqFvI1RYaUKYSmD73D6ZicrJrhZts8CYoiWTVWfBXACzBe4KWTJtU20GKCkkxdmBlHDPg+IIXpjctbRGkKzCRC5XSODGAwJbNrMwF06cg1O3UMedJ9LBpDCQDTVzp4B0i4j4KKgBygI9jHwMFi/r7KmQWxDKKlfSQLSOas0zBoSag9dCMZXAT4PoJLWY//IZwboCRAey5XnHqmavXBHSVFR4KwaEPvE2JiMH5qjji/pOp1FhDMBVJXYoGhkxm81jZ8NcdmvRydSe0rM/27dVYD0MArW1cWmaDn9swztNBB/mvoYMAw0gumPBP0lPaT9fnx1/SoFxD8roAAxOSrW3BEbW1HBJwF8IkAnADgOwHiT1f0utg4QV+HxXwFa0dpKyybNrV/vt1Ey9K8AKSJKf0/GB2s5fYqm6UcRaROJMIHB44kRZmCs23dAFpjOBKxnQpZA65jxDrO+Vte11XpIW3VkIrWzCDdLuqoCxL3wUzYdGaV38EiNyo4g5IbrOoYSYQiYBkGjAcx8mAYcwkAFgH6gfUmXjByANgJadeAjItoNnXeB+ANm7NA0bGeE3tO5Y6tWRpvD0cwmAOyeK6XbsgKkdGOvPDehgALEhEiqSOkqoAAp3dgrz00ooAAxIZIqUroKKEBKN/bKcxMKKEBMiKSKlK4CCpDSjb3y3IQCChATIqkipauAAqR0Y688N6GAAsSESKpI6SqgACnd2CvPTSjw/7bmn6o8qtUUAAAAAElFTkSuQmCC")image_data = io.BytesIO(image_bytes)image = Image.open(image_data)icon = pystray.Icon("icon", image, "图标名称", menu)threading.Thread(target=icon.run, daemon=True).start()threading.Thread(target=self.init_capture, daemon=True).start()# 重新定义点击关闭按钮的处理self.window.protocol('WM_DELETE_WINDOW', self.on_exit)self.window.title('摄像壁纸')self.window.mainloop()if __name__ == '__main__':window = Window()window.start()

2. 创建文件requirements.txt,文件内容

numpy==1.26.2
opencv-python==4.8.1.78
Pillow==10.1.0
pystray==0.19.5
pywin32==306
six==1.16.0

3. 安装依赖

pip install -r requirements.txt

4. 运行

双击main.pyw

在这里插入图片描述
防火布

github下载代码

git clone https://github.com/weiangongsi/wallpaper-camera.git

从上面第3步开始执行

这篇关于摄像头画面作为电脑桌面背景的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/571407

相关文章

基于Python开发电脑定时关机工具

《基于Python开发电脑定时关机工具》这篇文章主要为大家详细介绍了如何基于Python开发一个电脑定时关机工具,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 简介2. 运行效果3. 相关源码1. 简介这个程序就像一个“忠实的管家”,帮你按时关掉电脑,而且全程不需要你多做

C#实现获取电脑中的端口号和硬件信息

《C#实现获取电脑中的端口号和硬件信息》这篇文章主要为大家详细介绍了C#实现获取电脑中的端口号和硬件信息的相关方法,文中的示例代码讲解详细,有需要的小伙伴可以参考一下... 我们经常在使用一个串口软件的时候,发现软件中的端口号并不是普通的COM1,而是带有硬件信息的。那么如果我们使用C#编写软件时候,如

macOS怎么轻松更换App图标? Mac电脑图标更换指南

《macOS怎么轻松更换App图标?Mac电脑图标更换指南》想要给你的Mac电脑按照自己的喜好来更换App图标?其实非常简单,只需要两步就能搞定,下面我来详细讲解一下... 虽然 MACOS 的个性化定制选项已经「缩水」,不如早期版本那么丰富,www.chinasem.cn但我们仍然可以按照自己的喜好来更换

python写个唤醒睡眠电脑的脚本

《python写个唤醒睡眠电脑的脚本》这篇文章主要为大家详细介绍了如何使用python写个唤醒睡眠电脑的脚本,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 环境:win10python3.12问题描述:怎么用python写个唤醒睡眠电脑的脚本?解决方案:1.唤醒处于睡眠状

不删数据还能合并磁盘? 让电脑C盘D盘合并并保留数据的技巧

《不删数据还能合并磁盘?让电脑C盘D盘合并并保留数据的技巧》在Windows操作系统中,合并C盘和D盘是一个相对复杂的任务,尤其是当你不希望删除其中的数据时,幸运的是,有几种方法可以实现这一目标且在... 在电脑生产时,制造商常为C盘分配较小的磁盘空间,以确保软件在运行过程中不会出现磁盘空间不足的问题。但在

电脑显示hdmi无信号怎么办? 电脑显示器无信号的终极解决指南

《电脑显示hdmi无信号怎么办?电脑显示器无信号的终极解决指南》HDMI无信号的问题却让人头疼不已,遇到这种情况该怎么办?针对这种情况,我们可以采取一系列步骤来逐一排查并解决问题,以下是详细的方法... 无论你是试图为笔记本电脑设置多个显示器还是使用外部显示器,都可能会弹出“无HDMI信号”错误。此消息可能

电脑多久清理一次灰尘合? 合理清理电脑上灰尘的科普文

《电脑多久清理一次灰尘合?合理清理电脑上灰尘的科普文》聊起电脑清理灰尘这个话题,我可有不少话要说,你知道吗,电脑就像个勤劳的工人,每天不停地为我们服务,但时间一长,它也会“出汗”——也就是积累灰尘,... 灰尘的堆积几乎是所有电脑用户面临的问题。无论你的房间有多干净,或者你的电脑是否安装了灰尘过滤器,灰尘都

Python实现局域网远程控制电脑

《Python实现局域网远程控制电脑》这篇文章主要为大家详细介绍了如何利用Python编写一个工具,可以实现远程控制局域网电脑关机,重启,注销等功能,感兴趣的小伙伴可以参考一下... 目录1.简介2. 运行效果3. 1.0版本相关源码服务端server.py客户端client.py4. 2.0版本相关源码1

闲置电脑也能活出第二春?鲁大师AiNAS让你动动手指就能轻松部署

对于大多数人而言,在这个“数据爆炸”的时代或多或少都遇到过存储告急的情况,这使得“存储焦虑”不再是个别现象,而将会是随着软件的不断臃肿而越来越普遍的情况。从不少手机厂商都开始将存储上限提升至1TB可以见得,我们似乎正处在互联网信息飞速增长的阶段,对于存储的需求也将会不断扩大。对于苹果用户而言,这一问题愈发严峻,毕竟512GB和1TB版本的iPhone可不是人人都消费得起的,因此成熟的外置存储方案开

流媒体平台/视频监控/安防视频汇聚EasyCVR播放暂停后视频画面黑屏是什么原因?

视频智能分析/视频监控/安防监控综合管理系统EasyCVR视频汇聚融合平台,是TSINGSEE青犀视频垂直深耕音视频流媒体技术、AI智能技术领域的杰出成果。该平台以其强大的视频处理、汇聚与融合能力,在构建全栈视频监控系统中展现出了独特的优势。视频监控管理系统EasyCVR平台内置了强大的视频解码、转码、压缩等技术,能够处理多种视频流格式,并以多种格式(RTMP、RTSP、HTTP-FLV、WebS