使用Python 训练OpenCV Cascade分类器 - 4

创建positive和negative样本。

import cv2
import numpy as np
import os
def create_pos_n_neg():
    for file_type in ['neg']:
        
        for img in os.listdir(file_type):

            if file_type == 'pos':
                line = file_type+'/'+img+' 1 0 0 50 50\n'
                with open('info.dat','a') as f:
                    f.write(line)
            elif file_type == 'neg':
                line = file_type+'/'+img+'\n'
                with open('bg.txt','a') as f:
                    f.write(line)
                    
create_pos_n_neg();

 

你可能感兴趣的:(Python,计算机视觉)