Loading noctua/devices/mako.py +33 −19 Original line number Diff line number Diff line Loading @@ -97,16 +97,6 @@ class Webcam(Mako): cam.stop_streaming() self._streaming = False @property def image(self): """Get the latest raw numpy array.""" if self._streaming: with self._lock: return self._last_frame else: cam = self._check_connection() return cam.get_frame().as_numpy_ndarray() def _make_chunk(self, tag, data): """Helper for PNG chunks.""" chunk = tag + data Loading Loading @@ -147,20 +137,45 @@ class Webcam(Mako): png_bin += self._make_chunk(b'IEND', b'') return png_bin def save_image(self, filename="temp.png"): """Save image using pure Python PNG encoder.""" data = self.image @property def ndarray(self): """ Get the latest image as a numpy array. Replaces the old 'image' property for internal use. """ if self._streaming: with self._lock: return self._last_frame else: cam = self._check_connection() # Returns the raw array from a single grab return cam.get_frame().as_numpy_ndarray() @property def image(self): """ Get the current frame as a raw binary PNG. Identical behavior to devices/ipcam.py (binary content). """ data = self.ndarray if data is not None: png_data = self._to_png(data) return self._to_png(data) return None def save_image(self, filename="temp.png"): """Save image as PNG using the binary content.""" png_data = self.image if png_data: with open(filename, 'wb') as f: f.write(png_data) return filename def save_fits(self, filename="temp.fits"): """Save image as FITS using astropy.""" raw = self.image """Save image as FITS using the ndarray.""" raw = self.ndarray if raw is not None: # Automatic reshape to 2D if needed if raw.ndim == 3 and raw.shape[2] == 1: data = raw.reshape(raw.shape[0], raw.shape[1]) else: Loading @@ -181,7 +196,6 @@ class Webcam(Mako): self.put("ExposureAuto", value) def stream_opencv(self): """ Open an OpenCV window in a separate thread. Loading Loading @@ -258,7 +272,7 @@ class Webcam(Mako): while parent._http_server: # 1. Get the current image # (static or from stream buffer) data = parent.image data = parent.ndarray if data is not None: png_buffer = parent._to_png(data) Loading Loading
noctua/devices/mako.py +33 −19 Original line number Diff line number Diff line Loading @@ -97,16 +97,6 @@ class Webcam(Mako): cam.stop_streaming() self._streaming = False @property def image(self): """Get the latest raw numpy array.""" if self._streaming: with self._lock: return self._last_frame else: cam = self._check_connection() return cam.get_frame().as_numpy_ndarray() def _make_chunk(self, tag, data): """Helper for PNG chunks.""" chunk = tag + data Loading Loading @@ -147,20 +137,45 @@ class Webcam(Mako): png_bin += self._make_chunk(b'IEND', b'') return png_bin def save_image(self, filename="temp.png"): """Save image using pure Python PNG encoder.""" data = self.image @property def ndarray(self): """ Get the latest image as a numpy array. Replaces the old 'image' property for internal use. """ if self._streaming: with self._lock: return self._last_frame else: cam = self._check_connection() # Returns the raw array from a single grab return cam.get_frame().as_numpy_ndarray() @property def image(self): """ Get the current frame as a raw binary PNG. Identical behavior to devices/ipcam.py (binary content). """ data = self.ndarray if data is not None: png_data = self._to_png(data) return self._to_png(data) return None def save_image(self, filename="temp.png"): """Save image as PNG using the binary content.""" png_data = self.image if png_data: with open(filename, 'wb') as f: f.write(png_data) return filename def save_fits(self, filename="temp.fits"): """Save image as FITS using astropy.""" raw = self.image """Save image as FITS using the ndarray.""" raw = self.ndarray if raw is not None: # Automatic reshape to 2D if needed if raw.ndim == 3 and raw.shape[2] == 1: data = raw.reshape(raw.shape[0], raw.shape[1]) else: Loading @@ -181,7 +196,6 @@ class Webcam(Mako): self.put("ExposureAuto", value) def stream_opencv(self): """ Open an OpenCV window in a separate thread. Loading Loading @@ -258,7 +272,7 @@ class Webcam(Mako): while parent._http_server: # 1. Get the current image # (static or from stream buffer) data = parent.image data = parent.ndarray if data is not None: png_buffer = parent._to_png(data) Loading