opencv-python使用cvui编写界面

 

安装cvui

pip install cvui

说明文档中用到指针的地方,使用列表代替(如low_threshold = [5]),取值时为low_threshold[0]

import cv2
import numpy as np
import cvui

#initial cvui
WINDOW_NAME = 'CVUI Test'
cvui.init(WINDOW_NAME)

#capture one frame
low_threshold = [5]
method = cv2.THRESH_BINARY

cap = cv2.VideoCapture(0)
ret, frame = cap.read()

#image size
img_h, img_w = frame.shape[0:2]

#ui size
ui_h=80
ui_w=200

# total size
total_h = img_h+ui_h
total_w = max(ui_w, img_w)

#initial faram
total_frame = np.zeros((total_h,  total_w, 3), np.uint8)
total_frame[:]=(150,150,150)

while(1):
    #process image
    ret, frame = cap.read()
    imgGray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    th1, imgGray = cv2.threshold(imgGray, low_threshold[0], 255, method);
    frame = cv2.cvtColor(imgGray,cv2.COLOR_GRAY2BGR)
    total_frame[0:img_h, 0:img_w] = frame

    #draw ui
    cvui.update()
    cvui.text(total_frame, 10, img_h+15, 'Hello world!')     
    if cvui.button(total_frame, 100, img_h+15, "Inverse"):
        method = cv2.THRESH_BINARY if method == cv2.THRESH_BINARY_INV else cv2.THRESH_BINARY_INV

    cvui.trackbar(total_frame, 180, img_h+10, 220, low_threshold, 5, 150)

    #show
    cvui.imshow(WINDOW_NAME, total_frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):        
        break
cap.release()
cv2.destroyAllWindows()

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值