这篇文章主要介绍了opencv+pyQt5实现图片阈值编辑器/寻色块阈值利器,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
定位色块常用到hsv色彩空间下的颜色阈值,笔者曾经用openmv时,其IDE有自带一个阈值编辑器,使用起来非常方便,现在在linux上跑cv算法,需要类似的功能,因此自己写了一个阈值编辑器。 目前暂时只支持HSV色彩空间下的阈值编辑。
代码:
mian.py:
from threshold_ui import Ui_Widget
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QImage,QPixmap,QFont
from PyQt5 import QtWidgets
import sys
import cv2
import numpy as np
class Threshold_Value_Edit():
def __init__(self): #UI初始化
super(Threshold_Value_Edit,self).__init__()
(self)
("阈值编辑器")
img_path = r'D:\Pictures\'
ft=QFont()
(12)
(255)
(255)
(255)
(255)
(255)
(255)
(255)
(255)
(255)
("H最大值:"+str(()))
("H最小值:"+str(()))
("S最大值:"+str(()))
("S最小值:"+str(()))
("V最大值:"+str(()))
("V最小值:"+str(()))
(ft)
(ft)
(ft)
(ft)
(ft)
(ft)
("HSVmin: HSVmax:")
(ft)
= cv2.imread(img_path)
()
Changed[int].connect()
Changed[int].connect()
Changed[int].connect()