python-3.x - 没有收到检测到的汽车上的盒子

标签 python-3.x opencv classification

我正在尝试运行 Python 代码来检测图像中的汽车并在其周围绘制一个框。但不知何故,即使没有错误,我也没有得到盒子。我使用的代码如下:

画框的函数

def draw_boxes(img, bboxes, color=(0, 0, 255), thick=6):
    # Make a copy of the image
    imcopy = np.copy(img)
    # Iterate through the bounding boxes
    for bbox in bboxes:
        # Draw a rectangle given bbox coordinates
        cv2.rectangle(imcopy, bbox[0], bbox[1], color, thick)
    # Return the image copy with boxes drawn
    return imcopy

绘制框的函数

def search_windows(img, windows, model):
    #1) Create an empty list to receive positive detection windows
    #2) Iterate over all windows in the list
    test_images = []
    for window in windows:
        #3) Extract the test window from original image
        test_img = cv2.resize(img[window[0][1]:window[1][1], window[0][0]:window[1][0]], (64, 64))
        # Normalize image
        test_img = test_img/255
        # Predict and round the result
        test_images.append(test_img)
    test_images = np.array(test_images)

    prediction = np.around(model.predict(test_images))
    on_windows = [windows[i] for i in np.where(prediction==1)[0]]
    return on_windows

读取图像并使用函数绘制框

img = mpimg.imread(test_images[0])

detected_windows = search_windows(img, windows, model)                       

window_img = draw_boxes(img, detected_windows, color=(0, 255, 0), thick=3)                    

plt.imshow(window_img)

谢谢。

最佳答案

我找到了答案。我需要在代码中为我的 prediction 设置一个更好的限制。如果我将 0.40.5 设置为值,那么我会得到这些框,然后按照我的方式进行更好的预测。

关于python-3.x - 没有收到检测到的汽车上的盒子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44556910/

相关文章:

Python。从 Pandas 列中提取字符串的最后一位

python - 字符串检查函数 if else 断言

python -\b 正则表达式包括句点作为单词

linux - 让我的模块成为命令

c++ - 如何从 Mat 变量编辑/读取 OpenCv 中的像素值?

c++ - 使用 QImage::loadFromData 将 cv::mat 转换为 QImage

屏幕上相机输出的 OpenCV 延迟

matlab - 使用 matlab 中交叉验证的 Knn 分类器模型预测新数据集(测试数据)的标签

machine-learning - 决策树 split 策略

Java 朴素贝叶斯分类器评估