代码拉取完成,页面将自动刷新
//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;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。