Click here to Skip to main content
15,895,986 members
Articles / Desktop Programming / Win32

An Introduction to OpenCV: Displaying and Manipulating Video and Motion Data

Rate me:
Please Sign up or sign in to vote.
4.57/5 (12 votes)
1 May 2012CPOL10 min read 78.7K   5.5K   46  
Explains how to use some OpenCV commands for video manipulation.
//Class requires OpenCv libaries and headers; see stdafx.h


class Video_OP
{

//Constructor & Destructor
public:
	Video_OP():my_on_off(true)
	{}
	virtual ~Video_OP(){}

//Methods

	// loads videofile and assigns a pointer to it, returns true, when successful
	bool Get_Video_from_File(char* file_name);
	//returns frame rate (frames per sec) 
	int Get_Frame_Rate();
	//returns total number of frames
	int Get_Total_Frames();
	//returns width of captured video
	int Get_Width();
	//returns height of captured video
	int Get_Height();
	//returns index of current frame
	int Get_Current_Frame_Index();
	//moves video to frame 
	void Go_to_Frame(int);
	//breaks loop presenting movies
	void Stop_Video();
	//sets up loop to present video
	void Play_Video();
	//sets up loop that runs through movie 'from 'a frame 'to' a frame
	void Play_Video(int from, int to);
    //turns video into avi file; from=first frame to=last frame
	void Write_Video(int from, int to, char* path);
	//subtracts pixel info of current frame from previous frame
	void Subtract_Successive_Frames(int from,int to);
	//calculates optical flow according to the Lucas-Kanade technique 
	void Calc_optical_flow_Lucas_Kanade(int from, int to);

	//EXTRA CODE WHICH IS NOT USED IN APPLICATION
	//calculates contours of image
	void Depict_Contours();
	//releases CvCapture Structure 
	void Unload_Video();
	//gets current frame (as image) from loaded movie and returns index
	int Query_Frame();
	//returns pointer to cvCapture structure
	CvCapture* Get_Pointer_to_Video();
	//returns pointer to grabbed frame
	IplImage* Get_Pointer_of_grabbed_frame();
	//grabs frame of loaded movie 
    void Grab_frame(int at_pos);
	

//Variables
protected:


	CvCapture * my_p_capture;
	char* my_file_name;
	bool my_on_off;
	
	int my_total_frame;
	IplImage  *my_grabbed_frame; 
	IplImage *my_first_frame;
	

};

//###### FILE DIALOG CLASS DEFINITIONS ##########
//Common File Dialog
class FileDialog
{
public: 
//Konstruktor
	FileDialog(HWND parent_handle);
	~FileDialog(){}
//Methods
   bool OpenFile();
   bool SaveFile();
   //returns Char Array of selected path
   char* GetName();
   void PrintPathName(int posX, int posY);
   
private:
	OPENFILENAME my_ofn;
	HWND my_hwnd;
	char szFileName[MAX_PATH];
	char *p_szFileName;
	
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Austria Austria
I try to be a behavioral scientist who uses his programming 'skills' to solve problems arising in the field of nonverbal communication.

Comments and Discussions