资源简介
模板:基于OpenCV的车辆速度检测c++,可以自行套用,有需要可以账号关注留言
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
double get_speed(cv::Mat& frame vector& contourPoint2f centerfloat radiusvector prevContourCentersdouble fps)
{
int meters = 30;
int maxSpeed = 100;
if(center.x>5&¢er.x<200){
for(size_t i = 0; i < prevContourCenters.size(); i++ )
{
if(prevContourCenters[i].x double diff = center.x-prevContourCenters[i].x;
cv::Point xy;
int fontFace = 3;
double fontScale = 0.5;
int thickness = 1.8;
Point textOrg(center.x-20center.y-radius-5);
String str2 = “ km/h“;
double speed = diff*fps/300*meters*3.6;
if(speed>100) speed=101;
std::stringstream strSpeed;
strSpeed << speed;
if(speed>maxSpeed){
putText(frame strSpeed.str()+str2 textOrg fontFace fontScale Scalar(02550) thickness5);
imwrite(“/home/igrosso/www/inna_project_new/untitled/violators/image.jpg“frame);
} else {
putText(frame strSpeed.str()+str2 textOrg fontFace fontScale Scalar(02550) thickness5);
}
return speed;
}
}
}
};
int main()
{
int count;
double area ar;
Mat frame fore img prevImg temp gray vehicle_ROI img_temp;
VideoCapture cap(“/home/igrosso/www/inna_project_new/untitled/data/video.avi“);
BackgroundSubtractorMOG2 bg(500 25 false);
vector > contours;
vector prevContoursCenters;
vector tempContoursCenters;
vector cars;
namedWindow(“frame“);
cap >> img_temp;
cvtColor(img_temp gray CV_BGR2GRAY);
gray.convertTo(temp CV_8U);
bilateralFilter(temp prevImg 5 20 20);
// start and end times
time_t start end;
// fps calculated using number of frames / seconds
double fps;
// frame counter
int counter = 0;
// floating point seconds elapsed since start
double sec;
// start the clock
time(&start);
while(true)
{
count=0;
cap >> frame;
cvtColor(frame gray CV_BGR2GRAY);
gray.convertTo(temp CV_8U);
bilateralFilter(temp img 5 20 20);
bg.operator()(imgfore);
erode(foreforeMat());
dilate(foreforeMat());
findContours(forecontoursCV_RETR_EXTERNALCV_CHAIN_APPROX_SIMPLE);
vector >
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-04-13 21:14 模板:基于OpenCV的车辆速度检测\data\
文件 8192 2018-04-09 21:13 模板:基于OpenCV的车辆速度检测\data\Thumbs.db
文件 1049784 2015-12-19 22:55 模板:基于OpenCV的车辆速度检测\data\video.avi
文件 6008 2015-12-19 22:55 模板:基于OpenCV的车辆速度检测\main.cpp
目录 0 2018-04-13 21:14 模板:基于OpenCV的车辆速度检测\
- 上一篇:RDA5820技术资料参考源码
- 下一篇:C语言socket实现文件
评论
共有 条评论