Raster Prop Monitor#
Raster Prop Monitor fills a pod’s IVA with working screens, and adds external cameras that the screens show. The scripts below draw a menu on a screen, and show a camera’s view as video in a window. They need a crewed pod with a Raster Prop Monitor IVA, such as the Mk1 Lander Can, and an external camera on the vessel.
Camera Video#
The following script shows the view of the vessel’s first external camera in a window. It uses Pillow to decode the frames, and tkinter to show them:
import io
import tkinter as tk
from PIL import Image
from PIL.ImageTk import PhotoImage
import krpc
from krpc.services.stdlib import ImageFormat
conn = krpc.connect(name="Camera Video")
vessel = conn.space_center.active_vessel
camera = conn.raster_prop_monitor.cameras(vessel)[0]
# The camera's view as JPEG frames of 640 by 480 pixels, 30 times a second
frames = conn.add_stream(camera.image, 640, 480, ImageFormat.jpeg)
frames.rate = 30
window = tk.Tk()
window.title(camera.name)
label = tk.Label(window)
label.pack()
# Tk keeps no reference to the image it shows
shown = []
def show():
image = PhotoImage(Image.open(io.BytesIO(frames())))
label.configure(image=image)
shown[:] = [image]
window.after(30, show)
show()
window.mainloop()
ExternalCamera.image() renders the camera’s view, here as a JPEG image. JPEG is lossy,
and is smaller and faster to encode than PNG. A stream of it is a video, and the stream’s rate
is the frame rate. The server renders a frame on each update the rate allows, up to one per
physics tick, which is 50 a second. A 640 by 480 frame is about 25 KB, so a 30 frame a second
video takes under 1 MB/s.
The window shows the newest frame each time it redraws. To capture every frame of a recording
instead, call ExternalCamera.image() in a loop that holds each tick. The game then waits for the script on each tick.
See also
ExternalCamera for the camera’s field of view, and Monitor for reading a
screen’s text and image.