CapturePluginFile.cpp
Go to the documentation of this file.
00001 /*
00002  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
00003  *
00004  * Copyright 2007-2012 VTT Technical Research Centre of Finland
00005  *
00006  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
00007  *          <http://www.vtt.fi/multimedia/alvar.html>
00008  *
00009  * ALVAR is free software; you can redistribute it and/or modify it under the
00010  * terms of the GNU Lesser General Public License as published by the Free
00011  * Software Foundation; either version 2.1 of the License, or (at your option)
00012  * any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful, but WITHOUT
00015  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00016  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00017  * for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public License
00020  * along with ALVAR; if not, see
00021  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
00022  */
00023 
00024 #include "CapturePluginFile.h"
00025 
00026 namespace alvar {
00027 namespace plugins {
00028 
00029 CaptureFile::CaptureFile(const CaptureDevice captureDevice)
00030     : Capture(captureDevice)
00031     , mVideoCapture()
00032     , mMatrix()
00033     , mImage()
00034 {
00035 }
00036 
00037 CaptureFile::~CaptureFile()
00038 {
00039     stop();
00040 }
00041 
00042 bool CaptureFile::start()
00043 {
00044     if (isCapturing()) {
00045         return isCapturing();
00046     }
00047 
00048     mVideoCapture.open(captureDevice().id().c_str());
00049     if (mVideoCapture.isOpened()) {
00050         mXResolution = (int)mVideoCapture.get(CV_CAP_PROP_FRAME_WIDTH);
00051         mYResolution = (int)mVideoCapture.get(CV_CAP_PROP_FRAME_HEIGHT);
00052         mIsCapturing = true;
00053     }
00054 
00055     return isCapturing();
00056 }
00057 
00058 void CaptureFile::stop()
00059 {
00060     if (isCapturing()) {
00061         mVideoCapture.release();
00062         mIsCapturing = false;
00063     }
00064 }
00065 
00066 IplImage *CaptureFile::captureImage()
00067 {
00068     if (!isCapturing()) {
00069         return NULL;
00070     }
00071 
00072     if (!mVideoCapture.grab()) {
00073         // try to restart the capturing when end of file is reached
00074         mVideoCapture.release();
00075         mVideoCapture.open(captureDevice().id().c_str());
00076         if (!mVideoCapture.isOpened()) {
00077             mIsCapturing = false;
00078             return NULL;
00079         }
00080         if (!mVideoCapture.grab()) {
00081             return NULL;
00082         }
00083     }
00084     mVideoCapture.retrieve(mMatrix);
00085     mImage = mMatrix;
00086     return &mImage;
00087 }
00088 
00089 bool CaptureFile::showSettingsDialog()
00090 {
00091     // TODO: implement this method
00092     return false;
00093 }
00094 
00095 std::string CaptureFile::SerializeId()
00096 {
00097     return "CaptureFile";
00098 }
00099 
00100 bool CaptureFile::Serialize(Serialization *serialization)
00101 {
00102     return false;
00103 }
00104 
00105 CapturePluginFile::CapturePluginFile(const std::string &captureType)
00106     : CapturePlugin(captureType)
00107 {
00108 }
00109 
00110 CapturePluginFile::~CapturePluginFile()
00111 {
00112 }
00113 
00114 CapturePlugin::CaptureDeviceVector CapturePluginFile::enumerateDevices()
00115 {
00116     CaptureDeviceVector devices;
00117     return devices;
00118 }
00119 
00120 Capture *CapturePluginFile::createCapture(const CaptureDevice captureDevice)
00121 {
00122     return new CaptureFile(captureDevice);
00123 }
00124 
00125 void registerPlugin(const std::string &captureType, alvar::CapturePlugin *&capturePlugin)
00126 {
00127     capturePlugin = new CapturePluginFile(captureType);
00128 }
00129 
00130 } // namespace plugins
00131 } // namespace alvar


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Sun Oct 5 2014 22:16:26