opencv-python使用cvui编写界面
安装cvuipip install cvui说明文档中用到指针的地方,使用列表代替(如low_threshold = [5]),取值时为low_threshold[0]import cv2import numpy as npimport cvuiWINDOW_NAME = 'CVUI Test'cvui.init(WINDOW_NAME)low_threshold = [5]method = cv
·
安装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()
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
已为社区贡献5条内容
所有评论(0)