lyyiangang / dearpygui_demo

用OpenCV读取视频,并在Dearpygui库中进行播放的demo
3 stars 0 forks source link

DearPyGui1.62中不能正常执行 #1

Open monkeycc opened 2 years ago

monkeycc commented 2 years ago

首先感谢分享源码

最新的DearPyGui1.62中 不能正常执行

lyyiangang commented 1 year ago

什么错误提示?

alongsoft2018 commented 1 year ago

import cv2 import numpy as np import dearpygui.dearpygui as dpg

dpg.create_context() dpg.configure_app(manual_callback_management=True) dpg.create_viewport() dpg.setup_dearpygui()

def to_rgb(bgr_img): return bgr_img[..., [2, 1, 0]]

def normalize(img): return img.astype(np.float32) / 255

def run(): video_file = r'D:\video\xiniu.mp4' cap = cv2.VideoCapture(video_file) assert cap.isOpened(), f'can not open video file {videofile}' , first_frame = cap.read() h, w = first_frame.shape[:2]

raw_data = np.zeros((h,w,3), np.float32)

with dpg.texture_registry(show=True):    
    texture_id = dpg.add_raw_texture(w, h, raw_data, format=dpg.mvFormat_Float_rgb)
with dpg.window(label="Main"):
    dpg.add_image(texture_id)

dpg.show_viewport()
while(dpg.is_dearpygui_running()):
    print('loop----------')
    ret, bgr_img = cap.read()
    if not ret:
        break
    # 需要转换为rgb格式,并归一化到[0, 1]
    norm_rgb_img = normalize(to_rgb(bgr_img))
    raw_data[...] = norm_rgb_img[...]
    dpg.render_dearpygui_frame()   
dpg.create_viewport(title='Custom Title', width=1920, height=1080)     
dpg.start_dearpygui()
dpg.destroy_context()

if name == 'main': run()

-------------------------------------

dearpygui 1.9.1

-------------------------------------