#include<opencv2\opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
#define WINDOW_NAME "video"
#define LEFT_NAME "left"
#define RIGHT_NAME "right"
int g_frame=1;
int g_max_frame;
bool flag = false;
void on_Trackbar(int, void*)
{
flag = true;
}
int main()
{
Mat frame, left, right;
VideoCapture capture;
capture.open("D:\\加油站车位检测\\gas_station_all_func_video_20161207_入口拥堵加入vibe_开始占用就输出占用\\gas_station_all_func_video\\ch04.mp4");
namedWindow(WINDOW_NAME, 1);
namedWindow(LEFT_NAME, 1);
namedWindow(RIGHT_NAME, 1);
g_max_frame = capture.get(CV_CAP_PROP_FRAME_COUNT);//总共的视频帧
char TrackbarName[50];
sprintf(TrackbarName, "帧数%d", g_max_frame);
createTrackbar(TrackbarName, WINDOW_NAME, &g_frame, g_max_frame, on_Trackbar);//设置滑动条拖动的回调函数
if (!capture.isOpened())
{
cout << "No camera or video input!\n" << endl;
return -1;
}
while (1)
{
capture >> frame;
if (frame.empty())
return 0;
resize(frame, frame, Size(960, 600));
frame.copyTo(left);
frame.copyTo(right);
left = left((Rect(80, 150, 150, 150)));
right = right(Rect(582, 112, 150, 150));
imshow(WINDOW_NAME, frame);
imshow(LEFT_NAME, left);
imshow(RIGHT_NAME, right);
cvWaitKey(20);
if (flag)
{
capture.set(CV_CAP_PROP_POS_FRAMES, g_frame);
flag = false;
}
}
}
OPENCV获取相应区域,加滚动条C++版
最新推荐文章于 2024-02-05 17:20:40 发布