Exemplo n.º 1
0
def decode_frames(input_directory, zxing_path):
    """Decodes the barcodes overlaid in each frame.

  The function uses the Zxing command-line tool from the Zxing C++ distribution
  to decode the barcode in every PNG frame from the input directory. The frames
  should be named frame_xxxx.png, where xxxx is the frame number. The frame
  numbers should be consecutive and should start from 0001.
  The decoding results in a frame_xxxx.txt file for every successfully decoded
  barcode. This file contains the decoded barcode as 12-digit string (UPC-A
  format: 11 digits content + one check digit).

  Args:
    input_directory(string): The input directory from where the PNG frames are
      read.
    zxing_path(string): The path to the zxing binary. If specified as None,
      the PATH will be searched for it.
  Return:
    (bool): True if the decoding succeeded.
  """
    if not zxing_path:
        zxing_path = 'zxing.exe' if sys.platform == 'win32' else 'zxing'
    print 'Decoding barcodes from PNG files with %s...' % zxing_path
    return helper_functions.perform_action_on_all_files(
        directory=input_directory,
        file_pattern='frame_',
        file_extension='png',
        start_number=1,
        action=_decode_barcode_in_file,
        command_line_decoder=zxing_path)
def decode_frames(input_directory, zxing_dir=None):
  """Decodes the barcodes overlaid in each frame.

  The function uses the Zxing command-line tool from the Zxing C++ distribution
  to decode the barcode in every PNG frame from the input directory. The frames
  should be named frame_xxxx.png, where xxxx is the frame number. The frame
  numbers should be consecutive and should start from 0001.
  The decoding results in a frame_xxxx.txt file for every successfully decoded
  barcode. This file contains the decoded barcode as 12-digit string (UPC-A
  format: 11 digits content + one check digit).

  Args:
    input_directory(string): The input directory from where the PNG frames are
      read.
    zxing_dir(string): The directory containing the zxing executable. If
      omitted, the PATH will be searched for it.
  Return:
    (bool): True if the decoding went without errors.
  """
  zxing_executable = 'zxing.exe' if sys.platform == 'win32' else 'zxing'
  if zxing_dir:
    zxing_executable = os.path.join(zxing_dir, zxing_executable)
  print 'Decoding barcodes from PNG files with %s...' % zxing_executable
  return helper_functions.perform_action_on_all_files(
      directory=input_directory, file_pattern='frame_',
      file_extension='png', start_number=1, action=_decode_barcode_in_file,
      command_line_decoder=zxing_executable)
Exemplo n.º 3
0
def decode_frames(barcode_width, barcode_height, input_directory='.',
                  path_to_zxing='zxing-read-only'):
  """Decodes the barcodes overlaid in each frame.

  The function uses the example Java command-line tool from the Zxing
  distribution to decode the barcode in every PNG frame from the input
  directory. The frames should be named frame_xxxx.png, where xxxx is the frame
  number. The frame numbers should be consecutive and should start from 0001.
  The decoding results in a frame_xxxx.txt file for every successfully decoded
  barcode. This file contains the decoded barcode as 12-digit string (UPC-A
  format: 11 digits content + one check digit).

  Args:
    barcode_width(int): Width of the barcode.
    barcode_height(int): Height of the barcode.
    input_directory(string): The input directory from where the PNG frames are
      read.
    path_to_zxing(string): The path to Zxing.
  Return:
    (bool): True if the decoding went without errors.
  """
  jars = helper_functions.form_jars_string(path_to_zxing)
  command_line_decoder ='com.google.zxing.client.j2se.CommandLineRunner'
  return helper_functions.perform_action_on_all_files(
      directory=input_directory, file_pattern='frame_',
      file_extension='png', start_number=1, action=_decode_barcode_in_file,
      barcode_width=barcode_width, barcode_height=barcode_height, jars=jars,
      command_line_decoder=command_line_decoder)
Exemplo n.º 4
0
def decode_frames(barcode_width,
                  barcode_height,
                  input_directory='.',
                  path_to_zxing='zxing-read-only'):
    """Decodes the barcodes overlaid in each frame.

  The function uses the example Java command-line tool from the Zxing
  distribution to decode the barcode in every PNG frame from the input
  directory. The frames should be named frame_xxxx.png, where xxxx is the frame
  number. The frame numbers should be consecutive and should start from 0001.
  The decoding results in a frame_xxxx.txt file for every successfully decoded
  barcode. This file contains the decoded barcode as 12-digit string (UPC-A
  format: 11 digits content + one check digit).

  Args:
    barcode_width(int): Width of the barcode.
    barcode_height(int): Height of the barcode.
    input_directory(string): The input directory from where the PNG frames are
      read.
    path_to_zxing(string): The path to Zxing.
  Return:
    (bool): True if the decoding went without errors.
  """
    jars = helper_functions.form_jars_string(path_to_zxing)
    command_line_decoder = 'com.google.zxing.client.j2se.CommandLineRunner'
    return helper_functions.perform_action_on_all_files(
        directory=input_directory,
        file_pattern='frame_',
        file_extension='png',
        start_number=1,
        action=_decode_barcode_in_file,
        barcode_width=barcode_width,
        barcode_height=barcode_height,
        jars=jars,
        command_line_decoder=command_line_decoder)
def convert_png_to_yuv_barcodes(input_directory='.', output_directory='.'):
  """Converts PNG barcodes to YUV barcode images.

  This function reads all the PNG files from the input directory which are in
  the format frame_xxxx.png, where xxxx is the number of the frame, starting
  from 0000. The frames should be consecutive numbers. The output YUV file is
  named frame_xxxx.yuv. The function uses ffmpeg to do the conversion.

  Args:
    input_directory(string): The input direcotry to read the PNG barcodes from.
    output_directory(string): The putput directory to write the YUV files to.
  Return:
    (bool): True if the conversion was without errors.
  """
  return helper_functions.perform_action_on_all_files(
      input_directory, 'barcode_', 'png', 0, _convert_to_yuv_and_delete,
      output_directory=output_directory, pattern='barcode_')
def combine_yuv_frames_into_one_file(output_file_name, input_directory='.'):
  """Combines several YUV frames into one YUV video file.

  The function combines the YUV frames from input_directory into one YUV video
  file. The frames should be named in the format frame_xxxx.yuv where xxxx
  stands for the frame number. The numbers have to be consecutive and start from
  0000. The YUV frames are removed after they have been added to the video.

  Args:
    output_file_name(string): The name of the file to produce.
    input_directory(string): The directory from which the YUV frames are read.
  Return:
    (bool): True if the frame stitching went OK.
  """
  output_file = open(output_file_name, "wb")
  success = helper_functions.perform_action_on_all_files(
      input_directory, 'barcode_', 'yuv', 0, _add_to_file_and_delete,
      output_file=output_file)
  output_file.close()
  return success
Exemplo n.º 7
0
def convert_png_to_yuv_barcodes(input_directory='.', output_directory='.'):
    """Converts PNG barcodes to YUV barcode images.

  This function reads all the PNG files from the input directory which are in
  the format frame_xxxx.png, where xxxx is the number of the frame, starting
  from 0000. The frames should be consecutive numbers. The output YUV file is
  named frame_xxxx.yuv. The function uses ffmpeg to do the conversion.

  Args:
    input_directory(string): The input direcotry to read the PNG barcodes from.
    output_directory(string): The putput directory to write the YUV files to.
  Return:
    (bool): True if the conversion was without errors.
  """
    return helper_functions.perform_action_on_all_files(
        input_directory,
        'barcode_',
        'png',
        0,
        _convert_to_yuv_and_delete,
        output_directory=output_directory,
        pattern='barcode_')
Exemplo n.º 8
0
def combine_yuv_frames_into_one_file(output_file_name, input_directory='.'):
    """Combines several YUV frames into one YUV video file.

  The function combines the YUV frames from input_directory into one YUV video
  file. The frames should be named in the format frame_xxxx.yuv where xxxx
  stands for the frame number. The numbers have to be consecutive and start from
  0000. The YUV frames are removed after they have been added to the video.

  Args:
    output_file_name(string): The name of the file to produce.
    input_directory(string): The directory from which the YUV frames are read.
  Return:
    (bool): True if the frame stitching went OK.
  """
    output_file = open(output_file_name, "wb")
    success = helper_functions.perform_action_on_all_files(
        input_directory,
        'barcode_',
        'yuv',
        0,
        _add_to_file_and_delete,
        output_file=output_file)
    output_file.close()
    return success