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

Camera board • MJPEG streaming sample code, blue looks green but photo comes out correct

$
0
0
My code looks like this aside from the imports
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))
The image is displayed in a main file as

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?
blue-green.JPG

Statistics: Posted by jcun4128 — Sun Feb 08, 2026 12:34 am



Viewing all articles
Browse latest Browse all 8621

Trending Articles