Example #1
0
def DecodeFrames(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.PerformActionOnAllFiles(
        directory=input_directory,
        file_pattern='frame_',
        file_extension='png',
        start_number=1,
        action=_DecodeBarcodeInFile,
        command_line_decoder=zxing_path)
Example #2
0
def ConvertPngToYuvBarcodes(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.PerformActionOnAllFiles(
        input_directory,
        'barcode_',
        'png',
        0,
        _ConvertToYuvAndDelete,
        output_directory=output_directory,
        pattern='barcode_')
Example #3
0
def CombineYuvFramesIntoOneFile(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.PerformActionOnAllFiles(input_directory,
                                                       'barcode_',
                                                       'yuv',
                                                       0,
                                                       _AddToFileAndDelete,
                                                       output_file=output_file)
    output_file.close()
    return success