首页 > 解决方案 > 裁剪和调整图像大小以训练支持向量机

问题描述

我使用 OpenCV(Python) 使用 HOG+SVM 检测同一类的对象。我正在按照 Udacitiy-Project 的示例来检测车辆:访问https://github.com/TusharChugh/Vehicle-Detection-HOG/blob/master/src/vehicle-detection.ipynb。在这个例子中,他们使用了一个准备好的车辆数据集,其中包含裁剪和调整大小的图像。

我在问是否有人有裁剪和调整图像大小的想法,其中包含同一图像中的对象和背景?或者如何在上面提到的示例中标记图像并将它们集成?我使用 Windows 10 和 Python 3.6。

提前致谢

标签: pythonopencvsvm

解决方案


Read a negative input and convert to a Histogram of oriented gradients (HOG) 
    samples = []
    labels = []   
    for filename in glob.glob(os.path.join(negative_path, '*.jpg')):
        img = cv2.imread(filename, 1) 
        hist = hog(img)
        samples.append(hist)
        labels.append(1)

For the positive samples use the same code as above but with:
    labels.append(0)

then just train the svm modell with:
    svm.train(samples, cv2.ml.ROW_SAMPLE, labels)

推荐阅读