# 导入库 import PIL from PIL import Image,ImageTk import cv2 from tkinter import *# 设定宽度、高度 width, height = 800, 540 cap = cv2.VideoCapture(0)# 设置宽度,高度 cap.set(cv2.CAP_PROP_FRAME_WIDTH, width) cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)root = Tk() root.bind('<Escape>', lambda e: root.quit())def motion(event):pos = ("(%s x %s)" % (event.x, event.y))possition_lb.configure(text=pos)def show_frame():# 从摄像头获取图片_, frame = cap.read()frame = cv2.flip(frame, 1)# 将图片类型从 BGR 转换为 RGB 或 RGBAcv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)# 转换为 PIL图片img = PIL.Image.fromarray(cv2image)imgtk = ImageTk.PhotoImage(image=img)img_lb.imgtk = imgtk# 配置要显示的?????图片img_lb.configure(image=imgtk)# 10 毫秒后调用 show_frame()img_lb.after(10, show_frame)# 设定标签以显示视频??????? img_lb = Label(root,width=800,height=560) # 捕捉鼠标 img_lb.bind('<Motion>',motion) img_lb.pack()text_lb = Label(root,width=15,height=2, text= "Mouse position :") text_lb.place(x=2, y=575) # 设定标签以显示位置??????? possition_lb = Label(root,width=20,height=2) possition_lb.place(x=100, y=575)show_frame() root.geometry("800x600") root.mainloop()
详细解决方案
Python-Tkinter 调试视频
热度:19 发布时间:2023-12-21 22:59:09.0
相关解决方案
- ubuntu9.04上安装mic2 出错 (python setup.py build)
- ubuntu9.04下安装mic2 出错 (python setup.py build),该如何解决
- 请教如何理解JAVA、C++ Perl、PHP、Ruby、Python
- python sybase装配
- python(django框架) + mysql 的编码有关问题,求解
- SAE python web.py bootstrap 开发记要
- 数目字代码把大数据数字口语化(python+js) 数字代码
- python JSON string 的中文有关问题
- python――施用yaml数据格式,PK -> XML,JSON
- Learn Python The Hard Way学习(52) - 开始您的web游戏
- Python 相关有关问题
- 菜鸟,先学JAVA,还是Ruby,python
- 生手之前对编程无概念现在想转这行,想尽快入门,java ,python,net、php、C之间如
- 【大哥大姐】python 操作MS SQL Server 2005 效率
- python serial模块运用
- python scp自动登录解决方法
- 【Python】按行读取文件、IOError: [Errno 22] invalid mode ('a+') or filename,处置文件的换行符
- Python 3.x中使用print函数出现语法异常(SyntaxError: invalid syntax)的原因
- 【Error】Python安装gevent时出错:“致命异常: Python.h:没有那个文件或目录”
- [Python]attributeError:'module' object has no attribute 'dump'
- Python 出错:IndentationError: unexpected indent
- Python“TypeError: 'NoneType' object is not iterable"的缘故
- python in操作挑动 TypeError
- 【Error】Python:SyntaxError: Non-ASCII character '\xe5'解决办法
- python 有什么 步骤可以知道函数或类在哪个文件定义的
- 树莓派学习笔记——Python SQLite安插温度记录
- Python 将数组转换为 Wav
- Python:文件格式不正确
- Python-从tkinter脚本连接到远程主机
- 如何在 Bash 的 python 解释器中运行 python 脚本