opencv在视频中绘制直线与点
使用opencv读取视频并在视频画线画点
#include<iostream>
#include<opencv2\opencv.hpp>
#include <opencv2\dnn.hpp>
using namespace cv;
using namespace std;
void main(){
VideoCapture cap;
cap.open("2.MP4");
int width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
int height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
int frameRate = cap.get(CV_CAP_PROP_FPS);//帧率
int totalFrames = cap.get(CV_CAP_PROP_FRAME_COUNT);//总帧数
cout << "视频宽度=" << width << endl;
cout << "视频高度=" << height << endl;
cout << "视频总帧数=" << totalFrames << endl;
cout << "帧率=" << frameRate << endl;
初始定义
cap >> frame;
cv::Point point;
point.x = width / 2;
point.y = height / 2;
cv::circle(frame, point, 2, cv::Scalar(0, 0, 255));
点的绘制
cv::Point start = cv::Point(width / 2 - 100,height/2);
cv::Point end = cv::Point(width / 2 + 100, height / 2);
cv::line(frame, start, end, cv::Scalar(0, 0, 255));
cv::Point start1 = cv::Point(width / 2, height / 2-100);
cv::Point end1 = cv::Point(width / 2, height / 2+100);
cv::line(frame, start1, end1, cv::Scalar(0, 0, 255));
直线绘制
if (frame.empty())
{
break;
}
imshow("video", frame);
waitKey(30);
显示
版权声明:本文为weixin_46096032原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。