Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: webrtc/tools/barcode_tools/barcode_decoder.py

Issue 2741733003: Reland of PyLint fixes for tools-webrtc and webrtc/tools (Closed)
Patch Set: Rebased Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/tools/barcode_tools/barcode_decoder.py
diff --git a/webrtc/tools/barcode_tools/barcode_decoder.py b/webrtc/tools/barcode_tools/barcode_decoder.py
index e615fa83b83c55a2a4da1e11e914eb94fb9cc494..b89d6a41340c9fd0f6b23a092b4798dc74c87051 100755
--- a/webrtc/tools/barcode_tools/barcode_decoder.py
+++ b/webrtc/tools/barcode_tools/barcode_decoder.py
@@ -21,7 +21,7 @@ import helper_functions
sys.stderr = sys.stdout
-def convert_yuv_to_png_files(yuv_file_name, yuv_frame_width, yuv_frame_height,
+def ConvertYuvToPngFiles(yuv_file_name, yuv_frame_width, yuv_frame_height,
output_directory, ffmpeg_path):
"""Converts a YUV video file into PNG frames.
@@ -50,7 +50,7 @@ def convert_yuv_to_png_files(yuv_file_name, yuv_frame_width, yuv_frame_height,
try:
print 'Converting YUV file to PNG images (may take a while)...'
print ' '.join(command)
- helper_functions.run_shell_command(
+ helper_functions.RunShellCommand(
command, fail_msg='Error during YUV to PNG conversion')
except helper_functions.HelperError, err:
print 'Error executing command: %s. Error: %s' % (command, err)
@@ -61,7 +61,7 @@ def convert_yuv_to_png_files(yuv_file_name, yuv_frame_width, yuv_frame_height,
return True
-def decode_frames(input_directory, zxing_path):
+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
@@ -83,13 +83,13 @@ def decode_frames(input_directory, zxing_path):
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(
+ return helper_functions.PerformActionOnAllFiles(
directory=input_directory, file_pattern='frame_',
- file_extension='png', start_number=1, action=_decode_barcode_in_file,
+ file_extension='png', start_number=1, action=_DecodeBarcodeInFile,
command_line_decoder=zxing_path)
-def _decode_barcode_in_file(file_name, command_line_decoder):
+def _DecodeBarcodeInFile(file_name, command_line_decoder):
"""Decodes the barcode in the upper left corner of a PNG file.
Args:
@@ -101,7 +101,7 @@ def _decode_barcode_in_file(file_name, command_line_decoder):
"""
command = [command_line_decoder, '--try-harder', '--dump-raw', file_name]
try:
- out = helper_functions.run_shell_command(
+ out = helper_functions.RunShellCommand(
command, fail_msg='Error during decoding of %s' % file_name)
text_file = open('%s.txt' % file_name[:-4], 'w')
text_file.write(out)
@@ -116,7 +116,7 @@ def _decode_barcode_in_file(file_name, command_line_decoder):
return True
-def _generate_stats_file(stats_file_name, input_directory='.'):
+def _GenerateStatsFile(stats_file_name, input_directory='.'):
"""Generate statistics file.
The function generates a statistics file. The contents of the file are in the
@@ -128,19 +128,19 @@ def _generate_stats_file(stats_file_name, input_directory='.'):
stats_file = open(stats_file_name, 'w')
print 'Generating stats file: %s' % stats_file_name
- for i in range(1, _count_frames_in(input_directory=input_directory) + 1):
- frame_number = helper_functions.zero_pad(i)
+ for i in range(1, _CountFramesIn(input_directory=input_directory) + 1):
+ frame_number = helper_functions.ZeroPad(i)
barcode_file_name = file_prefix + frame_number + '.txt'
png_frame = file_prefix + frame_number + '.png'
- entry_frame_number = helper_functions.zero_pad(i-1)
+ entry_frame_number = helper_functions.ZeroPad(i-1)
entry = 'frame_' + entry_frame_number + ' '
if os.path.isfile(barcode_file_name):
- barcode = _read_barcode_from_text_file(barcode_file_name)
+ barcode = _ReadBarcodeFromTextFile(barcode_file_name)
os.remove(barcode_file_name)
- if _check_barcode(barcode):
- entry += (helper_functions.zero_pad(int(barcode[0:11])) + '\n')
+ if _CheckBarcode(barcode):
+ entry += (helper_functions.ZeroPad(int(barcode[0:11])) + '\n')
else:
entry += 'Barcode error\n' # Barcode is wrongly detected.
else: # Barcode file doesn't exist.
@@ -152,7 +152,7 @@ def _generate_stats_file(stats_file_name, input_directory='.'):
stats_file.close()
-def _read_barcode_from_text_file(barcode_file_name):
+def _ReadBarcodeFromTextFile(barcode_file_name):
"""Reads the decoded barcode for a .txt file.
Args:
@@ -166,7 +166,7 @@ def _read_barcode_from_text_file(barcode_file_name):
return barcode
-def _check_barcode(barcode):
+def _CheckBarcode(barcode):
"""Check weather the UPC-A barcode was decoded correctly.
This function calculates the check digit of the provided barcode and compares
@@ -200,7 +200,7 @@ def _check_barcode(barcode):
return dsum == int(barcode[11])
-def _count_frames_in(input_directory='.'):
+def _CountFramesIn(input_directory='.'):
"""Calculates the number of frames in the input directory.
The function calculates the number of frames in the input directory. The
@@ -217,7 +217,7 @@ def _count_frames_in(input_directory='.'):
num = 1
while file_exists:
- file_name = (file_prefix + helper_functions.zero_pad(num) + '.png')
+ file_name = (file_prefix + helper_functions.ZeroPad(num) + '.png')
if os.path.isfile(file_name):
num += 1
else:
@@ -225,7 +225,7 @@ def _count_frames_in(input_directory='.'):
return num - 1
-def _parse_args():
+def _ParseArgs():
"""Registers the command-line options."""
usage = "usage: %prog [options]"
parser = optparse.OptionParser(usage=usage)
@@ -256,7 +256,7 @@ def _parse_args():
return options
-def _main():
+def main():
"""The main function.
A simple invocation is:
@@ -265,27 +265,27 @@ def _main():
--yuv_frame_width=640 --yuv_frame_height=480
--stats_file=<path_and_name_to_stats_file>
"""
- options = _parse_args()
+ options = _ParseArgs()
# Convert the overlaid YUV video into a set of PNG frames.
- if not convert_yuv_to_png_files(options.yuv_file, options.yuv_frame_width,
- options.yuv_frame_height,
- output_directory=options.png_working_dir,
- ffmpeg_path=options.ffmpeg_path):
+ if not ConvertYuvToPngFiles(options.yuv_file, options.yuv_frame_width,
+ options.yuv_frame_height,
+ output_directory=options.png_working_dir,
+ ffmpeg_path=options.ffmpeg_path):
print 'An error occurred converting from YUV to PNG frames.'
return -1
# Decode the barcodes from the PNG frames.
- if not decode_frames(input_directory=options.png_working_dir,
- zxing_path=options.zxing_path):
+ if not DecodeFrames(input_directory=options.png_working_dir,
+ zxing_path=options.zxing_path):
print 'An error occurred decoding barcodes from PNG frames.'
return -2
# Generate statistics file.
- _generate_stats_file(options.stats_file,
- input_directory=options.png_working_dir)
+ _GenerateStatsFile(options.stats_file,
+ input_directory=options.png_working_dir)
print 'Completed barcode decoding.'
return 0
if __name__ == '__main__':
- sys.exit(_main())
+ sys.exit(main())
« no previous file with comments | « webrtc/examples/androidtests/video_quality_loopback_test.py ('k') | webrtc/tools/barcode_tools/barcode_encoder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698