Opencv 入门三(视频滑动条窗口)

发布时间:2023年12月20日

视频滑动条窗口源码如下:

#include "opencv2\highgui\highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"?
#include <iostream>?
#include <fstream>?
using namespace std;
int g_slider_position = 0;? ? ? // 滑动条的位置
int g_run = 1, g_dontset = 0; //start out in single step mode
cv::VideoCapture g_cap;
void onTrackbarSlide(int pos, void*) {
? ? g_cap.set(cv::CAP_PROP_POS_FRAMES, pos);? ?//真正使进度条移动到我们希望的位置
? ? if (!g_dontset)
? ? ? ? g_run = 1;
? ? g_dontset = 0;
}

int main(int argc, char** argv)
{
? ? cv::namedWindow("Example2_4", cv::WINDOW_AUTOSIZE);
? ? g_cap.open(string(argv[1]));
? ? int frames = (int)g_cap.get(cv::CAP_PROP_FRAME_COUNT);
? ? int tmpw = (int)g_cap.get(cv::CAP_PROP_FRAME_WIDTH);
? ? int tmph = (int)g_cap.get(cv::CAP_PROP_FRAME_HEIGHT);
? ? cout << "Video has "<<frames<<" frames of dimensions("<<tmpw<<", "<<tmph <<")."<<endl;
? ? cv::createTrackbar("Position", "Example2_4", &g_slider_position, frames, onTrackbarSlide);
? ??
? ? cv::Mat frame;
? ? for (;;) {
? ? ? ? if (g_run != 0)
? ? ? ? {
? ? ? ? ? ? g_cap >> frame;
? ? ? ? ? ? if (frame.empty())break;
? ? ? ? ? ? int current_pos = (int)g_cap.get(cv::CAP_PROP_POS_FRAMES);
? ? ? ? ? ? g_dontset = 1;
? ? ? ? ? ? cv::setTrackbarPos("Position", "Example2_4", current_pos);
? ? ? ? ? ? cv::imshow("Example2_4", frame);
? ? ? ? ? ? g_run -= 1;
? ? ? ? }

? ? ? ? char c = (char)cv::waitKey(10);
? ? ? ? if (c == 's')//single step
? ? ? ? {
? ? ? ? ? ? g_run = 1;
? ? ? ? ? ? cout << "Single step,run =" << g_run << endl;
? ? ? ? }
? ? ? ? if (c == 'r')//run mode
? ? ? ? {
? ? ? ? ? ? g_run = -1; cout << "Run mode,run=" << g_run << endl;
? ? ? ? }
? ? ? ? if (c == 27)? // Esc 按键
? ? ? ? ? ? break;
? ? }
? ??
? ? return 0;
}

?

文章来源:https://blog.csdn.net/EveryDayOneHour/article/details/135104087
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。