Saturday, January 08, 2005

mouse event, write avi and read avi

Example for mouse event and write file to an AVI file. Several functions are used:
cvSetMouseCallback, cvCreateVideoWriter, cvWriteFrame .

// AviTest.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"

char img_name[]="AviTest";
IplImage* img=0;
CvCapture* capture=0;
CvVideoWriter* writer=0;

void on_mouse(int event, int x, int y, int flags) { // step 4: when click mouse

cvCircle(img, cvPoint(x,y), 3, CV_RGB(255,64,0), 2, 8, 0);
cvShowImage(img_name, img);
cvWriteFrame(writer, img); // step 5: write one frame to video file, go to step 6

void main(void) {

// "init"
img=cvCreateImage(cvSize(256, 256), IPL_DEPTH_8U, 3);
cvNamedWindow(img_name, HG_AUTOSIZE);
cvShowImage(img_name, img);
writer=cvCreateVideoWriter("AviTest.avi", -1, 25, cvGetSize(img)); // step 1: give avi name

// "loop"
cvSetMouseCallback(img_name, on_mouse); // step 2: wait mouse // step 6: from step 5.
cvWaitKey(0); //step 3: // wait here for a key hit, otherwise, any mouse operation to the window will be processed

// "cleanup"

Writing to AVI can only be used in Beta4.

Read from AVI and get the frames. Functions are used:

cvCaptureFromAVI, cvQueryFrame. Reading from AVI can be used in 3.1

No comments:

Post a Comment