Python webcam capture

Asked 2 years ago, Updated 2 years ago, 76 views

path = os.path.dirname(__file__)
        filename = "recognizeface.jpg"
    fullpath = os.path.join(path, filename)

    cap = cv2.VideoCapture(0)
    # Capture Frame 
    ret, frame = cap.read()

    ## Set frame color
    gray = cv2.cvtColor(frame, cv2.IMREAD_COLOR)

    ## Visible in the window frame 
    cv2.imshow('frame', frame)
    cv2.imwrite(fullpath, gray)

    # Release cam resource 
    cap.release()
    # Turn off Windows 
    cv2.destroyAllWindows()

It's my code. If I run it, it takes a picture, but it comes out completely dark. How can I take a colorful picture

opencv python webcam

2022-09-22 11:00

1 Answers

I set it to gray, so of course it comes out dark.

If you want to save the original image as it is, remove the gray from cv2.imwrite(fullpath, gray) and save the frame.

cv2.imwrite(fullpath, frame)


2022-09-22 11:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.