查看: 1645|回复: 0

角蜂鸟 Console下可运行的Demo

[复制链接]
  • TA的每日心情

    2018-11-20 13:41
  • 签到天数: 3 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    发表于 2019-2-20 10:53:57 | 显示全部楼层 |阅读模式
    分享到:
    角蜂鸟Demo要在图形界面下才能跑,有些场景做演示不合适,且浪费资源。最好能在命令行下跑。我用pygame,实现在命令行下运行,就可以看到视频的Demo。

    1. import numpy as np,sys,cv2
    2. sys.path.append('../../api/')
    3. import hsapi as hs

    4. WEBCAM = False # Set to True if use Webcam
    5. net = hs.HS('ObjectDetector', zoom = True, verbose = 2)
    6. if WEBCAM: video_capture = cv2.VideoCapture(0)

    7. import time, pygame
    8. from pygame.locals import *
    9. # 显示器分辨率,我用的是竖屏,所以是w=1080 h=1920
    10. screen_size=(1080,1920)

    11. def init():
    12.         pygame.init()
    13.         screen = pygame.display.set_mode(screen_size)
    14.         return screen

    15. def update(screen,surface):
    16.         screen.blit(surface,((screen_size[0]-surface.get_width())/2, (screen_size[1]-surface.get_height())/2))
    17.         pygame.display.update()

    18. def eventCheck():
    19.         for event in pygame.event.get():
    20.                 if event.type in [QUIT,KEYDOWN]:
    21.                         pygame.quit()
    22.                         sys.exit()
    23. screen=init()

    24. while True:
    25.         if WEBCAM: _, img = video_capture.read()
    26.         else: img = None
    27.         result = net.run(img)
    28.         img = net.plotSSD(result)
    29.         img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
    30.         s = img.tostring()
    31.         p = pygame.image.frombuffer(s,(img.shape[1],img.shape[0]),"RGB")
    32.         eventCheck()
    33.         update(screen,p)
    复制代码


    作者:_49_
    來源:简书

    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-4-20 06:05 , Processed in 0.099137 second(s), 14 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.