CvTestbed is a class for making quick OpenCV test applications More...
#include <CvTestbed.h>
Classes | |
struct | Image |
Image structure to store the images internally. More... | |
Public Member Functions | |
IplImage * | CreateImage (const char *title, CvSize size, int depth, int channels) |
Creates an image with given size, depth and channels and stores it with a given 'title' (see CvTestbed::SetImage) | |
IplImage * | CreateImageWithProto (const char *title, IplImage *proto, int depth=0, int channels=0) |
Creates an image based on the given prototype and stores it with a given 'title' (see CvTestbed::SetImage) | |
IplImage * | GetImage (size_t index) |
Get a pointer for the stored image based on index number. | |
IplImage * | GetImage (const char *title) |
Get a pointer for the stored image based on title. | |
size_t | GetImageIndex (const char *title) |
Get an index number of the stored image based on title. | |
size_t | SetImage (const char *title, IplImage *ipl, bool release_at_exit=false) |
Sets an existing IplImage to be stored with the given title. | |
void | SetKeyCallback (int(*_keycallback)(int key)) |
Sets the keyboard callback function that will be called when keyboard is pressed. | |
void | SetVideoCallback (void(*_videocallback)(IplImage *image)) |
Set the videocallback function that will be called for every frame. | |
bool | StartVideo (Capture *_cap, const char *_wintitle=0) |
Start video input from given capture device. | |
void | StopVideo () |
Stop video. | |
bool | ToggleImageVisible (size_t index, int flags=1) |
Toggle the visibility of the stored image. | |
Static Public Member Functions | |
static CvTestbed & | Instance () |
The one and only instance of CvTestbed is accessed using CvTestbed::Instance() | |
Protected Member Functions | |
CvTestbed () | |
Hidden constructor for Singleton. | |
CvTestbed (const CvTestbed &) | |
Hidden copy constructor for Singleton. | |
CvTestbed & | operator= (const CvTestbed &) |
Hidden copy operator for Singleton. | |
void | ShowVisibleImages () |
ShowVisibleImages is called from the videocallback. This shows the internally stored images which have the visible-flag on | |
void | WaitKeys () |
WaitKeys contains the main loop. | |
~CvTestbed () | |
Hidden destructor for Singleton. | |
Static Protected Member Functions | |
static void | default_videocallback (IplImage *image) |
Video callback called for every frame. This calls user-defined videocallback if one exists. | |
Protected Attributes | |
Capture * | cap |
std::string | filename |
The filename if we are reading an AVI file. | |
std::vector< Image > | images |
Vector of images stored internally. | |
int(* | keycallback )(int key) |
Pointer for the user-defined KEYcallback. | |
bool | running |
Boolean indicating are we still running. We exit from the WaitKeys when this is false. | |
void(* | videocallback )(IplImage *image) |
Pointer for the user-defined videocallback. | |
std::string | wintitle |
The window title for the video view. |
CvTestbed is a class for making quick OpenCV test applications
Usage:
#include "CvTestbed.h" void videocallback(IplImage *image) { static IplImage *img_gray=NULL; assert(image); if (img_gray == NULL) { // Following image is toggled visible using key '0' img_gray = CvTestbed::Instance().CreateImageWithProto("img_gray", image, 0, 1); } cvCvtColor(image, img_gray, CV_RGB2GRAY); // TODO: Do your image operations } void main() { CvTestbed::Instance().SetVideoCallback(videocallback); // Set video callback CvTestbed::Instance().StartVideo("movie.avi"); // Video from avi // CvTestbed::Instance().StartVideo(0) // Video from camera 0 }
In addition to handling video input from avi or from camera CvTestbed has also functions for creating and showing (and automatically releasing) IplImage's.
The CvTestbed is made into a simple Meyers singleton:
class Singleton { public: static Singleton& Instance() { static Singleton obj; return obj; } private: Singleton(); Singleton(const Singleton&); Singleton& operator=(const Singleton&); ~Singleton(); }
The only instance of the class is accessed using public Instance()-interface. All possible constructors and destructors are hidden. If more complex singleton approach is needed refer to Loki library or the book "Modern C++ Design".
Definition at line 66 of file CvTestbed.h.
CvTestbed::CvTestbed | ( | ) | [protected] |
Hidden constructor for Singleton.
Definition at line 3 of file CvTestbed.cpp.
CvTestbed::CvTestbed | ( | const CvTestbed & | ) | [protected] |
Hidden copy constructor for Singleton.
CvTestbed::~CvTestbed | ( | ) | [protected] |
Hidden destructor for Singleton.
Definition at line 11 of file CvTestbed.cpp.
IplImage * CvTestbed::CreateImage | ( | const char * | title, |
CvSize | size, | ||
int | depth, | ||
int | channels | ||
) |
Creates an image with given size, depth and channels and stores it with a given 'title' (see CvTestbed::SetImage)
Definition at line 143 of file CvTestbed.cpp.
IplImage * CvTestbed::CreateImageWithProto | ( | const char * | title, |
IplImage * | proto, | ||
int | depth = 0 , |
||
int | channels = 0 |
||
) |
Creates an image based on the given prototype and stores it with a given 'title' (see CvTestbed::SetImage)
Definition at line 150 of file CvTestbed.cpp.
void CvTestbed::default_videocallback | ( | IplImage * | image | ) | [static, protected] |
Video callback called for every frame. This calls user-defined videocallback if one exists.
Definition at line 20 of file CvTestbed.cpp.
IplImage * CvTestbed::GetImage | ( | size_t | index | ) |
Get a pointer for the stored image based on index number.
Definition at line 160 of file CvTestbed.cpp.
IplImage * CvTestbed::GetImage | ( | const char * | title | ) |
Get a pointer for the stored image based on title.
Definition at line 176 of file CvTestbed.cpp.
size_t CvTestbed::GetImageIndex | ( | const char * | title | ) |
Get an index number of the stored image based on title.
Definition at line 166 of file CvTestbed.cpp.
CvTestbed & CvTestbed::Instance | ( | ) | [static] |
The one and only instance of CvTestbed is accessed using CvTestbed::Instance()
Definition at line 88 of file CvTestbed.cpp.
Hidden copy operator for Singleton.
size_t CvTestbed::SetImage | ( | const char * | title, |
IplImage * | ipl, | ||
bool | release_at_exit = false |
||
) |
Sets an existing IplImage to be stored with the given title.
title | Title for the image |
ipl | The IplImage to be stored |
release_at_exit | Boolean indicating should CvTestbed automatically release the image at exit |
Definition at line 126 of file CvTestbed.cpp.
void CvTestbed::SetKeyCallback | ( | int(*)(int key) | _keycallback | ) |
Sets the keyboard callback function that will be called when keyboard is pressed.
The callback should return 0 if it doesn't want the default keyboard actions to be made. By default keys '0'-'9' executes ToggleImageVisible for first 10 IplImage's, while any other key will Exit the program.
Definition at line 97 of file CvTestbed.cpp.
void CvTestbed::SetVideoCallback | ( | void(*)(IplImage *image) | _videocallback | ) |
Set the videocallback function that will be called for every frame.
Definition at line 93 of file CvTestbed.cpp.
void CvTestbed::ShowVisibleImages | ( | ) | [protected] |
ShowVisibleImages is called from the videocallback. This shows the internally stored images which have the visible-flag on
Definition at line 80 of file CvTestbed.cpp.
bool CvTestbed::StartVideo | ( | Capture * | _cap, |
const char * | _wintitle = 0 |
||
) |
Start video input from given capture device.
cap | The capture device. If NULL a default capture device is created. |
Definition at line 101 of file CvTestbed.cpp.
void CvTestbed::StopVideo | ( | ) | [inline] |
Stop video.
Definition at line 136 of file CvTestbed.h.
bool CvTestbed::ToggleImageVisible | ( | size_t | index, |
int | flags = 1 |
||
) |
Toggle the visibility of the stored image.
Definition at line 180 of file CvTestbed.cpp.
void CvTestbed::WaitKeys | ( | ) | [protected] |
WaitKeys contains the main loop.
Definition at line 36 of file CvTestbed.cpp.
Capture* CvTestbed::cap [protected] |
Definition at line 68 of file CvTestbed.h.
std::string CvTestbed::filename [protected] |
The filename if we are reading an AVI file.
Definition at line 87 of file CvTestbed.h.
std::vector<Image> CvTestbed::images [protected] |
Vector of images stored internally.
Definition at line 98 of file CvTestbed.h.
int(* CvTestbed::keycallback)(int key) [protected] |
Pointer for the user-defined KEYcallback.
Definition at line 83 of file CvTestbed.h.
bool CvTestbed::running [protected] |
Boolean indicating are we still running. We exit from the WaitKeys when this is false.
Definition at line 78 of file CvTestbed.h.
void(* CvTestbed::videocallback)(IplImage *image) [protected] |
Pointer for the user-defined videocallback.
Definition at line 81 of file CvTestbed.h.
std::string CvTestbed::wintitle [protected] |
The window title for the video view.
Definition at line 85 of file CvTestbed.h.