使用OpenCV的对象跟踪脚本中的慢速视频
Slow Video in Object Tracking Script using OpenCV
我在openCV和C++中编写了一个简短的例程,用网络摄像头跟踪对象。网络摄像头的配方很快,没有滞后,但在周末下班之前,我录制了一个典型的序列,用作周一之前的测试模板。这和相应的代码变化以某种方式使视频以非常慢的动作回放。这是打开"Test.avi"的代码,大约20秒长,而不是从网络摄像头上运行恒定的流:
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <vector>
using namespace cv;
using namespace std;
Mat drawBoundingBoxes (Mat canvasImage, vector<vector<Point>> contours);
int main(int argc, char** argv[])
{
Mat frame;
Mat back;
Mat fGround;
BackgroundSubtractorMOG2 bGround;
bGround.nmixtures = 3;
//bGround.nShadowDetection = 0;
bGround.fTau = .5;
VideoCapture cap;
cap.open("Test.avi");
if (!cap.isOpened())
{
cout << "Can't open video" << endl;
return -1;
}
vector<vector<Point>> contours;
namedWindow("video", CV_WINDOW_AUTOSIZE);
while (true)
{
static int count = 1;
cap >> frame;
if (frame.empty())
break;
bGround.operator()(frame, fGround);
bGround.getBackgroundImage(back);
erode(fGround, fGround, Mat(), Point(-1,-1), 2, BORDER_DEFAULT);
dilate(fGround, fGround, Mat(), Point(-1,-1), 10, BORDER_DEFAULT);
if (count > 50)
{
findContours(fGround, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
drawContours(frame, contours, -1, Scalar(239,255,0), 2);
drawBoundingBoxes(frame, contours);
}
imshow("video", frame);
if(waitKey(30) >= 0)
break;
count++;
}
return 0;
}
Mat drawBoundingBoxes (Mat canvasImage, vector<vector<Point>> contours)
{
vector<Rect> boundRect(contours.size());
for (int i=0; i<contours.size(); i++)
{
boundRect[i] = boundingRect(contours[i]);
rectangle(canvasImage, boundRect[i], Scalar(153,0,76), 2, 8, 0);
}
return canvasImage;
}
有什么想法吗?内存在哪里泄漏?谢谢,
-Tony
我相信您录制的视频的帧速率高于您的电脑实时处理的帧速。这不是网络摄像头的问题,因为它只是掉帧。您可以尝试减少waitKey()过程中的延迟,看看这是否有帮助。
相关文章:
- 光线跟踪器灯光反射错误
- 如何在c++中录制具有精确帧时间戳的视频
- 人脸跟踪arduino代码的优化
- 跟踪滚动条上的鼠标事件
- 如何在QT中的自定义视频小工具t上绘制矩形
- 如何使用新运算符跟踪在循环中创建的 QLabel
- 如何使用OpenCV-C++编写*.mp4视频?
- 开放 CV 中的动态内存分配,用于视频处理
- 错误:(-210:不支持的格式或格式组合)功能'create'中的硬件视频解码器不支持视频源
- C++:跟踪类对象
- 用于解析 win64 堆栈跟踪的命令行客户端(可以访问符号服务器)
- 跟踪日志中的T.11803()是什么意思?
- OpenCV QT,显示视频的帧(不使用while循环)
- FFmpeg——使用硬件加速进行视频解码
- 使用opencv在受控环境中进行视频跟踪的跟踪标记和跟踪算法选择
- 使用来自视频文件或网络摄像头的 Kinect 面部跟踪
- 在计算了一帧的SIFT或ORB之后,如何实时跟踪视频中的对象
- 使用 OpenGL 在视频中显示跟踪的对象
- Opencv对象跟踪和计数在视频帧中通过ROI的对象
- 使用OpenCV的对象跟踪脚本中的慢速视频