博客
关于我
Python OpenCV高速公路道路汽车车辆摄像头视频侦测检测识别统计数量
阅读量:356 次
发布时间:2019-03-04

本文共 2955 字,大约阅读时间需要 9 分钟。

Python OpenCV高速公路道路汽车车辆侦测检测识别统计数量

如需安装运行环境或远程调试,可加QQ905733049由专业技术人员远程协助!

运行结果如下:

运行主要代码如下:

import cv2import numpy as npimport timecap=cv2.VideoCapture("video.mp4")fgbg=cv2.createBack(detectShadows=False,history=200,varThreshold = 90)kernalOp = np.ones((3,3),np.uint8)kernalOp2 = np.ones((5,5),np.uint8)kernalCl = np.ones((11,11),np.uint8)font = cv2.FONT_HERSHEY_SIMPLEXcars = []max_p_age = 5pid = 1cnt_up=0cnt_down=0print("Car counting and classification")line_up=400line_down=250up_limit=230down_limit=int(4.5*(500/5))while(cap.isOpened()):    ret,frame=cap.read()    frame=cv2.resize(frame,(900,500))    for i in cars:        i.age_one()    fgmask=fgbg.apply(frame)        mask,countours0,hierarchy=cv2.findContours(mask,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)        for cnt in countours0:            area=cv2.contourArea(cnt)            print(area)            if area>300:                m=cv2.moments(cnt)                cx=int(m['m10']/m['m00'])                cy=int(m['m01']/m['m00'])                x,y,w,h=cv2.boundingRect(cnt)                new=True                if cy in range(up_limit,down_limit):                    for i in cars:                        if abs(x - i.getX()) <= w and abs(y - i.getY()) <= h:                            new = False                            i.updateCoords(cx, cy)                            if i.going_UP(line_down,line_up)==True:                                cnt_up+=1                            elif i.going_DOWN(line_down,line_up)==True:                                cnt_down+=1                            break                    if new==True:                        p=vehicles.Car(pid,cx,cy,max_p_age)                        cars.append(p)                        pid+1                cv2.circle(frame, (cx, cy), 2, (0, 0, 255), -1)        for i in cars:            cv2.putText(frame, str(i.getId()), (i.getX(), i.getY()), font, 0.3, (255,255,0), 1, cv2.LINE_AA)            if line_down+20<= i.getY() <= line_up-20:               a = (h + (.74*w)- 100)               if a >= 0:                     cv2.putText(frame, "Truck", (i.getX(), i.getY()), font, 1, (0,0,255), 2, cv2.LINE_AA)               else:                     cv2.putText(frame, "car", (i.getX(), i.getY()), font, 1, (0,0,255), 2, cv2.LINE_AA)        str_up='UP: '+str(cnt_up)        str_down='DOWN: '+str(cnt_down)        frame=cv2.line(frame,(0,line_up),(900,line_up),(0,0,255),3,8)        frame=cv2.line(frame,(0,up_limit),(900,up_limit),(0,0,0),1,8)        frame=cv2.line(frame,(0,down_limit),(900,down_limit),(255,255,0),1,8)        frame = cv2.line(frame, (0, line_down), (900, line_down), (255, 0,0), 3, 8)        cv2.imshow('Frame',frame)        if cv2.waitKey(1)&0xff==ord('q'):            break    else:        breakcap.release()cv2.destroyAllWindows()

运行结果如下:

C++学习参考实例

C++实现图形界面五子棋游戏源码:

C++实现图形界面五子棋游戏源码2:

C++ OpenCV相片视频人脸识别统计人数:

VS2017+PCL开发环境配置:

VS2017+Qt+PCL点云开发环境配置:

C++ OpenCV汽车检测障碍物与测距:

Windows VS2017安装配置PCL点云库:

 

转载地址:http://zxkr.baihongyu.com/

你可能感兴趣的文章
mysql中出现Incorrect DECIMAL value: '0' for column '' at row -1错误解决方案
查看>>
mysql中出现Unit mysql.service could not be found 的解决方法
查看>>
mysql中出现update-alternatives: 错误: 候选项路径 /etc/mysql/mysql.cnf 不存在 dpkg: 处理软件包 mysql-server-8.0的解决方法(全)
查看>>
Mysql中各类锁的机制图文详细解析(全)
查看>>
MySQL中地理位置数据扩展geometry的使用心得
查看>>
Mysql中存储引擎简介、修改、查询、选择
查看>>
Mysql中存储过程、存储函数、自定义函数、变量、流程控制语句、光标/游标、定义条件和处理程序的使用示例
查看>>
mysql中实现rownum,对结果进行排序
查看>>
mysql中对于数据库的基本操作
查看>>
Mysql中常用函数的使用示例
查看>>
MySql中怎样使用case-when实现判断查询结果返回
查看>>
Mysql中怎样使用update更新某列的数据减去指定值
查看>>
Mysql中怎样设置指定ip远程访问连接
查看>>
mysql中数据表的基本操作很难嘛,由这个实验来带你从头走一遍
查看>>
Mysql中文乱码问题完美解决方案
查看>>
mysql中的 +号 和 CONCAT(str1,str2,...)
查看>>
Mysql中的 IFNULL 函数的详解
查看>>
mysql中的collate关键字是什么意思?
查看>>
MySql中的concat()相关函数
查看>>
mysql中的concat函数,concat_ws函数,concat_group函数之间的区别
查看>>