CapturePluginHighgui.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
3  *
4  * Copyright 2007-2012 VTT Technical Research Centre of Finland
5  *
6  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
8  *
9  * ALVAR is free software; you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with ALVAR; if not, see
21  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
22  */
23 
24 #include "CapturePluginHighgui.h"
25 
26 #include <sstream>
27 
28 namespace alvar {
29 namespace plugins {
30 
32  : Capture(captureDevice)
33  , mVideoCapture()
34  , mMatrix()
35  , mImage()
36 {
37 }
38 
40 {
41  stop();
42 }
43 
44 void CaptureHighgui::setResolution(const unsigned long xResolution, const unsigned long yResolution)
45 {
46  if (mVideoCapture.isOpened()) {
47  mVideoCapture.set(CV_CAP_PROP_FRAME_WIDTH, xResolution);
48  mVideoCapture.set(CV_CAP_PROP_FRAME_HEIGHT, yResolution);
49  mXResolution = (int)mVideoCapture.get(CV_CAP_PROP_FRAME_WIDTH);
50  mYResolution = (int)mVideoCapture.get(CV_CAP_PROP_FRAME_HEIGHT);
51  }
52 }
53 
55 {
56  if (isCapturing()) {
57  return isCapturing();
58  }
59 
60  std::istringstream convert(captureDevice().id());
61  int id;
62  convert >> id;
63 
64  mVideoCapture.open(id);
65  if (mVideoCapture.isOpened()) {
66  mIsCapturing = true;
67  }
68 
69  return isCapturing();
70 }
71 
73 {
74  if (isCapturing()) {
75  mVideoCapture.release();
76  mIsCapturing = false;
77  }
78 }
79 
81 {
82  if (!isCapturing()) {
83  return NULL;
84  }
85  if (!mVideoCapture.grab()) {
86  return NULL;
87  }
88  mVideoCapture.retrieve(mMatrix);
89  mImage = mMatrix;
90  return &mImage;
91 }
92 
94 {
95  // TODO: implement this method
96  return false;
97 }
98 
100 {
101  return "CaptureHighgui";
102 }
103 
105 {
106  return false;
107 }
108 
109 CapturePluginHighgui::CapturePluginHighgui(const std::string &captureType)
110  : CapturePlugin(captureType)
111 {
112 }
113 
115 {
116 }
117 
119 {
120  CaptureDeviceVector devices;
121 
122  bool loop = true;
123  int id = 0;
124  cv::VideoCapture videoCapture;
125 
126  while (loop) {
127  std::stringstream convert;
128  convert << id;
129  CaptureDevice captureDevice(mCaptureType, convert.str());
130 
131  videoCapture.open(id);
132  if (videoCapture.isOpened()) {
133  int width = (int)videoCapture.get(CV_CAP_PROP_FRAME_WIDTH);
134  int height = (int)videoCapture.get(CV_CAP_PROP_FRAME_HEIGHT);
135  if (width > 0 && height > 0) {
136  devices.push_back(captureDevice);
137  }
138  else {
139  loop = false;
140  }
141  }
142  else {
143  loop = false;
144  }
145 
146  id++;
147  }
148  videoCapture.release();
149 
150  return devices;
151 }
152 
154 {
155  return new CaptureHighgui(captureDevice);
156 }
157 
158 void registerPlugin(const std::string &captureType, alvar::CapturePlugin *&capturePlugin)
159 {
160  capturePlugin = new CapturePluginHighgui(captureType);
161 }
162 
163 } // namespace plugins
164 } // namespace alvar
CaptureHighgui(const CaptureDevice captureDevice)
Constructor.
Main ALVAR namespace.
Definition: Alvar.h:174
CapturePluginHighgui(const std::string &captureType)
Constructor.
This file implements a capture plugin based on Highgui.
Implementation of Capture interface for Highgui plugin.
CaptureDevice captureDevice()
The camera information associated to this capture object.
Definition: Capture.h:70
void setResolution(const unsigned long xResolution, const unsigned long yResolution)
Set the resolution.
unsigned long mXResolution
Definition: Capture.h:181
unsigned long xResolution()
The resolution along the x axis (horizontal).
Definition: Capture.h:75
int height
Definition: GlutViewer.cpp:160
std::string mCaptureType
Definition: CapturePlugin.h:83
unsigned long yResolution()
The resolution along the y axis (vertical).
Definition: Capture.h:80
bool showSettingsDialog()
Show the settings dialog of the camera.
CaptureDevice holder for camera information.
Definition: CaptureDevice.h:44
bool Serialize(Serialization *serialization)
Performs serialization of the class members and configuration.
Capture * createCapture(const CaptureDevice captureDevice)
Create Capture class. Transfers onwership to the caller.
void registerPlugin(const std::string &captureType, alvar::CapturePlugin *&capturePlugin)
CapturePlugin interface that plugins must implement.
Definition: CapturePlugin.h:44
CaptureDeviceVector enumerateDevices()
Enumerate capture devices currently available.
int width
Definition: GlutViewer.cpp:159
void stop()
Stops the camera capture.
IplImage * captureImage()
Capture one image from the camera.
bool isCapturing()
Test if the camera was properly initialized.
Definition: Capture.h:85
Capture interface that plugins must implement.
Definition: Capture.h:46
std::string SerializeId()
The identification of the class for serialization.
void convert(const A &a, B &b)
Class for serializing class content to/from file or std::iostream.
Definition: Util.h:352
bool mIsCapturing
Definition: Capture.h:183
std::vector< CaptureDevice > CaptureDeviceVector
Vector of CaptureDevices.
Definition: CapturePlugin.h:60
bool start()
Starts the camera capture.
unsigned long mYResolution
Definition: Capture.h:182


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Mon Jun 10 2019 12:47:04