示例#1
0
def createSamples(classifier_yaml, output_dir):
    # numPos, _, _ = requiredImageCounts(classifier_yaml)

    samples_vec_fname = '{}/samples.vec'.format(output_dir)
    pos_info_fname = '{}/positive.txt'.format(output_dir)

    numPos = 0
    tmp_info = utils.load_opencv_bounding_box_info(pos_info_fname)
    for img_path, bboxes in tmp_info.iteritems():
        num = len(bboxes)
        numPos += num

    samplesCommand = [ 'opencv_createsamples'
        , '-info', pos_info_fname
        , '-vec',  samples_vec_fname
        , '-num',  str(numPos)
        , '-w',    classifier_yaml['training']['cascade']['sampleSize'][0]
        , '-h',    classifier_yaml['training']['cascade']['sampleSize'][1]
        ]

    print ' '.join(samplesCommand)

    try:
        with open('{}/output_create_samples.txt'.format(output_dir), 'w') as cmd_output_file:
            cmd_ouptut = subprocess.check_call(samplesCommand, stdout=cmd_output_file, stderr=subprocess.STDOUT, cwd='.', bufsize=1)
    except subprocess.CalledProcessError as e:
        print 'ERROR:'
        print '\te.returncode: {}'.format(e.returncode)
        print '\te.cmd: {}'.format(e.cmd)
        print '\te.output: {}'.format(e.output)
        sys.exit(0)
def createSamples(classifier_yaml, output_dir):
    # numPos, _, _ = requiredImageCounts(classifier_yaml)

    samples_vec_fname = '{}/samples.vec'.format(output_dir)
    pos_info_fname = '{}/positive.txt'.format(output_dir)

    numPos = 0
    tmp_info = utils.load_opencv_bounding_box_info(pos_info_fname)
    for img_path, bboxes in tmp_info.iteritems():
        num = len(bboxes)
        numPos += num

    samplesCommand = [
        'opencv_createsamples', '-info', pos_info_fname, '-vec',
        samples_vec_fname, '-num',
        str(numPos), '-w',
        classifier_yaml['training']['cascade']['sampleSize'][0], '-h',
        classifier_yaml['training']['cascade']['sampleSize'][1]
    ]

    print ' '.join(samplesCommand)

    try:
        with open('{}/output_create_samples.txt'.format(output_dir),
                  'w') as cmd_output_file:
            cmd_ouptut = subprocess.check_call(samplesCommand,
                                               stdout=cmd_output_file,
                                               stderr=subprocess.STDOUT,
                                               cwd='.',
                                               bufsize=1)
    except subprocess.CalledProcessError as e:
        print 'ERROR:'
        print '\te.returncode: {}'.format(e.returncode)
        print '\te.cmd: {}'.format(e.cmd)
        print '\te.output: {}'.format(e.output)
        sys.exit(0)
示例#3
0
 def load_opencv_bounding_box_info(self, bbinfo_file):
     self.bbinfo_map = utils.load_opencv_bounding_box_info(bbinfo_file)
示例#4
0
 def load_opencv_bounding_box_info(self, bbinfo_file):
     self.bbinfo_map = utils.load_opencv_bounding_box_info(bbinfo_file)