nicegui更新halcon图像

import threading
import halcon as ha
from PIL import Image
from nicegui import ui, app, run

# from niceguiToolkit.layout import inject_layout_tool
# inject_layout_tool()
class Hal2Pil():
    def __init__(self):
        print("Hal2Pil")
        self.acq = ha.open_framegrabber('DirectShow', 1, 1, 0, 0,
                                        0, 0, 'default', 8, 'rgb', -1,
                                        'false', 'default', '[0] ASUS 5M WebCam', 0, -1)
        ha.grab_image_async(self.acq, 1)
        self.imagePil = self.grab7convert()
        self.thrEnable = True
        self.start()
    def grab7convert(self):
        imageha = ha.grab_image(self.acq)
        imageha=ha.zoom_image_factor(imageha,0.1,0.1,"constant")
        arr = ha.himage_as_numpy_array(imageha)
        return Image.fromarray(arr)
    def __del__(self):
        ha.close_framegrabber(self.acq)
    def run(self):
        while self.thrEnable:
            # print("run")
            self.imagePil = self.grab7convert()
    def retpil(self):
        return self.imagePil
    def start(self):
        threading.Thread(target=self.run).start()
h2p = Hal2Pil()
ucar = ui.card().style("width:1280;height:960")
ucar
with ucar:
    img = h2p.retpil()
    uiim = ui.interactive_image(img).style("width:800;height:600")


def fresh():
    img = h2p.retpil()
    uiim.set_source(img)
ui.timer(0.1,callback=fresh)
# app.shutdown(ha.close_framegrabber(acq))
ui.run(host='0.0.0.0', port=8080, show=True, reload=False)  #, window_size=(800, 600)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值