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

gpt4实现对摄像头帧缓冲区图像的LAB阈值选择界面(python-opencv)

代码全是GPT4写的,我就提出Prompt和要改的地方而已。

图形界面效果

可复制阈值:(xxx, xxx, xxx, xxx, xxx, xxx)

代码

import cv2
import numpy as np
import time
from tkinter import *
from PIL import Image, ImageTk
import pyperclip  # new# Global variables for storing the LAB color space threshold values
l_min_g, a_min_g, b_min_g, l_max_g, a_max_g, b_max_g = 0, 0, 0, 255, 255, 255class App:def __init__(self, window, window_title, video_source=0):self.window = windowself.window.title(window_title)self.video_source = video_sourceself.ok = Falseself.vid = cv2.VideoCapture(self.video_source)if not self.vid.isOpened():raise ValueError("Unable to open video source", video_source)self.canvas1 = Canvas(window, width=480, height=360)self.canvas1.pack(side=LEFT)self.canvas2 = Canvas(window, width=480, height=360)self.canvas2.pack(side=LEFT)self.btn_snapshot = Button(window, text="Snapshot", width=50, command=self.snapshot)self.btn_snapshot.pack(anchor=CENTER, expand=True)self.l_min_slider = Scale(window, from_=0, to=255, orient=HORIZONTAL, label="L_min", length=480)self.l_min_slider.pack()self.a_min_slider = Scale(window, from_=0, to=255, orient=HORIZONTAL, label="A_min", length=480)self.a_min_slider.pack()self.b_min_slider = Scale(window, from_=0, to=255, orient=HORIZONTAL, label="B_min", length=480)self.b_min_slider.pack()self.l_max_slider = Scale(window, from_=0, to=255, orient=HORIZONTAL, label="L_max", length=480)self.l_max_slider.pack()self.a_max_slider = Scale(window, from_=0, to=255, orient=HORIZONTAL, label="A_max", length=480)self.a_max_slider.pack()self.b_max_slider = Scale(window, from_=0, to=255, orient=HORIZONTAL, label="B_max", length=480)self.b_max_slider.pack()self.btn_copy = Button(window, text="Copy LAB Values", command=self.copy_values)  # newself.btn_copy.pack()self.delay = 10self.update()self.window.mainloop()def snapshot(self):if self.ok:cv2.imwrite("frame-" + time.strftime("%d-%m-%Y-%H-%M-%S") + ".jpg", cv2.cvtColor(self.frame, cv2.COLOR_RGB2BGR))def copy_values(self):  # newl_min = self.l_min_slider.get()a_min = self.a_min_slider.get()b_min = self.b_min_slider.get()l_max = self.l_max_slider.get()a_max = self.a_max_slider.get()b_max = self.b_max_slider.get()values_str = f"({l_min}, {a_min}, {b_min}, {l_max}, {a_max}, {b_max})"pyperclip.copy(values_str)def update(self):ret, self.frame = self.vid.read()if ret:self.frame = cv2.cvtColor(self.frame, cv2.COLOR_BGR2RGB)self.photo1 = ImageTk.PhotoImage(image=Image.fromarray(self.frame).resize((480, 360)))self.canvas1.create_image(0, 0, image=self.photo1, anchor=NW)l_min = self.l_min_slider.get()a_min = self.a_min_slider.get()b_min = self.b_min_slider.get()l_max = self.l_max_slider.get()a_max = self.a_max_slider.get()b_max = self.b_max_slider.get()lower_bound = np.array([l_min, a_min, b_min])upper_bound = np.array([l_max, a_max, b_max])mask = cv2.inRange(cv2.cvtColor(self.frame, cv2.COLOR_RGB2Lab), lower_bound, upper_bound)self.photo2 = ImageTk.PhotoImage(image=Image.fromarray(mask).resize((480, 360)))self.canvas2.create_image(0, 0, image=self.photo2, anchor=NW)self.ok = Trueself.window.after(self.delay, self.update)App(Tk(), "LAB Thresholding", video_source=2)

video_source参数为摄像头ID。

被取代是我的命运,我了解。。。

http://www.lryc.cn/news/94583.html

相关文章:

  • Stable Diffusion WebUI 集成 LoRA模型,给自己做一张壁纸 Ubuntu22.04 rtx2060 6G
  • Flink 读写Kafka总结
  • LiDAR SLAM 闭环——BoW3D论文详解
  • Android NTP时间同步源码分析
  • 数据库之MySQL字符集与数据库操作
  • 搜索引擎概念解析
  • 网页链接投票链接步骤公众号投票链接制作制作投票
  • 【通信安全CACE-管理类基础级】第7章 安全运维
  • 随手笔记——将ROS图像话题转为OpenCV图像格式处理后再转为ROS图像话题发布(Python版)
  • Win11系统如何安装Oracle数据库(超级详细)
  • 【代理服务器】Squid 反向代理与Nginx缓存代理
  • 目标检测之遮挡物体检测
  • Vim 命令大全
  • 【Visual Studio】printf() 函数无输出显示问题。使用 C++ 语言,配合 Qt 开发串口通信界面
  • Linux安装配置Oracle+plsql安装配置(详细)
  • 软件UI工程师的职责模板
  • 【Python】Selenium操作cookie实现免登录
  • 【数据结构与算法篇】之时间复杂度与空间复杂度
  • 硬件性能 - 网络瓶颈分析
  • stm32驱动MCP2515芯片,项目已通过测试
  • Nginx部署前后端分离项目
  • pytorch多分类问题 CrossEntropyLoss()函数的输入size/shape不一致问题
  • 硬盘或者U盘提示需要格式化的解决办法
  • Clip-Path
  • Matlab绘图系列教程-Matlab 34 种绘图函数示例(下)
  • 【Vue+Django】Training Management Platform Axios并发请求 - 20230703
  • smart Spring:自定义注解、拦截器的使用(更新中...)
  • php导出pdf
  • 【ECMAScript6_2】字符串
  • 37.RocketMQ之Broker消息存储源码分析