【发布时间】:2020-11-16 09:50:25
【问题描述】:
需要帮助找出 cv2.imshow('frame',frame) 错误的原因 (在 Jupyter Notebook 中工作)
这个程序是收集很多图像,这样我就可以训练一个有 10 个手势的模型。
import cv2 #opencv
import os
import time
import uuid
# Directory to collect images for training
IMAGES_PATH='Tensorflow/workspace/images/collectedimages'
# Setting an array with all the labels
labels = ['gest-1', 'gest-2', 'gest-3','gest-4','gest-5','gest-6','gest-7','gest-8', 'gest-
9', 'gest-10']
number_imgs = 20
# loop throught each of the labels in the array
for label in labels:
#create a directory for each of the labels
os.mkdir ('Tensorflow/workspace/images/collectedimages/'+label)
# Initialize the webcam (openCV)
cap = cv2.VideoCapture(0)
# time.sleep(2)
print('Collecting images for {}'.format(label))
time.sleep(5)
#Loop through the number of images we want to collect
for imgnum in range(number_imgs):
ret,frame = cap.read()
# Naming of the pictures
# .format(str(uuid.uuid1())) makes sure that we dont duplicate names
imgname = os.path.join(IMAGES_PATH, label, label+'.'+'{}.jpg'.format(str(uuid.uuid1())))
cv2.imwrite(imgname, frame)
cv2.imshow('frame',frame)
time.sleep(2)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
【问题讨论】:
-
error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'----->Image == None----> Path_image 为假