汽车的检测和计数 opencv3.0.0 c++.

Detection and counting of cars opencv3.0.0 c++

本文关键字:opencv3 c++ 检测 汽车      更新时间:2023-10-16

我有一个记录道路上汽车交通的视频,我想用opencv 3.0.0和c ++对这些汽车进行检测和计数,这里有以下源代码

#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<iostream>
#include<conio.h>           // it may be necessary to change or remove this line if not using Windows
   int main(int argc, char** argv)
    {
        cv::VideoCapture capVideo;
        capVideo.open("CarsDrivingUnderBridge.mp4");
     if (!capVideo.isOpened())
            return -1;
        Mat frame;
        /// Create Window
        namedWindow("Result", 1);
        while (true) {
            //grab and retrieve each frames of the video sequentially 
            cap >> frame;
            //draw a line onto the frame
            line(frame, Point(0, frame.rows / 2), Point(frame.cols, frame.rows / 2), Scalar(0), 3);
            //display the result
            imshow("Result", frame);
            line(frame, Point(0, frame.rows / 8), Point(frame.cols, frame.rows / 8), Scalar(0), 3);
             imshow("Result", frame);
            //wait some time for the frame to render
            waitKey(30);
        }
        return 0;
    }

此代码可以读取视频并在此视频上绘制两行。 我可以为此源代码添加什么 用于检测汽车并计算这些汽车的线

要检测汽车,您可以使用斑点检测器。定义最小和最大大小,并在 Blob 通过特定(需要定义该(行时增加计数器。

您还可以在互联网上搜索"人流量统计器",您会发现其他读数

这是我解决这个问题的方法,但在 python 中 https://medium.com/@a.nikishaev/tutorial-making-road-traffic-counting-app-based-on-computer-vision-and-opencv-166937911660