裁剪和调整图像大小以训练支持向量机

2024-06-25 22:59:43 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

提前谢谢


Tags: 项目对象图像githubcom示例opencvdetection
1条回答
网友
1楼 · 发布于 2024-06-25 22:59:43
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)

相关问题 更多 >