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()
|