Camera

Juno has no juno.camera module: OpenCV is built in, and cv2.VideoCapture(0) opens the device’s camera. The first time, iOS asks the person for camera access. Check isOpened() before reading frames.

import cv2

camera = cv2.VideoCapture(0)
if camera.isOpened():
    ok, frame = camera.read()
    camera.release()
    if ok:
        cv2.imwrite("photo.jpg", frame)
else:
    print("No camera: allow it in Settings > Juno > Camera.")

Frames

read() returns (ok, frame), where frame is a NumPy array of BGR pixels: pass it to any OpenCV function, or write it to a file with cv2.imwrite. Release the camera with release() when done.

Showing a frame

ui.Image takes a file path or encoded PNG, JPEG, GIF or HEIC bytes of at most 700 KB, not an array, so encode the frame first. Shrink a large frame with cv2.resize to stay under the limit.

ok, jpeg = cv2.imencode(".jpg", frame)
picture = ui.Image(jpeg.tobytes())

juno.preview.show reads a three-channel array as RGB, so convert first: preview.show(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)).

In a juno.ui window

Open the camera and read frames in a callback, such as a button’s on_press, never in body. To pick an existing photo from the library instead, use juno.photos.pick; to save one there, use juno.photos.save.