找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 1843|回复: 0

[代码与实例] WXpython 的 app.mainloop() 如何与while true:同时执行?

1

主题

1

帖子

1

积分

贫民

积分
1
Bin 发表于 2020-8-8 19:16:43 | 显示全部楼层 |阅读模式
import cv2
import os

while True:
    ret, frame = cap.read()

    frame = frame[crop_h_start:crop_h_start + w, crop_w_start:crop_w_start + w]
    # ?

    frame = cv2.flip(frame, 1, dst=None)
    # 镜像显示
    cv2.imshow("capture", frame)
    # 显示

    input = cv2.waitKey(1) & 0xFF
    if input == ord('z'):
        class_name = input("请输入存储目录:")
        while os.path.exists(class_name):
            class_name = input("目录已存在!请输入存储目录:")
        os.mkdir(class_name)
    # 存储

    elif input == ord('x'):
        cv2.imwrite("%s/%d.jpeg" % (class_name, index),
                    cv2.resize(frame, (400, 400), interpolation=cv2.INTER_AREA))
        print("%s: %d 张图片" % (class_name, index))
        index += 1
    # ?
    if input == ord('q'):
        break
    # 退出

cap.release()
cv2.destroyAllWindows()
# 关闭窗口

if __name__ == '__main__':
    app = wx.App()

    main_win = MyFrame(None)
    main_win.Show()
    app.MainLoop()

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表