Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4781

Troubleshooting • Re: Raspberry Pi Camera only working when i add --qt-preview on libcamera-hello

$
0
0

Code:

import cv2from picamera2 import Picamera2# start Pi camerapicam2 = Picamera2()picam2.configure(picam2.create_preview_configuration(main={"format": 'XRGB8888', "size": (640,480)}))picam2.start()name = 'Fishy' #replace with your namecv2.namedWindow("press space to take a photo", cv2.WINDOW_NORMAL)cv2.resizeWindow("press space to take a photo", 500, 300)img_counter = 0while True:    img = picam2.capture_array("main")    frame = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)    cv2.imshow("press space to take a photo", frame)    k = cv2.waitKey(1)    if k%256 == 27:        # ESC pressed        print("Escape hit, closing...")        break    elif k%256 == 32:        # SPACE pressed        img_name = "dataset/"+ name +"/image_{}.jpg".format(img_counter)        cv2.imwrite(img_name, frame)        print("{} written!".format(img_name))        img_counter += 1cv2.destroyAllWindows()

Statistics: Posted by gordon77 — Sat Mar 23, 2024 5:40 pm



Viewing all articles
Browse latest Browse all 4781

Trending Articles