1 Star 0 Fork 0

lewlovehow / Learning-OpenCV-3_examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
example_09-03.cpp 1.95 KB
一键复制 编辑 原始数据 按行查看 历史
Gary Bradski 提交于 2017-07-01 06:56 . fixed a bunch of printouts
//Example 9-3. Using a trackbar to create a “switch” that the user can turn on and off;
//this program plays a video and uses the switch to create a pause functionality
//
// An example program in which the user can draw boxes on the screen.
//
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
//
// Using a trackbar to create a "switch" that the user can turn on and off.
// We make this value global so everyone can see it.
//
int g_switch_value = 1;
void switch_off_function() { cout << "Pause\n"; }; //YOU COULD DO MORE
void switch_on_function() { cout << "Run\n"; };
// This will be the callback that we give to the trackbar.
//
void switch_callback( int position, void* ) {
if( position == 0 ) {
switch_off_function();
} else {
switch_on_function();
}
}
void help(char ** argv) {
cout << "Example 9-3. Using a trackbar to create a “switch” that the user can turn on and off"
<< "\n this program plays a video and uses the switch to create a pause functionality."
<< "\n\nCall:\n" << argv[0] << " <path/video_file>"
<< "\n\nShows putting a pause button in a video; Esc to quit\n" << endl;
}
int main( int argc, char** argv ) {
cv::Mat frame; // To hold movie images
cv::VideoCapture g_capture;
help(argv);
if( argc < 2 || !g_capture.open( argv[1] ) ){
cout << "Failed to open " << argv[1] << " video file\n" << endl;
return -1;
}
// Name the main window
//
cv::namedWindow( "Example", 1 );
// Create the trackbar. We give it a name,
// and tell it the name of the parent window.
//
cv::createTrackbar(
"Switch",
"Example",
&g_switch_value,
1,
switch_callback
);
// This will cause OpenCV to idle until
// someone hits the Esc key.
//
for(;;) {
if( g_switch_value ) {
g_capture >> frame;
if( frame.empty() ) break;
cv::imshow( "Example", frame);
}
if( cv::waitKey(10)==27 ) break; //esc
}
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/lewlovehow/Learning-OpenCV-3_examples.git
git@gitee.com:lewlovehow/Learning-OpenCV-3_examples.git
lewlovehow
Learning-OpenCV-3_examples
Learning-OpenCV-3_examples
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891