Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
CvTestbed Class Reference

CvTestbed is a class for making quick OpenCV test applications More...

#include <CvTestbed.h>

List of all members.

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 CvTestbedInstance ()
 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.
CvTestbedoperator= (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

Capturecap
std::string filename
 The filename if we are reading an AVI file.
std::vector< Imageimages
 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.

Detailed Description

CvTestbed is a class for making quick OpenCV test applications

Author:
ttehop

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.


Constructor & Destructor Documentation

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.


Member Function Documentation

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)

Examples:
SampleIntegralImage.cpp, SampleMarkerHide.cpp, and SamplePointcloud.cpp.

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)

Examples:
SampleCvTestbed.cpp, SampleIntegralImage.cpp, SampleMarkerDetector.cpp, SamplePointcloud.cpp, and SampleTrack.cpp.

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::operator= ( const CvTestbed ) [protected]

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.

Parameters:
titleTitle for the image
iplThe IplImage to be stored
release_at_exitBoolean 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.

Examples:
SampleLabeling.cpp, SampleMultiMarker.cpp, SampleMultiMarkerBundle.cpp, SamplePointcloud.cpp, and SampleTrack.cpp.

Definition at line 97 of file CvTestbed.cpp.

void CvTestbed::SetVideoCallback ( void(*)(IplImage *image _videocallback)
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.

Parameters:
capThe capture device. If NULL a default capture device is created.
Examples:
SampleCamCalib.cpp, SampleCvTestbed.cpp, SampleIntegralImage.cpp, SampleLabeling.cpp, SampleMarkerDetector.cpp, SampleMarkerHide.cpp, SampleMarkerlessDetector.cpp, SampleMultiMarker.cpp, SampleMultiMarkerBundle.cpp, SamplePointcloud.cpp, and SampleTrack.cpp.

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.

Examples:
SampleIntegralImage.cpp, and SamplePointcloud.cpp.

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.


Member Data Documentation

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.


The documentation for this class was generated from the following files:


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Thu Feb 16 2017 03:23:02