【问题标题】:error: (-215:Assertion failed) size.width>0 && size.height>0 in function cv::imshow错误:(-215:断言失败)size.width>0 && size.height>0 in function cv::imshow
【发布时间】: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()

【问题讨论】:

标签: python opencv


【解决方案1】:

1- 你的路径图片是假的:Image == None --> 产生错误

2- 要在 jupyter 中显示图像,您需要这样做:

image = cv2.imread('example/image.png')
cv2.imshow("test", image)
cv2.waitKey(0)
cv2.destroyAllWindows()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    • 2020-09-03
    • 2019-10-18
    相关资源
    最近更新 更多