【问题标题】:Not getting the box on detected car没有在检测到的汽车上拿到盒子
【发布时间】:2017-11-17 07:44:09
【问题描述】:

我正在尝试运行 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)

非常感谢。

【问题讨论】:

  • 可能是没有检测到车,您可以通过print prediction进行验证
  • 我对@9​​87654325@ 设置的限制非常高。我需要将prediction 的条件设置为0.40.5 附近的某个位置,然后使用它。

标签: python-3.x opencv classification


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-21
    • 2020-08-09
    • 1970-01-01
    • 1970-01-01
    • 2017-10-21
    • 2013-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多