Convert from: watermark (.jpg,.bmp), and save the continuous image as a video for Demonstration:
Paste the Code directly. After learning opencv for a week, you can definitely understand it:
# Include <stdlib. h> # include <stdio. h> # include <math. h> # include <cv. h> # include
// Initialize a video file catcher cvcapture * capture = cvcapturefromavi (filename );
// Obtain the video information cvqueryframe (capture); int frameh = (INT) cvgetcaptureproperty (capture, cv_cap_prop_frame_height); int framew = (INT) cvgetcaptureproperty (capture, cv_cap_prop_frame_width ); int FPS = (INT) cvgetcaptureproperty (capture, cv_cap_prop_fps); int numframes = (INT) cvgetcaptureproperty (capture, duration); printf ("tvideo Height: % dntvideo width: % dntfps: % dntframe numbers: % DN ", frameh, framew, FPS, numframes );
// Define and initialize the int I = 0; iplimage * IMG = 0; char image_name [13]; cvnamedwindow ("mainwin", cv_window_autosize );
// Read and display while (1) {IMG = cvqueryframe (capture); // obtain an image cvshowimage ("mainwin", IMG ); // display the char key = cvwaitkey (20); sprintf (image_name, "% S % d % s", "image", ++ I ,". jpg "); // name of the saved image cvsaveimage (image_name, IMG); // save an image if (I = num_frame) break;} cvreleasecapture (& capture ); cvdestroywindow ("mainwin");} void image_to_video () {int I = 0; iplimage * IMG = 0; char image_name [13]; printf ("------------- image to video... ---------------- N ");
// Initialize the video writer. Modify the parameter cvvideowriter * Writer = 0 according to the actual video file; int iscolor = 1; int FPS = 30; // or 25 int framew = 400; // 744 for Firewire cameras int frameh = 240; // 480 for Firewire cameras writer = cvcreatevideowriter ("out. avi ", cv_fourcc ('x', 'V', 'I', 'D'), FPS, cvsize (framew, frameh), iscolor); printf (" tvideo height: % dntvideo width: % dntfps: % DN ", frameh, framew, FPS );
// Create a window cvnamedwindow ("mainwin", cv_window_autosize); While (I <num_frame) {sprintf (image_name, "% S % d % s", "image ", ++ I ,". jpg "); IMG = cvloadimage (image_name); If (! IMG) {printf ("cocould not load image file... N "); exit (0);} cvshowimage (" mainwin ", IMG); char key = cvwaitkey (20); cvwriteframe (writer, IMG );} cvreleasevideowriter (& writer); cvdestroywindow ("mainwin");} int main (INT argc, char * argv []) {char filename [13] = "1.avi "; video_to_image (filename); // return 0 for video conversion ;}
Convert from: watermark (.jpg,.bmp), and save the continuous image as a video for Demonstration:
Paste the Code directly. After learning opencv for a week, you can definitely understand it:
# Include <stdlib. h> # include <stdio. h> # include <math. h> # include <cv. h> # include
// Initialize a video file catcher cvcapture * capture = cvcapturefromavi (filename );
// Obtain the video information cvqueryframe (capture); int frameh = (INT) cvgetcaptureproperty (capture, cv_cap_prop_frame_height); int framew = (INT) cvgetcaptureproperty (capture, cv_cap_prop_frame_width ); int FPS = (INT) cvgetcaptureproperty (capture, cv_cap_prop_fps); int numframes = (INT) cvgetcaptureproperty (capture, duration); printf ("tvideo Height: % dntvideo width: % dntfps: % dntframe numbers: % DN ", frameh, framew, FPS, numframes );
// Define and initialize the int I = 0; iplimage * IMG = 0; char image_name [13]; cvnamedwindow ("mainwin", cv_window_autosize );
// Read and display while (1) {IMG = cvqueryframe (capture); // obtain an image cvshowimage ("mainwin", IMG ); // display the char key = cvwaitkey (20); sprintf (image_name, "% S % d % s", "image", ++ I ,". jpg "); // name of the saved image cvsaveimage (image_name, IMG); // save an image if (I = num_frame) break;} cvreleasecapture (& capture ); cvdestroywindow ("mainwin");} void image_to_video () {int I = 0; iplimage * IMG = 0; char image_name [13]; printf ("------------- image to video... ---------------- N ");
// Initialize the video writer. Modify the parameter cvvideowriter * Writer = 0 according to the actual video file; int iscolor = 1; int FPS = 30; // or 25 int framew = 400; // 744 for Firewire cameras int frameh = 240; // 480 for Firewire cameras writer = cvcreatevideowriter ("out. avi ", cv_fourcc ('x', 'V', 'I', 'D'), FPS, cvsize (framew, frameh), iscolor); printf (" tvideo height: % dntvideo width: % dntfps: % DN ", frameh, framew, FPS );
// Create a window cvnamedwindow ("mainwin", cv_window_autosize); While (I <num_frame) {sprintf (image_name, "% S % d % s", "image ", ++ I ,". jpg "); IMG = cvloadimage (image_name); If (! IMG) {printf ("cocould not load image file... N "); exit (0);} cvshowimage (" mainwin ", IMG); char key = cvwaitkey (20); cvwriteframe (writer, IMG );} cvreleasevideowriter (& writer); cvdestroywindow ("mainwin");} int main (INT argc, char * argv []) {char filename [13] = "1.avi "; video_to_image (filename); // return 0 for video conversion ;}