Esempio n. 1
0
def main(argv):
  if FLAGS.output_type not in VALID_OUTPUT_TYPES:
    raise ValueError('output_type "%s" not in allowed types: %s' %
                     (FLAGS.output_type, VALID_OUTPUT_TYPES))

  # Exclude argv[0], which is the current binary.
  patterns = argv[1:]
  if not patterns:
    raise ValueError('PNG file glob(s) must be specified')
  input_paths = []
  for pattern in patterns:
    pattern_paths = file_io.get_matching_files(pattern)
    if not pattern_paths:
      raise ValueError('Pattern "%s" failed to match any files' % pattern)
    input_paths.extend(pattern_paths)

  start = time.time()
  output = run(
      input_paths,
      FLAGS.glyphs_saved_model,
      output_notesequence=FLAGS.output_type == 'NoteSequence')
  end = time.time()
  sys.stderr.write('OMR elapsed time: %.2f\n' % (end - start))

  if FLAGS.output_type == 'MusicXML':
    output_bytes = conversions.score_to_musicxml(output)
  else:
    if FLAGS.text_format:
      output_bytes = text_format.MessageToString(output).encode('utf-8')
    else:
      output_bytes = output.SerializeToString()
  file_io.write_string_to_file(FLAGS.output, output_bytes)
Esempio n. 2
0
 def testMusicXML(self):
   filename = os.path.join(resource_loader.get_data_files_path(),
                           'testdata/IMSLP00747-000.png')
   score = self.engine.run([filename])
   num_measures = sum(
       len(system.bar) - 1 for page in score.page for system in page.system)
   musicxml = etree.fromstring(conversions.score_to_musicxml(score))
   self.assertEqual(2, len(musicxml.findall('part')))
   self.assertEqual(num_measures,
                    len(musicxml.find('part[1]').findall('measure')))
Esempio n. 3
0
 def evaluate(self, ground_truth):
   expected = file_io.read_file_to_string(ground_truth.ground_truth_filename)
   score = self.omr.run(
       page_spec.filename for page_spec in ground_truth.page_spec)
   actual = conversions.score_to_musicxml(score)
   return musicxml.musicxml_similarity(actual, expected)