【发布时间】:2017-10-21 03:14:20
【问题描述】:
我有一段视频记录路上的车流量,我想用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;
}
此代码可以读取视频并在此视频上画两行。我可以为这个源代码添加什么用于检测汽车并计算这些汽车的行
【问题讨论】:
-
“我已经解决了琐碎的部分。请帮我解决非琐碎的部分,如此非琐碎的书籍已经单独写了关于这个主题的书籍。”不,抱歉,这不是 Stack Overflow 存在的原因。这是一个针对特定编程问题的问答网站。请使用tour 并查看How to Ask。
-
再一次,看起来你甚至没有解决琐碎的部分,但有someone else do it for you。鉴于您目前的技能,这个项目可能方式遥不可及。
-
这个answer 可能会给你一些关于如何解决这个问题的灵感。将该代码移植到 C++ 应该不难——事实上它应该提供一些急需的练习 :)
-
This 开源项目可能有用,它使用blob检测器来检测、跟踪和计数车辆。
标签: c++ opencv visual-c++