代码之家  ›  专栏  ›  技术社区  ›  Stefan

理解“/dev/video”输出

  •  2
  • Stefan  · 技术社区  · 15 年前

    /开发/视频 设备。就像 motion 做。

    我怎样才能把这些数据解释成一个可以理解的像素矩阵呢?

    参考程序代码:

    #!/usr/bin/ruby
    
    # calculates a percentage difference between two array's
    def percentage_difference( arrayA, arrayB )
      top_size = arrayA.size > arrayB.size ? arrayA.size : arrayB.size
      diff_elements = 0;
      0.upto( top_size - 1 ) do |i|
        diff_elements += 1 unless arrayA[i] == arrayB[i]
      end
      ( 1.0 * diffelements ) / top_size
    end
    
    
    cam = File.open( '/dev/video' );
    
    lastframe = [];
    
    while( true ) do
      # reads a frame from the open video device ( cam ) and converts to bytes;
      newframe = cam.readpartial( num_of_bytes_per_frame ).bytes.map { |b| b }
    
      # prints the percentage difference between the two frames
      puts percentage_difference( lastframe, newframe );
    
      lastframe = newframe;
    end
    
    2 回复  |  直到 15 年前
        1
  •  1
  •   Nicolas Raoul    15 年前

    我对这个话题一无所知,但也许这也适用?
    有一个文档解释了每个字节的含义,以及C中的代码示例:

    http://v4l2spec.bytesex.org

        2
  •  2
  •   jartieda    15 年前

    读取/dev/video并不简单。 我建议为此使用一个特殊的库。

    推荐文章