feature_extractor.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:traffic-light-detection 作者: ranveeraggarwal 项目源码 文件源码
def extract_features():
    pos_img_path = positive_images_path
    neg_img_path = negative_images_path

    pos_feat_path = positive_features_path
    neg_feat_path = negative_features_path

    if not os.path.isdir(pos_feat_path):
        os.makedirs(pos_feat_path)

    if not os.path.isdir(neg_feat_path):
        os.makedirs(neg_feat_path)

    print "Extracting positive features"
    progress = 0.0
    for im_path in glob.glob(os.path.join(pos_img_path, "*")):
        im = imread(im_path)
        im_ycbcr = cv2.cvtColor(im, cv2.COLOR_RGB2YCR_CB)
        im = cv2.split(im_ycbcr)[0]
        feature_vector = hog(image=im, orientations=9, pixels_per_cell=(8, 8), cells_per_block=(3, 3), visualise=False)
        feature_name = os.path.split(im_path)[1].split(".")[0] + ".feat"
        feature_path = os.path.join(pos_feat_path, feature_name)
        joblib.dump(feature_vector, feature_path)
        progress += 1.0
        update_progress(progress/float(len(glob.glob(os.path.join(pos_img_path, "*")))))

    print "Extracting negative features"
    progress = 0.0
    for im_path in glob.glob(os.path.join(neg_img_path, "*")):
        im = imread(im_path)
        im_ycbcr = cv2.cvtColor(im, cv2.COLOR_RGB2YCR_CB)
        im = cv2.split(im_ycbcr)[0]
        feature_vector = hog(image=im, orientations=9, pixels_per_cell=(8, 8), cells_per_block=(3, 3), visualise=False)
        feature_name = os.path.split(im_path)[1].split(".")[0] + ".feat"
        feature_path = os.path.join(neg_feat_path, feature_name)
        joblib.dump(feature_vector, feature_path)
        progress += 1.0
        update_progress(progress/float(len(glob.glob(os.path.join(neg_img_path, "*")))))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号