11 bool flip_image = (image->origin?
true:
false);
14 image->origin = !image->origin;
24 const int min_edge_size = 10;
25 CvSeq* edges = labeling->
LabelImage(image, min_edge_size);
27 int n_edges = edges->total;
28 for(
int i = 0; i < n_edges; ++i)
30 CvSeq* pixels = (CvSeq*)cvGetSeqElem(edges, i);
31 int n_pixels = pixels->total;
32 for(
int j = 0; j < n_pixels; ++j)
34 CvPoint* pt = (CvPoint*)cvGetSeqElem(pixels, j);
35 cvLine(image, *pt, *pt, CV_RGB(255,0,0));
44 image->origin = !image->origin;
53 std::cout<<
"Adaptive threshold block size: "<<
thresh_param1<<std::endl;
59 std::cout<<
"Adaptive threshold block size: "<<
thresh_param1<<std::endl;
67 int main(
int argc,
char *argv[])
72 filename = filename.substr(filename.find_last_of(
'\\') + 1);
73 std::cout <<
"SampleLabeling" << std::endl;
74 std::cout <<
"==============" << std::endl;
75 std::cout << std::endl;
76 std::cout <<
"Description:" << std::endl;
77 std::cout <<
" This is an example of how to use the 'LabelingCvSeq' class to perform" << std::endl;
78 std::cout <<
" labeling. Blobs are detected in the image and if the blobs have four" << std::endl;
79 std::cout <<
" corners, the edges between the corners are visualized." << std::endl;
80 std::cout << std::endl;
81 std::cout <<
"Usage:" << std::endl;
82 std::cout <<
" " << filename <<
" [device]" << std::endl;
83 std::cout << std::endl;
84 std::cout <<
" device integer selecting device from enumeration list (default 0)" << std::endl;
85 std::cout <<
" highgui capture devices are prefered" << std::endl;
86 std::cout << std::endl;
87 std::cout <<
"Keyboard Shortcuts:" << std::endl;
88 std::cout <<
" +: Increase adaptive threshold block size." << std::endl;
89 std::cout <<
" -: Decrease adaptive threshold block size." << std::endl;
90 std::cout <<
" q: quit" << std::endl;
91 std::cout << std::endl;
99 if (plugins.size() < 1) {
100 std::cout <<
"Could not find any capture plugins." << std::endl;
105 std::cout <<
"Available Plugins: ";
107 std::cout << std::endl;
111 if (devices.size() < 1) {
112 std::cout <<
"Could not find any capture devices." << std::endl;
119 selectedDevice = atoi(argv[1]);
121 if (selectedDevice >= (
int)devices.size()) {
126 std::cout <<
"Enumerated Capture Devices:" << std::endl;
128 std::cout << std::endl;
132 std::string uniqueName = devices[selectedDevice].uniqueName();
137 std::stringstream settingsFilename;
138 settingsFilename <<
"camera_settings_" << uniqueName <<
".xml";
144 std::cout <<
"Loading settings: " << settingsFilename.str() << std::endl;
147 std::stringstream title;
153 std::cout <<
"Saving settings: " << settingsFilename.str() << std::endl;
162 std::cout <<
"Could not initialize the selected capture backend." << std::endl;
167 catch (
const std::exception &e) {
168 std::cout <<
"Exception: " << e.what() << endl;
171 std::cout <<
"Exception: unknown" << std::endl;
static CvTestbed & Instance()
The one and only instance of CvTestbed is accessed using CvTestbed::Instance()
Capture * createCapture(const CaptureDevice captureDevice)
Create Capture class. Transfers onwership to the caller.
virtual void stop()=0
Stops the camera capture.
This file implements connected component labeling.
void SetThreshParams(int param1, int param2)
virtual bool start()=0
Starts the camera capture.
CaptureDevice captureDevice()
The camera information associated to this capture object.
void SetVideoCallback(void(*_videocallback)(IplImage *image))
Set the videocallback function that will be called for every frame.
static CaptureFactory * instance()
The singleton instance of CaptureFactory.
void videocallback(IplImage *image)
int main(int argc, char *argv[])
std::vector< CaptureDevice > CaptureDeviceVector
Vector of CaptureDevices.
std::string captureType() const
The type of capture backend.
bool StartVideo(Capture *_cap, const char *_wintitle=0)
Start video input from given capture device.
std::vector< std::string > CapturePluginVector
Vector of strings.
void outputEnumeratedPlugins(CaptureFactory::CapturePluginVector &plugins)
void SetKeyCallback(int(*_keycallback)(int key))
Sets the keyboard callback function that will be called when keyboard is pressed. ...
CvSeq * LabelImage(IplImage *image, int min_size, bool approx=false)
CaptureDeviceVector enumerateDevices(const std::string &captureType="")
Enumerate capture devices currently available.
CapturePluginVector enumeratePlugins()
Enumerate capture plugins currently available.
void outputEnumeratedDevices(CaptureFactory::CaptureDeviceVector &devices, int selectedDevice)
void LabelSquares(IplImage *image, bool visualize=false)
Labels image and filters blobs to obtain square-shaped objects from the scene.
Capture interface that plugins must implement.
virtual bool loadSettings(std::string filename)
Load camera settings from a file.
int defaultDevice(CaptureFactory::CaptureDeviceVector &devices)
virtual void setResolution(const unsigned long xResolution, const unsigned long yResolution)
Set the resolution.
Labeling class that uses OpenCV routines to find connected components.
virtual bool saveSettings(std::string filename)
Save camera settings to a file.