-1

Need help finding why the error with cv2.imshow('frame',frame) (Working in Jupyter Notebook)

This program is to collect many images so that I can train a model that has 10 gestures.

        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()
ZF007
  • 3,708
  • 8
  • 29
  • 48
ypm
  • 9
  • 1
  • 5
  • `error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'` -----> `Image == None` ----> Path_image is False – RashidLadj_Winux Nov 16 '20 at 11:16
  • Does this answer your question? [OpenCV Error: (-215)size.width>0 && size.height>0 in function imshow](https://stackoverflow.com/questions/27953069/opencv-error-215size-width0-size-height0-in-function-imshow) – RashidLadj_Winux Nov 16 '20 at 11:20

1 Answers1

0

1- Your path image is false : Image == None --> generate error

2- for show image in jupyter you need do this:

image = cv2.imread('example/image.png')
cv2.imshow("test", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
RashidLadj_Winux
  • 810
  • 1
  • 6
  • 17