BitmapCapture.cpp
Go to the documentation of this file.
00001 // ****************************************************************************
00002 // This file is part of the Integrating Vision Toolkit (IVT).
00003 //
00004 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
00005 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
00006 //
00007 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
00008 // All rights reserved.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are met:
00012 //
00013 // 1. Redistributions of source code must retain the above copyright
00014 //    notice, this list of conditions and the following disclaimer.
00015 //
00016 // 2. Redistributions in binary form must reproduce the above copyright
00017 //    notice, this list of conditions and the following disclaimer in the
00018 //    documentation and/or other materials provided with the distribution.
00019 //
00020 // 3. Neither the name of the KIT nor the names of its contributors may be
00021 //    used to endorse or promote products derived from this software
00022 //    without specific prior written permission.
00023 //
00024 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
00025 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
00028 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00033 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 // ****************************************************************************
00035 // ****************************************************************************
00036 // Filename:  BitmapCapture.cpp
00037 // Author:    Pedram Azad
00038 // Date:      2005
00039 // ****************************************************************************
00040 
00041 
00042 // ****************************************************************************
00043 // Includes
00044 // ****************************************************************************
00045 
00046 #include <new> // for explicitly using correct new/delete operators on VC DSPs
00047 
00048 #include "BitmapCapture.h"
00049 
00050 #include "Image/ImageProcessor.h"
00051 #include "Image/ByteImage.h"
00052 
00053 
00054 
00055 // ****************************************************************************
00056 // Constructor / Destructor
00057 // ****************************************************************************
00058 
00059 CBitmapCapture::CBitmapCapture(const char *pFilePath, const char *pSecondFilePath)
00060 {
00061         m_sFilePath = "";
00062         m_sFilePath += pFilePath;
00063 
00064         m_sSecondFilePath = "";
00065         m_pLeftImage = new CByteImage();
00066 
00067         if (pSecondFilePath)
00068         {
00069                 m_sSecondFilePath += pSecondFilePath;
00070                 m_bStereo = true;
00071                 m_pRightImage = new CByteImage();
00072         }
00073         else
00074         {
00075                 m_pRightImage = 0;
00076                 m_bStereo = false;
00077         }
00078         
00079         m_pLeftImageRGB24Split = 0;
00080         m_pRightImageRGB24Split = 0;
00081 
00082         m_bOK = false;
00083 }
00084 
00085 CBitmapCapture::~CBitmapCapture()
00086 {
00087         if (m_pLeftImage)
00088                 delete m_pLeftImage;
00089 
00090         if (m_pRightImage)
00091                 delete m_pRightImage;
00092         
00093         if (m_pLeftImageRGB24Split)
00094                 delete m_pLeftImageRGB24Split;
00095         
00096         if (m_pRightImageRGB24Split)
00097                 delete m_pRightImageRGB24Split;
00098 }
00099 
00100 
00101 // ****************************************************************************
00102 // Methods
00103 // ****************************************************************************
00104 
00105 int CBitmapCapture::GetWidth()
00106 {
00107         return m_bOK ? m_pLeftImage->width : -1;
00108 }
00109 
00110 int CBitmapCapture::GetHeight()
00111 {
00112         return m_bOK ? m_pLeftImage->height : -1;
00113 }
00114 
00115 CByteImage::ImageType CBitmapCapture::GetType()
00116 {
00117         return m_bOK ? m_pLeftImage->type : (CByteImage::ImageType) -1;
00118 }
00119 
00120 
00121 bool CBitmapCapture::OpenCamera()
00122 {
00123         m_bOK = false;
00124 
00125         if (!m_pLeftImage->LoadFromFile(m_sFilePath.c_str()))
00126                 return false;
00127         
00128         if (m_pLeftImage->type == CByteImage::eRGB24)
00129         {
00130                 if (m_pLeftImageRGB24Split)
00131                         delete m_pLeftImageRGB24Split;
00132                 
00133                 m_pLeftImageRGB24Split = new CByteImage(m_pLeftImage->width, m_pLeftImage->height, CByteImage::eRGB24Split);
00134                 ImageProcessor::ConvertImage(m_pLeftImage, m_pLeftImageRGB24Split);
00135         }
00136 
00137         if (m_bStereo)
00138         {
00139                 if (!m_pRightImage->LoadFromFile(m_sSecondFilePath.c_str()))
00140                         return false;
00141                         
00142                 if (m_pLeftImage->width != m_pRightImage->width || m_pLeftImage->height != m_pRightImage->height)
00143                         return false;
00144                 
00145                 if (m_pRightImage->type == CByteImage::eRGB24)
00146                 {
00147                         if (m_pRightImageRGB24Split)
00148                                 delete m_pRightImageRGB24Split;
00149                         
00150                         m_pRightImageRGB24Split = new CByteImage(m_pRightImage->width, m_pRightImage->height, CByteImage::eRGB24Split);
00151                         ImageProcessor::ConvertImage(m_pRightImage, m_pRightImageRGB24Split);
00152                 }
00153         }
00154         
00155         m_bOK = true;
00156     
00157         return true;
00158 }
00159 
00160 void CBitmapCapture::CloseCamera()
00161 {
00162 }
00163 
00164 bool CBitmapCapture::CaptureImage(CByteImage **ppImages)
00165 {
00166         if (!m_bOK)
00167                 return false;
00168         
00169         if (ppImages[0]->IsCompatible(m_pLeftImage))
00170                 ImageProcessor::CopyImage(m_pLeftImage, ppImages[0]);
00171         else if (ppImages[0]->IsCompatible(m_pLeftImageRGB24Split))
00172                 ImageProcessor::CopyImage(m_pLeftImageRGB24Split, ppImages[0]);
00173         else
00174         {
00175                 printf("error: images are not compatible in CBitmapCapture::CaptureImage\n");
00176                 return false;
00177         }
00178                 
00179         if (m_bStereo)
00180         {
00181                 if (ppImages[1]->IsCompatible(m_pRightImage))
00182                         ImageProcessor::CopyImage(m_pRightImage, ppImages[1]);
00183                 else if (ppImages[1]->IsCompatible(m_pRightImageRGB24Split))
00184                         ImageProcessor::CopyImage(m_pRightImageRGB24Split, ppImages[1]);
00185                 else
00186                 {
00187                         printf("error: images are not compatible in CBitmapCapture::CaptureImage\n");
00188                         return false;
00189                 }
00190         }
00191         
00192         return true;
00193 }


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Thu Jun 6 2019 21:46:57