Files
2022-12-12 11:51:07 +01:00

50 lines
1.4 KiB
Python

import numpy
import time
import h5py
import logging
from cam_server.camera.source.camera import *
_logger = logging.getLogger(__name__)
class source_h5(Camera):
def __init__(self, camera_config):
Camera.__init__(self, camera_config)
self.camera_config = camera_config
self.file_name =camera_config.get_source()
self.shape = None
self.check_data = True
self.interval = camera_config.get_configuration().get("interval", 1.0)
def get_raw_geometry(self):
return self.width_raw, self.height_raw
def verify_camera_online(self):
pass
def connect(self):
self.h5 = h5py.File(self.file_name, 'r')
self.dataset =self.h5['camera1/image']
_logger.info(">>>>>> " + str(self.dataset))
self.shape = self.dataset.shape # (4,100,200)
# Width and height of the raw image
self.width_raw = self.shape[2]
self.height_raw = self.shape[1]
self.num_images = self.shape[0]
self.cur_index = 0
def disconnect(self):
pass
def read(self):
ret =self.dataset[self.cur_index]
self.cur_index = self.cur_index+1
if self.cur_index >=self.num_images:
self.cur_index = 0
#width, height = self.get_raw_geometry()
#ret = numpy.random.randint(1, 101, width * height, "uint16").reshape((height, width))
#time.sleep(self.interval)
return ret