×

INDI Library v2.0.7 is Released (01 Apr 2024)

Bi-monthly release with minor bug fixes and improvements

Blob to image using pyindi client

  • Posts: 1
  • Thank you received: 0
Hello All,

I working on building python client to capture single image from ASI224MC camera. I am able to run the python script along with Indi_asi_ccd driver. looking at the log I am assuming that image from ASI224MC is captured in terms of blob. I am wondering how do I convert blob binary data into image and save it on disk.

Platform: Raspberry PI 4
OS: Ubuntu server 22.04

Python script:

import PyIndi
import sys
import time

class IndiClient(PyIndi.BaseClient):
def __init__(self):
super(IndiClient, self).__init__()

# Emmited when a new device is created from INDI server.
def newDevice(self, dev):
print(f"New device: {dev.getDeviceName()}")

# Emmited when a new property is created for an INDI driver.
def newProperty(self, prop):
print(f"New property: {prop.getName()}")
pass

# Emmited when a new property value arrives from INDI server.
def updateProperty(self, prop):
print(f"Update property: {prop.getName()}")
if prop.isNameMatch("CCD1"):
blob = PyIndi.PropertyBlob(prop) # cast generic type to blob type
print(f" name: {blob.getName()}")
print(f" label: {blob.getLabel()}")
print(f" device: {blob.getDeviceName()}")

# usually, the first item is the expected photo
print(f" format: {blob[0].getFormat()}")
print(f" blob len: {blob[0].getBlobLen()}")
print(f" size: {blob[0].getSize()}")

# e.g. run indiserver indi_simulator_ccd
deviceName = "ZWO CCD ASI224MC"

indiClient = IndiClient()
indiClient.setServer("localhost", 7624)

if not indiClient.connectServer():
print("No indi server found")
sys.exit(1)

indiClient.setBLOBMode(PyIndi.B_ALSO, deviceName, "")

# Connect to device
time.sleep(0.1)
indiClient.connectDevice(deviceName)

# Take exposure
time.sleep(0.1)
ccdExposure = indiClient.getDevice(deviceName).getNumber("CCD_EXPOSURE")
if ccdExposure.isValid():
ccdExposure[0].setValue(1) # one second
indiClient.sendNewProperty(ccdExposure)
else:
print(f"Cannot find {deviceName} or CCD_EXPOSURE property")

input("")

Log output after running python script:

INDI::BaseClient::connectServer: creating new connection...
New device: ZWO CCD ASI224MC
New property: CONNECTION
New property: DRIVER_INFO
New property: POLLING_PERIOD
New property: DEBUG
New property: SIMULATION
New property: CONFIG_PROCESS
New property: ACTIVE_DEVICES
New property: CCD_EXPOSURE
New property: CCD_ABORT_EXPOSURE
New property: CCD_FRAME
New property: CCD_FRAME_RESET
New property: CCD_BINNING
New property: FITS_HEADER
New property: CCD_CAPTURE_FORMAT
New property: CCD_TRANSFER_FORMAT
New property: CCD_INFO
New property: CCD_COMPRESSION
New property: CCD1
New property: TELESCOPE_TIMED_GUIDE_NS
New property: TELESCOPE_TIMED_GUIDE_WE
New property: CCD_FRAME_TYPE
New property: CCD_CFA
New property: SCOPE_INFO
New property: WCS_CONTROL
New property: UPLOAD_MODE
New property: UPLOAD_SETTINGS
New property: CCD_FAST_TOGGLE
New property: CCD_FAST_COUNT
New property: CCD_VIDEO_STREAM
New property: STREAM_DELAY
New property: STREAMING_EXPOSURE
New property: FPS
New property: RECORD_STREAM
New property: RECORD_FILE
New property: RECORD_OPTIONS
New property: CCD_STREAM_FRAME
New property: CCD_STREAM_ENCODER
New property: CCD_STREAM_RECORDER
New property: LIMITS
New property: CCD_TEMPERATURE
New property: CCD_CONTROLS
New property: CCD_CONTROLS_MODE
New property: FLIP
New property: CCD_VIDEO_FORMAT
New property: BLINK
New property: ADC_DEPTH
New property: SDK
New property: Serial Number
New property: NICKNAME
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: CCD_TEMPERATURE
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: CCD_EXPOSURE
Update property: DRIVER_INFO
Update property: CCD1
name: CCD1
label: Image Data
device: ZWO CCD ASI224MC
format: .fits
blob len: 2548800
size: 2548800
Update property: CCD_EXPOSURE
Update property: CCD_TEMPERATURE
5 months 3 weeks ago #96872

Please Log in or Create an account to join the conversation.

  • Posts: 262
  • Thank you received: 66
The blob is FITS data. The code below is roughly what you need to produce a JPEG.

import io
import numpy as np
import cv2
from astropy.io import fits
 
blobdata = blob.getblobdata()
blobfile = io.BytesIO(blobdata)
hdulist = fits.open(blobfile)
 
# debayer RGGB pattern for ASI224
image_bgr_16bit = cv2.cvtColor(hdulist[0].data, cv2.COLOR_BAYER_BG2BGR)
 
# downsample to 8 bits (ZWO cameras return 16-bit data)
image_bgr_8bit = np.right_shift(image_bgr_16bit, 8).astype(np.uint8)
 
cv2.imwrite('image.jpg', image_bgr_8bit, [cv2.IMWRITE_JPG_QUALITY, 90])
The following user(s) said Thank You: Amit
Last edit: 5 months 3 weeks ago by Aaron Morris.
5 months 3 weeks ago #96880

Please Log in or Create an account to join the conversation.

Time to create page: 0.674 seconds