使用Python在少于10行代码中计数汽车数量

译者|Arno

来源|Medium

当你还是个孩子坐车旅行的时候,你玩过数经过的汽车的数目的游戏吗?

在这篇文章中,我将教你如何使用Python用c。
以下是运行文中代码的环境及相应的版本库:

  • Python版本 3.6.9
  • cvlib: 0.2.2
  • opencv-python: 4.1.1.26
  • tensorflow: 1.14.0
  • matplotlib: 3.1.1
  • Keras: 2.2.5

下面的代码用于导入所需的python库、从存储中读取图像、对图像执行目标检测、用边界框显示图像以及关于检测目标的标签、计算图像中的汽车数量并打印图像:

import cv2
import matplotlib.pyplot as plt
import cvlib as cv
from cvlib.object_detection import draw_bbox
'''
更多Python学习资料以及源码教程资料,可以在群1136201545免费获取
'''
im = cv2.imread('cars_4.jpeg')
bbox, label, conf = cv.detect_common_objects(im)
output_image = draw_bbox(im, bbox, label, conf)
plt.imshow(output_image)
plt.show()
print('Number of cars in the image is '+ str(label.count('car')))

在这里插入图片描述
此图像的输出:

Number of cars in the image is 29

在这里插入图片描述
此图像的输出:

Number of cars in the image is 22

在这里插入图片描述
此图像的输出:

Number of cars in the image is 25
  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值