class Labcom::ArcFrames

Authors

S.imazu

Version

22.0.0

Date

2020-07-31

[クラス名] ArcFrames

[メンバー]

[クラスメソッド]

[インスタンスメソッド]

[説 明]

  1. 同一形式のフレームの集合体

[UPDATE履歴]

18.0.0 初版 22.0.0 追加:converted_rgb()

Attributes

frames[R]
image_type[R]
x_size[R]
y_size[R]

Public Class Methods

new( i_type, x_size, y_size) click to toggle source
i_type(string)

イメージタイプ

[ #x_size(int) ]  X方向サイズ [ #y_size(int) ]  Y方向サイズ

例外

TypeError:to_narray_type

[説  明]
コンストラクタ
イメージタイプ: 'GRAY8', 'GRAY10', 'GREY8', 'GREY10', 'RGB', 'YUV',...
# File labcom/ArcFrames.rb, line 123
def initialize( i_type, x_size, y_size)
  @image_type = i_type
  @x_size = x_size
  @y_size = y_size
  @na_type = Labcom::to_narray_type( i_type )
  @bytes_per_sample = Labcom::to_bytes_per_sample( i_type )
  @frames = []
end

Public Instance Methods

add_frame( binary_str, bsize=nil) click to toggle source
binary_str (string)

データ配列(binary string)

bsize (int)

有効バイトデータサイズ

返値

なし

例外

RuntimeError

[説  明]
1フレームのデータを追加する。
# File labcom/ArcFrames.rb, line 150
def add_frame( binary_str, bsize=nil)
  if nil != @frames then
    @frames.push(Frame.new(binary_str, bsize))
  else
    raise RuntimeError, 'No initialize frames.'
  end
end
converted_rgb() click to toggle source
引数

なし

返値

4次元配列オブジェクト(NArray)

例外

RuntimeError

[説  明]
フレームデータをNArrayクラスの4次元配列オブジェクトで戻す。
# File labcom/ArcFrames.rb, line 217
def converted_rgb()
  sz = num()
  return nil if nil == sz
   
  sy = @y_size
  sx = @x_size
  fr_size = sy*sx
  if( @image_type == 'YUV422') then
      ary_4d = NArray.new(NArray::BYTE, 3,sx,sy,sz)
              for fr in 0..sz-1 do
                if fr_size != @frames[fr].byte_length/@bytes_per_sample then
                  raise RuntimeError, 'Illegal frame object size'
                end
                rgb_bin = Retrieve.rgb_from_yuv422(@frames[fr].block_bin_str, @frames[fr].byte_length(),0 )
                ary_4d[0..-1,0..-1,0..-1,fr] = NArray.to_na( rgb_bin , NArray::BYTE, 3, sx, sy)
              end
      return ary_4d
  elsif( @image_type == 'YUY2') then
      ary_4d = NArray.new(NArray::BYTE, 3,sx,sy,sz)
              for fr in 0..sz-1 do
                if fr_size != @frames[fr].byte_length/@bytes_per_sample then
                  raise RuntimeError, 'Illegal frame object size'
                end
                rgb_bin = Retrieve.rgb_from_yuy2(@frames[fr].block_bin_str, @frames[fr].byte_length() )
                ary_4d[0..-1,0..-1,0..-1,fr] = NArray.to_na( rgb_bin , NArray::BYTE, 3, sx, sy)
              end
      return ary_4d
  end
  return nil

end
num() click to toggle source
引数

なし

返値

フレーム件数(int)

[説  明]
データ配列のデータ件数ではない。
# File labcom/ArcFrames.rb, line 169
def num()
  if nil != @frames then
    return @frames.length
  end
  return nil
end
val() click to toggle source
引数

なし

返値

3次元配列オブジェクト(NArray)

例外

RuntimeError

[説  明]
フレームデータをNArrayクラスの3次元配列オブジェクトで戻す。
# File labcom/ArcFrames.rb, line 188
def val()
  sz = num()
  return nil if nil == sz
   
  sy = @y_size
  sx = @x_size
  fr_size = sy*sx
  ary_3d = NArray.new(@na_type, sx,sy,sz)
  for fr in 0..sz-1 do
    if fr_size != @frames[fr].byte_length/@bytes_per_sample then
      raise RuntimeError, 'Illegal frame object size'
    end 
    ary_3d[0..-1,0..-1,fr] = NArray.to_na( @frames[fr].block_bin_str , @na_type, sx, sy)
  end
  return ary_3d
end