【发布时间】: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进行验证 -
我对@987654325@ 设置的限制非常高。我需要将
prediction的条件设置为0.4或0.5附近的某个位置,然后使用它。
标签: python-3.x opencv classification