1 Star 0 Fork 0

杨雪锋/opencv-python-5

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ex3-2.py 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
杨雪锋 提交于 2023-04-14 21:45 +08:00 . update ch3
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''采用PySimpleGUI的调色盘程序'''
import numpy as np
import cv2
import PySimpleGUI as sg
# 界面风格
sg.theme('GreenTan')
slider_r=[ sg.Text('红色分量', size=(10, 1)),
sg.Slider(range=(0,255),size=(40,15),resolution=1,change_submits=True,
orientation='horizontal',key='-SLIDER_R-')]
slider_g=[ sg.Text('绿色分量', size=(10, 1)),
sg.Slider(range=(0,255),size=(40,15),resolution=1,change_submits=True,
orientation='horizontal',key='-SLIDER_G-')]
slider_b=[ sg.Text('蓝色分量', size=(10, 1)),
sg.Slider(range=(0,255),size=(40,15),resolution=1,change_submits=True,
orientation='horizontal',key='-SLIDER_B-')]
image_palette=[sg.Image(key='-IMAGE_PALETTE-',size=(400,400))]
window = sg.Window('调色盘',
[slider_r,slider_g,slider_b,[sg.HorizontalSeparator()],image_palette],
font=("Helvetica", 15),element_justification="center" )
img = np.zeros((400,400,3), np.uint8)
#事件循环
while True:
# 读取界面操作
event, values = window.read()
# 检测是否需要退出
if event == sg.WIN_CLOSED:
break
r=np.uint8(values['-SLIDER_R-'])
g=np.uint8(values['-SLIDER_G-'])
b=np.uint8(values['-SLIDER_B-'])
img[:] = [b,g,r]
imgbytes = cv2.imencode(".png", img)[1].tobytes()
window["-IMAGE_PALETTE-"].update(data=imgbytes)
cv2.waitKey(0)
cv2.destroyAllWindows()
window.close()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/hopeasy/opencv-python-5.git
git@gitee.com:hopeasy/opencv-python-5.git
hopeasy
opencv-python-5
opencv-python-5
master

搜索帮助