class Labcom3::ArcFrames

Authors

S.imazu

Version

25.2.0

Date

2024-11-20

[ 説明 ]

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

[ メンバー ]

[ クラスメソッド ]

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

[UPDATE履歴 ]

18.0.0

初版

22.0.0

追加: converted_rgb()

25.2.0

NArray to Numo::NArray

Attributes

bytes_per_sample[R]
frames[R]
image_type[R]
na_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 lib/labcom3/ArcFrames.rb, line 124
def initialize( i_type, x_size, y_size)
  @image_type = i_type
  @x_size = x_size
  @y_size = y_size
  @na_type = Labcom3::to_narray_type( i_type )
  @bytes_per_sample = Labcom3::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 lib/labcom3/ArcFrames.rb, line 154
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次元配列オブジェクト(Numo::NArray)

例 外

RuntimeError

説 明

フレームデータをNumo::NArrayクラスの4次元配列オブジェクトで戻す。

# File lib/labcom3/ArcFrames.rb, line 221
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(Numo::UInt8, 3,sx,sy,sz)
      ary_4d = Labcom3::new_shape(Numo::UInt8, [sz,sy,sx,3]).fill(0)
      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 , Numo::UInt8, 3, sx, sy)
        ary_4d[fr,0..-1,0..-1,0..-1] = Labcom3::to_narray( rgb_bin , Numo::UInt8, [sy,sx,3])
      end
      return ary_4d
  elsif( @image_type == 'YUY2') then
      #ary_4d = NArray.new(Numo::UInt8, 3,sx,sy,sz)
      ary_4d = Labcom3::new_shape(Numo::UInt8, [sz,sy,sx,3]).fill(0)
      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 , Numo::UInt8, 3, sx, sy)
        ary_4d[fr,0..-1,0..-1,0..-1] = Labcom3::to_narray( rgb_bin , Numo::UInt8, [sy,sx,3])
      end
      return ary_4d
  end
  return nil

end
num() click to toggle source
引 数

なし

返 値

フレーム件数(int)

説 明

データ配列のデータ件数ではない。

# File lib/labcom3/ArcFrames.rb, line 172
def num()
  if nil != @frames then
    return @frames.length
  end
  return nil
end
val() click to toggle source
引 数

なし

返 値

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

例 外

RuntimeError

説 明

フレームデータをNumo::NArrayクラスの3次元配列オブジェクトで戻す。

# File lib/labcom3/ArcFrames.rb, line 190
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)
  ary_3d = Labcom3::new_shape(@na_type, [sz,sy,sx]).fill(0)
  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)
    #ary_3d[fr..fr,0..-1,0..-1].store( Labcom3::to_narray( @frames[fr].block_bin_str , @na_type, [sy, sx]) ) OK
    ary_3d[fr,0..-1,0..-1] = Labcom3::to_narray( @frames[fr].block_bin_str , @na_type, [sy, sx]) # OK
  end
  return ary_3d
end