Module labcom.ArcData

実験データをチャネル単位に格納する。

実験データには、パラメータおよび時間軸情報が付属する。 時間軸情報はDTS情報が参照できる場合のみである。

Python3 long –> int binary string –> ByteArray np.fromstring –> np.frombuffer (int)/(int) –> (int)//(int)

Classes

class ArcData (start_time=None,
sampling_interval=None,
samp_data=None,
samp_params=None,
num_times=None)
Expand source code
class ArcData(object):
    '''
[ クラス名 ] ArcData
< パブリックメンバー >
  start_time (double|int)         : サンプリング開始時刻(秒|ピコ秒)
  sampling_interval (double|int)  : サンプリング間隔(秒|ピコ秒)
  samp_data (ArcSamples|ArcFrames) : データ・オブジェクト
  samp_params (ディクショナリ)        : パラメータ連想配列
  num_times (int)                  : 時間軸データ数
      
< 参照系メソッド >
  val()          : データを取り出す (numpy) 
  time()         : 時間軸配列データを取り出す (numpy) 
  num()                : データ件数
  num_times()    : 時間軸配列データ件数
  converted_rgb(): RGBデータに変換して取り出す(numpy) 

< 更新系メソッド >
  set_data( obj) : データオブジェクトを設定する。
  set_parameters( dict_obj) 
                 : パラメータ配列を設定する。
  set_time( start_time, sampling_interval, num_times) 
                 : 時間軸情報を設定する。
  set_samples( dtype, data, bsize=None) 
                 : データを設定する。
  add_parameters( dict_obj) 
                 : パラメータ配列を追加する。
  add_parameter( param_name, param_value, param_type) 
                 : パラメータを追加する。
  init_frames( i_type, x_size, y_size) 
                 : データをフレーム構造に初期化する。
  add_frame( binary_str, bsize=None) 
                 : データに1フレームデータを追加する。

< 説明 >
  チャネルデータを管理するクラス
    '''


    def __init__(self, start_time=None, sampling_interval=None, samp_data=None, samp_params=None, num_times=None):
        '''
    [ Constructor ]
    < 引数 >
      start_time (double|int)         : サンプリング開始時刻(秒|ピコ秒)
      sampling_interval (double|int)  : サンプリング間隔(秒|ピコ秒)
      samp_data (ArcSamples|ArcFrames) : データ・オブジェクト
      samp_params (dict)               : パラメータ連想配列
      num_times (int)                 : 時間軸データ数
        '''
        if isinstance(start_time, int) :
            self.start_time = int(start_time)
        else :
            self.start_time = start_time

        if isinstance(sampling_interval, int) :
            self.sampling_interval = int(sampling_interval)
        else :
            self.sampling_interval = sampling_interval

        self.set_data( samp_data)
        self.set_parameters( samp_params)
        self.num_of_times = num_times
        
    def val(self):
        '''
    [ 関数名] val
    < 引数 >
      なし
    < 返値 >
      データオブジェクトの配列データ (numpy)
    < 説明 >
      データオブジェクトのデータをnumpyクラスのオブジェクトに変換する。
           
        '''
        if self.samples is None :
            return None
        else :
            return self.samples.val()
    
    def converted_rgb(self):
        '''
    [ 関数名] converted_rgb
    < 引数 >
      なし
    < 返値 >
      データの3次元配列RGBデータ(numpy)
    < 説明 >
      データオブジェクトのデータをRGBデータに変換し、numpyクラスのオブジェクトにする。
           
        '''
        if self.is_frame()  :
            return self.samples.converted_rgb()
        else :
            return None

    def num(self):
        '''
    [ 関数名 ] num
    < 引数 >
      なし
    < 返値 >
      データオブジェクトのデータ件数 (int)
    < 説明 >
      フレームの場合、フレーム数
        '''
        if self.samples is None :
            return None
        else :
            return self.samples.num()

    def num_times(self):
        '''
    [ 関数名 ] num_times
    < 引数 >
      なし
    < 返値 >
      時間軸データ件数 (int)
    < 説明 >
      サンプル数と異る場合あり。
        '''
        if self.num_of_times is None :
            return self.num()
        else :
            return self.num_of_times

    def time(self):
        '''
    [ 関数名 ] time
    < 引数 >
      なし
    < 返値 >
      データオブジェクトの時間軸配列データ(numpy)
    < 説明 >
      時間軸情報がない場合は、index配列になる。
        
        '''
        num = self.num_times()
        if num is None :
            return None

        if self.sampling_interval is None :
            interval = int(0)
        else :
            interval = self.sampling_interval

        if 0.0 == interval :
            interval = int(0)
            
        if self.start_time is None :
            start_t = int(0)
        else :
            start_t = self.start_time

        if isinstance(interval, int) :
            if 0 < interval :
                return (start_t + interval * np.array(list(range( 1, num+1)), dtype=np.int64))/1000000000000.0 
            else : 
                return (start_t + np.array(list(range( 1, num+1)))) 
        else : 
            return (start_t + interval * np.array(list(range( 1, num+1)))) 


    def set_parameters(self, dict_obj):
        '''
    [ 関数名 ] set_parameters
    < 引数 >
      dict_obj (dict)    : 設定するパラメータオブジェクト
    < 返値 >
      なし
    < 説明 >
      パラメータオブジェクトに設定する。
        '''
        self.parameters = dict_obj

        
    def add_parameters(self, dict_obj):
        '''
    [ 関数名 ] add_parameters
    < 引数 >
      dict_obj (dict)    : 追加するパラメータオブジェクト。
    < 返値 >
      なし
    < 説明 >
      パラメータオブジェクトに追加する。
        
        '''
        if self.parameters is None :
            self.parameters = dict_obj
        else :
            self.parameters.update( dict_obj)
        

    def add_parameter(self, param_name, param_value, param_type):
        '''
    [ 関数名 ] add_parameter
    < 引数 >
      param_name (string)       : 追加するパラメータ名
      param_value
          (int,double,string,..) : 追加するパラメータ値
      param_type (int)           : 追加するパラメータの型
    < 返値 >
      なし
    < 説明 >
      パラメータオブジェクトに追加する。
        
        '''
        self.parameters[param_name] = param_value
        self.parameters[param_name+'#PTYPE'] = param_type

    def set_data(self, obj):
        '''
    [ 関数名 ] set_data
    < 引数 >
      obj (ArcSamples,ArcFrames) : 設定するデータオブジェクト
    < 返値 >
      なし
    < 説明 >
      データオブジェクトに設定する。
    < 例外 >
      TypeError
            
        '''
        if None == obj :
            self.samples = obj
        elif "ArcSamples" == obj.__class__.__name__ :
            self.samples = obj
        elif "ArcFrames" == obj.__class__.__name__ :
            self.samples = obj
        else :
            raise TypeError("object class(%s) is unsupported." % obj.__class__.__name__ )
            
    def is_frame(self):
        '''
        '''
        if None == self.samples :
            return None
        elif "ArcSamples" == self.samples.__class__.__name__ :
            return False
        elif "ArcFrames" == self.samples.__class__.__name__ :
            return True
        else :
            raise TypeError("object class(%s) is unsupported." % self.samples.__class__.__name__ )

    def have_parameters(self):
        '''
        '''
        if self.parameters is None :
            return False
        else :
            return True
        

    def set_time( self, start_time, sampling_interval, num_times=None):
        '''
    [ 関数名 ] set_time
    < 引数 >
      start_time (double|int)         : サンプリング開始時刻(秒|ピコ秒)
      sampling_interval (double|int)   : サンプリング間隔(秒|ピコ秒)
    < 返値 >
      なし
    < 説明 >
      メンバーに設定する。
            
        '''
        if isinstance(start_time, int) :
            self.start_time = int(start_time)
        else :
            self.start_time = start_time

        if isinstance(sampling_interval, int) :
            self.sampling_interval = int(sampling_interval)
        else :
            self.sampling_interval = sampling_interval

        self.num_of_times = num_times

    def set_samples(self, dtype, data, bsize=None):
        '''
    [ 関数名 ] set_samples
    < 引数 >
      dtype (string)     : データ型
      data  (string)     : データ配列(binary string)
      bsize (int)        : データバイト数
    < 返値 >
      なし
    < 説明 >
      データオブジェクトを設定する。
            
        '''
        self.samples = ArcSamples(dtype, data, bsize)
        
    def init_frames(self, i_type, x_size, y_size):
        '''
    [ 関数名 ] init_frames
    < 引数 >
      i_type(string) : イメージタイプ(データ型)
      x_size(int)    : X方向サイズ
      y_size(int)    : Y方向サイズ
    < 返値 >
      なし
    < 説明 >
      データオブジェクトをArcFramesに初期化する。
    < 例外 >
      TypeError
        '''
        self.samples = ArcFrames( i_type, x_size, y_size)

    def add_frame(self, binary_str, bsize=None):
        '''
    [ 関数名 ] add_frame
    < 引数 >
      binary_str (ByteArray) : データ一次元配列
      bsize (int)            : データバイト数
    < 返値 >
      なし
    < 説明 >
      1フレームのデータを追加する。
    < 例外 >
      RuntimeError
        '''
        if self.samples is None :
            raise RuntimeError( 'No initialize samples(ArcFrames).')
        else :
            self.samples.add_frame(binary_str, bsize)

[ クラス名 ] ArcData < パブリックメンバー > start_time (double|int) : サンプリング開始時刻(秒|ピコ秒) sampling_interval (double|int) : サンプリング間隔(秒|ピコ秒) samp_data (ArcSamples|ArcFrames) : データ・オブジェクト samp_params (ディクショナリ) : パラメータ連想配列 num_times (int) : 時間軸データ数

< 参照系メソッド > val() : データを取り出す (numpy) time() : 時間軸配列データを取り出す (numpy) num() : データ件数 num_times() : 時間軸配列データ件数 converted_rgb(): RGBデータに変換して取り出す(numpy)

< 更新系メソッド > set_data( obj) : データオブジェクトを設定する。 set_parameters( dict_obj) : パラメータ配列を設定する。 set_time( start_time, sampling_interval, num_times) : 時間軸情報を設定する。 set_samples( dtype, data, bsize=None) : データを設定する。 add_parameters( dict_obj) : パラメータ配列を追加する。 add_parameter( param_name, param_value, param_type) : パラメータを追加する。 init_frames( i_type, x_size, y_size) : データをフレーム構造に初期化する。 add_frame( binary_str, bsize=None) : データに1フレームデータを追加する。

< 説明 > チャネルデータを管理するクラス

[ Constructor ] < 引数 > start_time (double|int) : サンプリング開始時刻(秒|ピコ秒) sampling_interval (double|int) : サンプリング間隔(秒|ピコ秒) samp_data (ArcSamples|ArcFrames) : データ・オブジェクト samp_params (dict) : パラメータ連想配列 num_times (int) : 時間軸データ数

Methods

def add_frame(self, binary_str, bsize=None)
Expand source code
def add_frame(self, binary_str, bsize=None):
    '''
[ 関数名 ] add_frame
< 引数 >
  binary_str (ByteArray) : データ一次元配列
  bsize (int)            : データバイト数
< 返値 >
  なし
< 説明 >
  1フレームのデータを追加する。
< 例外 >
  RuntimeError
    '''
    if self.samples is None :
        raise RuntimeError( 'No initialize samples(ArcFrames).')
    else :
        self.samples.add_frame(binary_str, bsize)

[ 関数名 ] add_frame < 引数 > binary_str (ByteArray) : データ一次元配列 bsize (int) : データバイト数 < 返値 > なし < 説明 > 1フレームのデータを追加する。 < 例外 > RuntimeError

def add_parameter(self, param_name, param_value, param_type)
Expand source code
def add_parameter(self, param_name, param_value, param_type):
    '''
[ 関数名 ] add_parameter
< 引数 >
  param_name (string)       : 追加するパラメータ名
  param_value
      (int,double,string,..) : 追加するパラメータ値
  param_type (int)           : 追加するパラメータの型
< 返値 >
  なし
< 説明 >
  パラメータオブジェクトに追加する。
    
    '''
    self.parameters[param_name] = param_value
    self.parameters[param_name+'#PTYPE'] = param_type

[ 関数名 ] add_parameter < 引数 > param_name (string) : 追加するパラメータ名 param_value (int,double,string,..) : 追加するパラメータ値 param_type (int) : 追加するパラメータの型 < 返値 > なし < 説明 > パラメータオブジェクトに追加する。

def add_parameters(self, dict_obj)
Expand source code
def add_parameters(self, dict_obj):
    '''
[ 関数名 ] add_parameters
< 引数 >
  dict_obj (dict)    : 追加するパラメータオブジェクト。
< 返値 >
  なし
< 説明 >
  パラメータオブジェクトに追加する。
    
    '''
    if self.parameters is None :
        self.parameters = dict_obj
    else :
        self.parameters.update( dict_obj)

[ 関数名 ] add_parameters < 引数 > dict_obj (dict) : 追加するパラメータオブジェクト。 < 返値 > なし < 説明 > パラメータオブジェクトに追加する。

def converted_rgb(self)
Expand source code
def converted_rgb(self):
    '''
[ 関数名] converted_rgb
< 引数 >
  なし
< 返値 >
  データの3次元配列RGBデータ(numpy)
< 説明 >
  データオブジェクトのデータをRGBデータに変換し、numpyクラスのオブジェクトにする。
       
    '''
    if self.is_frame()  :
        return self.samples.converted_rgb()
    else :
        return None

[ 関数名] converted_rgb < 引数 > なし < 返値 > データの3次元配列RGBデータ(numpy) < 説明 > データオブジェクトのデータをRGBデータに変換し、numpyクラスのオブジェクトにする。

def have_parameters(self)
Expand source code
def have_parameters(self):
    '''
    '''
    if self.parameters is None :
        return False
    else :
        return True
def init_frames(self, i_type, x_size, y_size)
Expand source code
def init_frames(self, i_type, x_size, y_size):
    '''
[ 関数名 ] init_frames
< 引数 >
  i_type(string) : イメージタイプ(データ型)
  x_size(int)    : X方向サイズ
  y_size(int)    : Y方向サイズ
< 返値 >
  なし
< 説明 >
  データオブジェクトをArcFramesに初期化する。
< 例外 >
  TypeError
    '''
    self.samples = ArcFrames( i_type, x_size, y_size)

[ 関数名 ] init_frames < 引数 > i_type(string) : イメージタイプ(データ型) x_size(int) : X方向サイズ y_size(int) : Y方向サイズ < 返値 > なし < 説明 > データオブジェクトをArcFramesに初期化する。 < 例外 > TypeError

def is_frame(self)
Expand source code
def is_frame(self):
    '''
    '''
    if None == self.samples :
        return None
    elif "ArcSamples" == self.samples.__class__.__name__ :
        return False
    elif "ArcFrames" == self.samples.__class__.__name__ :
        return True
    else :
        raise TypeError("object class(%s) is unsupported." % self.samples.__class__.__name__ )
def num(self)
Expand source code
def num(self):
    '''
[ 関数名 ] num
< 引数 >
  なし
< 返値 >
  データオブジェクトのデータ件数 (int)
< 説明 >
  フレームの場合、フレーム数
    '''
    if self.samples is None :
        return None
    else :
        return self.samples.num()

[ 関数名 ] num < 引数 > なし < 返値 > データオブジェクトのデータ件数 (int) < 説明 > フレームの場合、フレーム数

def num_times(self)
Expand source code
def num_times(self):
    '''
[ 関数名 ] num_times
< 引数 >
  なし
< 返値 >
  時間軸データ件数 (int)
< 説明 >
  サンプル数と異る場合あり。
    '''
    if self.num_of_times is None :
        return self.num()
    else :
        return self.num_of_times

[ 関数名 ] num_times < 引数 > なし < 返値 > 時間軸データ件数 (int) < 説明 > サンプル数と異る場合あり。

def set_data(self, obj)
Expand source code
def set_data(self, obj):
    '''
[ 関数名 ] set_data
< 引数 >
  obj (ArcSamples,ArcFrames) : 設定するデータオブジェクト
< 返値 >
  なし
< 説明 >
  データオブジェクトに設定する。
< 例外 >
  TypeError
        
    '''
    if None == obj :
        self.samples = obj
    elif "ArcSamples" == obj.__class__.__name__ :
        self.samples = obj
    elif "ArcFrames" == obj.__class__.__name__ :
        self.samples = obj
    else :
        raise TypeError("object class(%s) is unsupported." % obj.__class__.__name__ )

[ 関数名 ] set_data < 引数 > obj (ArcSamples,ArcFrames) : 設定するデータオブジェクト < 返値 > なし < 説明 > データオブジェクトに設定する。 < 例外 > TypeError

def set_parameters(self, dict_obj)
Expand source code
def set_parameters(self, dict_obj):
    '''
[ 関数名 ] set_parameters
< 引数 >
  dict_obj (dict)    : 設定するパラメータオブジェクト
< 返値 >
  なし
< 説明 >
  パラメータオブジェクトに設定する。
    '''
    self.parameters = dict_obj

[ 関数名 ] set_parameters < 引数 > dict_obj (dict) : 設定するパラメータオブジェクト < 返値 > なし < 説明 > パラメータオブジェクトに設定する。

def set_samples(self, dtype, data, bsize=None)
Expand source code
def set_samples(self, dtype, data, bsize=None):
    '''
[ 関数名 ] set_samples
< 引数 >
  dtype (string)     : データ型
  data  (string)     : データ配列(binary string)
  bsize (int)        : データバイト数
< 返値 >
  なし
< 説明 >
  データオブジェクトを設定する。
        
    '''
    self.samples = ArcSamples(dtype, data, bsize)

[ 関数名 ] set_samples < 引数 > dtype (string) : データ型 data (string) : データ配列(binary string) bsize (int) : データバイト数 < 返値 > なし < 説明 > データオブジェクトを設定する。

def set_time(self, start_time, sampling_interval, num_times=None)
Expand source code
def set_time( self, start_time, sampling_interval, num_times=None):
    '''
[ 関数名 ] set_time
< 引数 >
  start_time (double|int)         : サンプリング開始時刻(秒|ピコ秒)
  sampling_interval (double|int)   : サンプリング間隔(秒|ピコ秒)
< 返値 >
  なし
< 説明 >
  メンバーに設定する。
        
    '''
    if isinstance(start_time, int) :
        self.start_time = int(start_time)
    else :
        self.start_time = start_time

    if isinstance(sampling_interval, int) :
        self.sampling_interval = int(sampling_interval)
    else :
        self.sampling_interval = sampling_interval

    self.num_of_times = num_times

[ 関数名 ] set_time < 引数 > start_time (double|int) : サンプリング開始時刻(秒|ピコ秒) sampling_interval (double|int) : サンプリング間隔(秒|ピコ秒) < 返値 > なし < 説明 > メンバーに設定する。

def time(self)
Expand source code
def time(self):
    '''
[ 関数名 ] time
< 引数 >
  なし
< 返値 >
  データオブジェクトの時間軸配列データ(numpy)
< 説明 >
  時間軸情報がない場合は、index配列になる。
    
    '''
    num = self.num_times()
    if num is None :
        return None

    if self.sampling_interval is None :
        interval = int(0)
    else :
        interval = self.sampling_interval

    if 0.0 == interval :
        interval = int(0)
        
    if self.start_time is None :
        start_t = int(0)
    else :
        start_t = self.start_time

    if isinstance(interval, int) :
        if 0 < interval :
            return (start_t + interval * np.array(list(range( 1, num+1)), dtype=np.int64))/1000000000000.0 
        else : 
            return (start_t + np.array(list(range( 1, num+1)))) 
    else : 
        return (start_t + interval * np.array(list(range( 1, num+1)))) 

[ 関数名 ] time < 引数 > なし < 返値 > データオブジェクトの時間軸配列データ(numpy) < 説明 > 時間軸情報がない場合は、index配列になる。

def val(self)
Expand source code
def val(self):
    '''
[ 関数名] val
< 引数 >
  なし
< 返値 >
  データオブジェクトの配列データ (numpy)
< 説明 >
  データオブジェクトのデータをnumpyクラスのオブジェクトに変換する。
       
    '''
    if self.samples is None :
        return None
    else :
        return self.samples.val()

[ 関数名] val < 引数 > なし < 返値 > データオブジェクトの配列データ (numpy) < 説明 > データオブジェクトのデータをnumpyクラスのオブジェクトに変換する。

class ArcFrames (i_type, x_size, y_size)
Expand source code
class ArcFrames(object):
    '''
[ クラス名 ] ArcFrames
< パブリックメンバー >
  image_type (string)    : データ型 
  np_type (int)          : numpyデータ型
  bytes_per_sample (int) : 1サンプルあたりのバイト数
  x_size (int)           : X方向サイズ
  y_size (int)           : Y方向サイズ
  frames (Frame[])       : フレームデータ配列

< 参照系メソッド >
  val()           : データを取り出す(numpy) 
  num()           : フレーム件数
  converted_rgb() : RGB変換してデータを取り出す(numpy)

< 更新系メソッド >
  add_frame(self, binary_str, bsize=None)
                 : 1フレームのデータを追加する。

<説  明>
  同一形式のフレームの集合体
        
    '''

    def __init__(self, i_type, x_size, y_size):
        '''
    [ コンストラクタ ]
    < 引数 >
      i_type (string) : イメージタイプ
      x_size (int)    : X方向サイズ
      y_size (int)    : Y方向サイズ
    < 例外 >
      TypeError
        '''
        self.image_type = i_type
        self.np_type = _to_numpy_type( i_type )
        self.bytes_per_sample = _to_bytes_per_sample( i_type )
        self.x_size = x_size
        self.y_size = y_size
        self.frames = []


    def add_frame(self, binary_str, bsize=None):
        '''
   [ 関数名 ] add_frame
   < 引数 >
     binary_str (ByteArray) : フレームデータ一次元配列
     bsize (int)            : データバイト数
   < 返値 >
      なし
   < 説明 >
     1フレームのデータを追加する。
   < 例外 >
      RuntimeError : framesが初期化されていない場合
        '''
        if self.frames is None :
            raise RuntimeError("No initialize frames." )
        else :
            fr = Frame(binary_str, bsize)
            self.frames.append(fr)
        
        
    def num(self):
        '''
    [ 関数名 ] num
    < 引数 >
      なし
    < 返値 >
      フレーム件数 (int)
    < 説明 >
        '''
        if self.frames is None :
            return None
        else :
            return len(self.frames)
    

    def val(self):
        '''
    [ 関数名 ] val
    < 引数 >
      なし
    < 返値 >
      データの3次元配列データ (numpy)
    < 説明 >
    < 例外 > 
      RuntimeError : フレームサイズが異なる場合
           
        '''
        sz = self.num()
        if sz is None :
            return None

        sy = self.y_size
        sx = self.x_size
        fr_size = sy*sx
        
        ary_3d = np.empty([sz,sy,sx], self.np_type)
        for fr in range(sz):
            if fr_size != self.frames[fr].byte_length()/self.bytes_per_sample :
                raise RuntimeError( 'illegal frame object size' )
            
            ary_3d[fr,:,:] = np.frombuffer(self.frames[fr].block_bin_str , self.np_type).reshape((sy, sx))
        return ary_3d

    def converted_rgb(self):
        '''
    [ 関数名 ] converted_rgb
    < 引数 >
      なし
    < 返値 >
      データの3次元配列RGBデータ(numpy)
    < 説明 >
    < 例外 > 
      RuntimeError : フレームサイズが異なる場合
           
        '''
        sz = self.num()
        if sz is None :
            return None

        import labcom._retrieve as _retrieve  
        sy = self.y_size
        sx = self.x_size
        fr_size = sy*sx
        
        if self.image_type == 'YUV422' :
            ary_4d = np.empty([sz,sy,sx,3], np.uint8)
            for fr in range(sz):
                if fr_size != self.frames[fr].byte_length()/self.bytes_per_sample :
                    raise RuntimeError( 'illegal frame object size' )
                rgb_bin = _retrieve.rgb_from_yuv422(self.frames[fr].block_bin_str, self.frames[fr].byte_length(),0 )
                ary_4d[fr,:,:,:] = np.frombuffer(rgb_bin , np.uint8).reshape((sy, sx, 3))
                
            return ary_4d

        elif self.image_type == 'YUY2' :
            ary_4d = np.empty([sz,sy,sx,3], np.uint8)
            for fr in range(sz):
                if fr_size != self.frames[fr].byte_length()/self.bytes_per_sample :
                    raise RuntimeError( 'illegal frame object size' )
                rgb_bin = _retrieve.rgb_from_yuy2(self.frames[fr].block_bin_str, self.frames[fr].byte_length())
                ary_4d[fr,:,:,:] = np.frombuffer(rgb_bin , np.uint8).reshape((sy, sx, 3))

            return ary_4d
                
        else :
            return None

[ クラス名 ] ArcFrames < パブリックメンバー > image_type (string) : データ型 np_type (int) : numpyデータ型 bytes_per_sample (int) : 1サンプルあたりのバイト数 x_size (int) : X方向サイズ y_size (int) : Y方向サイズ frames (Frame[]) : フレームデータ配列

< 参照系メソッド > val() : データを取り出す(numpy) num() : フレーム件数 converted_rgb() : RGB変換してデータを取り出す(numpy)

< 更新系メソッド > add_frame(self, binary_str, bsize=None) : 1フレームのデータを追加する。

<説 明> 同一形式のフレームの集合体

[ コンストラクタ ] < 引数 > i_type (string) : イメージタイプ x_size (int) : X方向サイズ y_size (int) : Y方向サイズ < 例外 > TypeError

Methods

def add_frame(self, binary_str, bsize=None)
Expand source code
 def add_frame(self, binary_str, bsize=None):
     '''
[ 関数名 ] add_frame
< 引数 >
  binary_str (ByteArray) : フレームデータ一次元配列
  bsize (int)            : データバイト数
< 返値 >
   なし
< 説明 >
  1フレームのデータを追加する。
< 例外 >
   RuntimeError : framesが初期化されていない場合
     '''
     if self.frames is None :
         raise RuntimeError("No initialize frames." )
     else :
         fr = Frame(binary_str, bsize)
         self.frames.append(fr)

[ 関数名 ] add_frame < 引数 > binary_str (ByteArray) : フレームデータ一次元配列 bsize (int) : データバイト数 < 返値 > なし < 説明 > 1フレームのデータを追加する。 < 例外 > RuntimeError : framesが初期化されていない場合

def converted_rgb(self)
Expand source code
def converted_rgb(self):
    '''
[ 関数名 ] converted_rgb
< 引数 >
  なし
< 返値 >
  データの3次元配列RGBデータ(numpy)
< 説明 >
< 例外 > 
  RuntimeError : フレームサイズが異なる場合
       
    '''
    sz = self.num()
    if sz is None :
        return None

    import labcom._retrieve as _retrieve  
    sy = self.y_size
    sx = self.x_size
    fr_size = sy*sx
    
    if self.image_type == 'YUV422' :
        ary_4d = np.empty([sz,sy,sx,3], np.uint8)
        for fr in range(sz):
            if fr_size != self.frames[fr].byte_length()/self.bytes_per_sample :
                raise RuntimeError( 'illegal frame object size' )
            rgb_bin = _retrieve.rgb_from_yuv422(self.frames[fr].block_bin_str, self.frames[fr].byte_length(),0 )
            ary_4d[fr,:,:,:] = np.frombuffer(rgb_bin , np.uint8).reshape((sy, sx, 3))
            
        return ary_4d

    elif self.image_type == 'YUY2' :
        ary_4d = np.empty([sz,sy,sx,3], np.uint8)
        for fr in range(sz):
            if fr_size != self.frames[fr].byte_length()/self.bytes_per_sample :
                raise RuntimeError( 'illegal frame object size' )
            rgb_bin = _retrieve.rgb_from_yuy2(self.frames[fr].block_bin_str, self.frames[fr].byte_length())
            ary_4d[fr,:,:,:] = np.frombuffer(rgb_bin , np.uint8).reshape((sy, sx, 3))

        return ary_4d
            
    else :
        return None

[ 関数名 ] converted_rgb < 引数 > なし < 返値 > データの3次元配列RGBデータ(numpy) < 説明 > < 例外 > RuntimeError : フレームサイズが異なる場合

def num(self)
Expand source code
def num(self):
    '''
[ 関数名 ] num
< 引数 >
  なし
< 返値 >
  フレーム件数 (int)
< 説明 >
    '''
    if self.frames is None :
        return None
    else :
        return len(self.frames)

[ 関数名 ] num < 引数 > なし < 返値 > フレーム件数 (int) < 説明 >

def val(self)
Expand source code
def val(self):
    '''
[ 関数名 ] val
< 引数 >
  なし
< 返値 >
  データの3次元配列データ (numpy)
< 説明 >
< 例外 > 
  RuntimeError : フレームサイズが異なる場合
       
    '''
    sz = self.num()
    if sz is None :
        return None

    sy = self.y_size
    sx = self.x_size
    fr_size = sy*sx
    
    ary_3d = np.empty([sz,sy,sx], self.np_type)
    for fr in range(sz):
        if fr_size != self.frames[fr].byte_length()/self.bytes_per_sample :
            raise RuntimeError( 'illegal frame object size' )
        
        ary_3d[fr,:,:] = np.frombuffer(self.frames[fr].block_bin_str , self.np_type).reshape((sy, sx))
    return ary_3d

[ 関数名 ] val < 引数 > なし < 返値 > データの3次元配列データ (numpy) < 説明 > < 例外 > RuntimeError : フレームサイズが異なる場合

class ArcSamples (dtype=None, binary_str=None, bsize=None)
Expand source code
class ArcSamples(object):
    '''
[ クラス名 ] ArcSamples
< パブリックメンバー >
  block_bin_str (ByteArray) : サンプリングデータ
  image_type (string)       : データ型 
  np_type (int)             : numpyデータ型
  bytes_per_sample (int)    : 1サンプルあたりのバイト数

< 参照系メソッド >
  val()        : データを取り出す(numpy) 
  time()       : 時間軸配列データを取り出す(numpy) 
  num()             : データ件数

< 更新系メソッド >
  set_val(self, dtype, binary_str, bsize=None)
                 : データを設定する。

<説  明> 
  サンプリングデータを管理する。
    '''

    def __init__(self, dtype=None, binary_str=None, bsize=None):
        '''
    [ コンストラクタ ] 
    < 引数 >
      dtype (string)         : データ型
      binary_str (ByteArray) : サンプリングデータ配列
      bsize (int)            : データバイト数
    < 返値 >
      なし
    < 説明 >
    < 例外 >
      TypeError
        '''
        if dtype is None :
            self.image_type = None
            self.np_type = None
            self.bytes_per_sample = None
        else :
            self.image_type = dtype
            self.np_type = _to_numpy_type( dtype )
            self.bytes_per_sample = _to_bytes_per_sample( dtype )
            
        if binary_str is None : 
            self.block_bin_str = None
        else :
            if bsize is None :
                self.block_bin_str = binary_str
            else :
                self.block_bin_str = binary_str[0:bsize]

    def val(self):
        '''
    [ 関数名 ] val
    < 引数 >
      なし
    < 返値 >
      データの配列データ (numpy)
    < 説明 >
      サンプリングデータをnumpyクラスのオブジェクトで取得する。。
           
        '''
        if self.block_bin_str is None :
            return None
        
        ary = np.frombuffer(self.block_bin_str , self.np_type)
        return ary
    
    
    def num(self):
        '''
    [ 関数名 ] num
    < 引数 >
      なし
    < 返値 >
      サンプリングデータのデータ件数(int)
    < 説明 >

        '''
        num_sample = len(self.block_bin_str)//self.bytes_per_sample
        
        return num_sample
    
     
    def set_val(self, dtype, binary_str, bsize=None):
        '''
    [ 関数名 ] set_val
    < 引数 >
      dtype (string)        : データ型
      binary_str (ByteArray): サンプリングデータ配列
      bsize (int)           : データバイト数
    < 返値 >
      なし
    < 説明 >
      メンバー変数に設定する。
            
        '''
        if dtype is None :
            self.image_type = None
            self.np_type = None
            self.bytes_per_sample = None
        else :
            self.image_type = dtype
            self.np_type = _to_numpy_type( dtype )
            self.bytes_per_sample = _to_bytes_per_sample( dtype )
            
        if binary_str is None : 
            self.block_bin_str = None
        else :
            if bsize is None :
                self.block_bin_str = binary_str
            else :
                self.block_bin_str = binary_str[0:bsize]

[ クラス名 ] ArcSamples < パブリックメンバー > block_bin_str (ByteArray) : サンプリングデータ image_type (string) : データ型 np_type (int) : numpyデータ型 bytes_per_sample (int) : 1サンプルあたりのバイト数

< 参照系メソッド > val() : データを取り出す(numpy) time() : 時間軸配列データを取り出す(numpy) num() : データ件数

< 更新系メソッド > set_val(self, dtype, binary_str, bsize=None) : データを設定する。

<説 明> サンプリングデータを管理する。

[ コンストラクタ ] < 引数 > dtype (string) : データ型 binary_str (ByteArray) : サンプリングデータ配列 bsize (int) : データバイト数 < 返値 > なし < 説明 > < 例外 > TypeError

Methods

def num(self)
Expand source code
def num(self):
    '''
[ 関数名 ] num
< 引数 >
  なし
< 返値 >
  サンプリングデータのデータ件数(int)
< 説明 >

    '''
    num_sample = len(self.block_bin_str)//self.bytes_per_sample
    
    return num_sample

[ 関数名 ] num < 引数 > なし < 返値 > サンプリングデータのデータ件数(int) < 説明 >

def set_val(self, dtype, binary_str, bsize=None)
Expand source code
def set_val(self, dtype, binary_str, bsize=None):
    '''
[ 関数名 ] set_val
< 引数 >
  dtype (string)        : データ型
  binary_str (ByteArray): サンプリングデータ配列
  bsize (int)           : データバイト数
< 返値 >
  なし
< 説明 >
  メンバー変数に設定する。
        
    '''
    if dtype is None :
        self.image_type = None
        self.np_type = None
        self.bytes_per_sample = None
    else :
        self.image_type = dtype
        self.np_type = _to_numpy_type( dtype )
        self.bytes_per_sample = _to_bytes_per_sample( dtype )
        
    if binary_str is None : 
        self.block_bin_str = None
    else :
        if bsize is None :
            self.block_bin_str = binary_str
        else :
            self.block_bin_str = binary_str[0:bsize]

[ 関数名 ] set_val < 引数 > dtype (string) : データ型 binary_str (ByteArray): サンプリングデータ配列 bsize (int) : データバイト数 < 返値 > なし < 説明 > メンバー変数に設定する。

def val(self)
Expand source code
def val(self):
    '''
[ 関数名 ] val
< 引数 >
  なし
< 返値 >
  データの配列データ (numpy)
< 説明 >
  サンプリングデータをnumpyクラスのオブジェクトで取得する。。
       
    '''
    if self.block_bin_str is None :
        return None
    
    ary = np.frombuffer(self.block_bin_str , self.np_type)
    return ary

[ 関数名 ] val < 引数 > なし < 返値 > データの配列データ (numpy) < 説明 > サンプリングデータをnumpyクラスのオブジェクトで取得する。。

class Frame (binary_str, bsize=None)
Expand source code
class Frame(object):
    '''
[ クラス名 ] Frame
< パブリックメンバー >
   block_bin_str (string)    : フレームデータ(binary string)

< 参照系メソッド >
  byte_length()  : データバイト数

< 更新系メソッド >

< 説  明 > 
  1フレームのデータを管理する。
    '''


    def __init__(self, binary_str, bsize=None ):
        '''
    [ コンストラクタ ]
    < 引数 >
      binary_str (ByteArray) : フレームデータ配列
      bsize (int)            : データバイト数
        '''
        if bsize is None :
            self.block_bin_str = binary_str
        else :
            self.block_bin_str = binary_str[0:bsize]

    def byte_length(self ) :
        '''
    [ 関数名 ] byte_length
    < 引数 >
      なし
    < 返値 >
      データバイト数
    < 説明 >
      フレームデータのバイト数を取得する。(データ数ではない)
        '''
        if self.block_bin_str is None :
            return None
        else :
            return len(self.block_bin_str)

[ クラス名 ] Frame < パブリックメンバー > block_bin_str (string) : フレームデータ(binary string)

< 参照系メソッド > byte_length() : データバイト数

< 更新系メソッド >

< 説 明 > 1フレームのデータを管理する。

[ コンストラクタ ] < 引数 > binary_str (ByteArray) : フレームデータ配列 bsize (int) : データバイト数

Methods

def byte_length(self)
Expand source code
def byte_length(self ) :
    '''
[ 関数名 ] byte_length
< 引数 >
  なし
< 返値 >
  データバイト数
< 説明 >
  フレームデータのバイト数を取得する。(データ数ではない)
    '''
    if self.block_bin_str is None :
        return None
    else :
        return len(self.block_bin_str)

[ 関数名 ] byte_length < 引数 > なし < 返値 > データバイト数 < 説明 > フレームデータのバイト数を取得する。(データ数ではない)