• opencv_python学习笔记六


    8使用滑动条作调色板

    cv2.getTrackbarPos()

    cv2.createTrackbar()

    函数原型
    def getTrackbarPos(trackbarname, #滚动条名字

    winname)#放置窗口的名字

    def createTrackbar(trackbarName,
                       windowName,
                       value,
                       count,
                       onChange)

    使用三个滚动条设置RGB

    示例代码如下

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Time    : 2016/11/14 10:17
    # @Author  : Retacn
    # @Site    : 使用滑动条作调色板
    # @File    : trackbarTest.py
    # @Software: PyCharm

    import cv2
    import numpy as np

    def nothing(x):
        pass

    #创建图像
    img=np.zeros((300,512,3),np.uint8)
    cv2.namedWindow("Trackbar")

    cv2.createTrackbar("R","Trackbar",0,255,nothing)
    cv2.createTrackbar("G","Trackbar",0,255,nothing)
    cv2.createTrackbar("B","Trackbar",0,255,nothing)

    switch='0:OFF 1:ON'
    cv2.createTrackbar(switch,'Trackbar',0,1,nothing)

    while(1):
        cv2.imshow('Trackbar',img)
        k=cv2.waitKey(1)&0xFF
        if k==27:
            break

        
    r=cv2.getTrackbarPos('R','Trackbar')
        g=cv2.getTrackbarPos('G','Trackbar')
        b=cv2.getTrackbarPos('B','Trackbar')
        s=cv2.getTrackbarPos(switch,'Trackbar')

        if s==0:
            img[:]=0
        else:
            img[:]=[b,g,r]
    cv2.destroyAllWindows()

  • 相关阅读:
    navicat执行大容量的.sql文件时的设置
    unity3d的四元数 Quaternion
    Unity运行时刻资源管理
    unity3d 加密资源并缓存加载
    unity3d webplayer 16:9 居中显示模板
    quaternion*Vector3的新理解
    PoolManager
    网上关于碰撞的资料
    游戏美术:色彩原理
    unity3d下载Obb分包文件
  • 原文地址:https://www.cnblogs.com/retacn-yue/p/6194170.html
Copyright © 2020-2023  润新知