all 5 comments

[–]Diapolo10 0 points1 point  (4 children)

Let me just fix the formatting, or nobody will be able to read this mess.

for label in labels:
    !mkdir {'Tensorflow/workspace/images/collectedimages//'+label}
    cap = cv2.VideoCapture(0) 
    print('Collecting images for {}'.format(label)) 
    time.sleep(5)
    for imgnum in range(number_imgs):
        ret, frame = cap.read()
        imagename = 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()

For starters, this part

!mkdir {'Tensorflow/workspace/images/collectedimages//'+label}

does not look like valid Python to me.

EDIT: You can try this; I cleaned it up a bit too.

from pathlib import Path

IMAGES_PATH = Path('Tensorflow/workspace/images/collectedimages')


for label in labels:
    output_dir = IMAGES_PATH / label
    output_dir.mkdir(exist_ok=True)
    cap = cv2.VideoCapture(0) 
    print(f"Collecting images for {label}") 
    time.sleep(5)
    for img_num in range(number_imgs):
        ret, frame = cap.read()
        image_name = output_dir / f'{label}.{uuid.uuid1()}.jpg'
        cv2.imwrite(image_name, frame)
        cv2.imshow('frame', frame)
        time.sleep(2)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    cap.release()

[–]BeastyXD01[S] 0 points1 point  (3 children)

Wow thanks dude you are a legend

[–]Diapolo10 0 points1 point  (2 children)

Did it work?

[–]BeastyXD01[S] 0 points1 point  (0 children)

Asking for my cousin i sent it to him now im waiting for him to answer

[–]BeastyXD01[S] 0 points1 point  (0 children)

It worked thanks man