Chapter 4 Exercise 4 of learning opencv

Source: Internet
Author: User
First, add the following lib file to "project properties-" Configure properties-"linker-" input-"and add dependencies:
 opencv_imgproc220d.lib opencv_legacy220d.lib opencv_ml220d.lib opencv_core220d.lib opencv_highgui220d.lib opencv_video220d.lib 
// 4-4.cpp: defines the entry point of the console application. // # Include "stdafx. H "# include <opencv/cv. h> # include <opencv/highgui. h>/* int g_switch_value = 1; void switch_off_function () {printf ("Pause \ n") ;}; // You cocould do something with these functions toovoid switch_on_function () {printf ("Run \ n") ;}; void switch_callback (INT position) {If (position = 0) {switch_off_function () ;}else {switch_on_function ();}} int main () {iplimage * frame; cvcapture * g_capt Ure = NULL; If (! (G_capture = cvcreatefilecapture ("C: \ test. avi ") {printf (" failed to open % s \ n "," C: \ test. avi "); Return-1;} cvnamedwindow (" slidercontrol ", 1); cvcreatetrackbar (" Switch "," slidercontrol ", & g_switch_value, 1, switch_callback); While (1) {If (g_switch_value) {frame = cvqueryframe (g_capture); If (! Frame) break;} cvshowimage ("slidercontrol", frame); If (cvwaitkey (10) = 27) break;} cvreleasecapture (& g_capture); cvdestroywindow ("slidercontrol "); return (0);} */INT g_switch_value = 1; int g_slider_position = 0; cvcapture * g_capture = NULL; void ontrackbarslide (int pos) {cvsetcaptureproperty (g_capture, cv_cap_prop_pos_frames, pos);} void switch_callback (INT position) {If (position = 0) {PRI Ntf ("Pause \ n");} else {printf ("On \ n") ;}} int main () {cvnamedwindow ("test vedio slide", cv_window_autosize ); g_capture = cvcreatefilecapture ("C: \ test. avi "); int frames = (INT) cvgetcaptureproperty (g_capture, cv_cap_prop_frame_count); int framerate = (INT) cvgetcaptureproperty (g_capture, cv_cap_prop_fps); If (frames! = 0) {cvcreatetrackbar ("Switch", "test vedio slide", & g_switch_value, 1, switch_callback); cvcreatetrackbar ("position", "test vedio slide", & g_slider_position, frames, ontrackbarslide);} iplimage * frame; while (g_slider_position <frames) {If (g_switch_value = 1) {frame = cvqueryframe (g_capture); If (! Frame) break; cvshowimage ("test vedio slide", frame); char c = cvwaitkey (framerate); cvsettrackbarpos ("position", "test vedio slide", g_slider_position ); ontrackbarslide (g_slider_position); If (C = 27) break; g_slider_position ++;} else {If (cvwaitkey (10) = 27) break ;}} cvreleasecapture (& g_capture); cvdestroywindow ("test vedio slide ");}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.