My code looks like this aside from the imports
Based on the sample mjpeg_server code
The image is displayed in a main file as
Here's an example where the preview shows blues as green
The photo that it takes looks correct though
Maybe it's the np.array process?
Based on the sample mjpeg_server code
Code:
class StreamingOutput(io.BufferedIOBase): def __init__(self): self.frame = None self.condition = Condition() def write(self, buf): with self.condition: self.frame = buf self.condition.notify_all()class Camera: def __init__(self): self.streaming = False self.picam2 = Picamera2() self.output = None self.photo_config = self.picam2.create_still_configuration( main={"size": self.picam2.sensor_resolution, "format":"RGB888"} ) self.video_config = self.picam2.create_video_configuration( main={"size": (640, 480), "format":"RGB888"}, ) def change_mode(self, mode): if mode == "full": self.picam2.switch_mode(self.photo_config) else: self.picam2.switch_mode(self.video_config) def take_picture(self): img_path = base_path + str(time.time()).split(".")[0] + ".jpg" self.change_mode("full") self.picam2.capture_file(img_path) self.change_mode("stream") def start_streaming(self): self.picam2.configure(self.video_config) self.output = StreamingOutput() self.picam2.start_recording(JpegEncoder(), FileOutput(self.output))Code:
def buf_to_pil_img(buf): return np.array(Image.open(io.BytesIO(buf)))cv2.imshow(window_name, buf_to_pil_img(camera.output.frame)Here's an example where the preview shows blues as green
The photo that it takes looks correct though
Maybe it's the np.array process?
Statistics: Posted by jcun4128 — Sun Feb 08, 2026 12:34 am