SVSCapture.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:  SVSCapture.cpp
00037 // Author:    Pedram Azad
00038 // Date:      2005
00039 // ****************************************************************************
00040 // Changes:   13.07.2006, Martin Loesch
00041 //            * Fixed compatiblity issues for newer versions of the SVS
00042 //            13.06.2008, Miguel Bernal Marin
00043 //            * Optimized RGBA2RGB conversion
00044 // ****************************************************************************
00045 
00046 
00047 // ****************************************************************************
00048 // Includes
00049 // ****************************************************************************
00050 
00051 #include "SVSCapture.h"
00052 
00053 #include "Image/ByteImage.h"
00054 
00055 #include <memory.h>
00056 #include <iostream>
00057 
00058 #include <svsclass.h>
00059 
00060 
00061 
00062 // ****************************************************************************
00063 // Constructor / Destructor
00064 // ****************************************************************************
00065 
00066 CSVSCapture::CSVSCapture(VideoMode mode, int nIndex) : m_nIndex(nIndex), m_mode(mode)
00067 {
00068         svs_video = getVideoObject();
00069         
00070         m_nBytesPerPixel = 0;
00071         m_bColor = false;
00072 
00073         width = -1;
00074         height = -1;
00075 }
00076 
00077 CSVSCapture::~CSVSCapture()
00078 {
00079         CloseCamera();
00080 }
00081 
00082 
00083 // ****************************************************************************
00084 // Methods
00085 // ****************************************************************************
00086 
00087 bool CSVSCapture::CaptureImage(CByteImage **ppImages)
00088 {
00089         if (!ppImages || !ppImages[0] || !ppImages[1] ||
00090                 ppImages[0]->width != width || ppImages[0]->height != height ||
00091                 ppImages[1]->width != width || ppImages[1]->height != height )
00092         {
00093                 return false;
00094         }
00095 
00096         if ((m_bColor && ( ppImages[0]->type != CByteImage::eRGB24 || ppImages[1]->type != CByteImage::eRGB24) ) ||
00097            (!m_bColor && ( ppImages[0]->type != CByteImage::eGrayScale || ppImages[1]->type != CByteImage::eGrayScale) ) )
00098         {
00099                 return false;
00100         }
00101 
00102         // get image
00103         svsStereoImage *svs_image = svs_video->GetImage(10);
00104         if (!svs_image)
00105                 return false;
00106                 
00107         if (m_bColor)
00108         {
00109                 // destination images
00110                 unsigned int *dstL = (unsigned int *) ppImages[0]->pixels;
00111                 unsigned int *dstR = (unsigned int *) ppImages[1]->pixels;
00112 
00113                 // source images
00114                 unsigned int *srcL = (unsigned int *) svs_image->color;
00115                 unsigned int *srcR = (unsigned int *) svs_image->color_right;
00116 
00117                 // BEGIN: Miguel Bernal Marin
00118                 int max = width * height / 4;
00119                 
00120                 while (max--)
00121                 {
00122                         // copy four left images
00123                         *dstL++ = (srcL[0] & 0x00FFFFFF)       | (srcL[1] & 0x000000FF) << 24;
00124                         *dstL++ = (srcL[1] & 0x00FFFF00) >>  8 | (srcL[2] & 0x0000FFFF) << 16;
00125                         *dstL++ = (srcL[2] & 0x00FF0000) >> 16 | (srcL[3] & 0x00FFFFFF) <<  8;
00126                         
00127                         // copy four right images
00128                         *dstR++ = (srcR[0] & 0x00FFFFFF)       | (srcR[1] & 0x000000FF) << 24;
00129                         *dstR++ = (srcR[1] & 0x00FFFF00) >>  8 | (srcR[2] & 0x0000FFFF) << 16;
00130                         *dstR++ = (srcR[2] & 0x00FF0000) >> 16 | (srcR[3] & 0x00FFFFFF) <<  8;
00131 
00132                         srcL += 4;
00133                         srcR += 4;
00134                 }
00135                 // END
00136         }
00137         else
00138         {
00139                 memcpy(ppImages[1]->pixels, svs_image->left, width * height * m_nBytesPerPixel);
00140                 memcpy(ppImages[0]->pixels, svs_image->right, width * height * m_nBytesPerPixel);
00141         }
00142 
00143         return true;
00144 }
00145 
00146 void CSVSCapture::CloseCamera()
00147 {
00148         if (svs_video)
00149         {
00150                 svs_video->Stop();
00151                 svs_video->Close();
00152         }
00153 }
00154 
00155 bool CSVSCapture::OpenCamera()
00156 {
00157         int resolution = -1;
00158 
00159         // BEGIN INSERTED
00160         int maxSizeFactor = 0;  // 1=1280x960, 2=640x480
00161         // END INSERTED
00162         
00163         switch (m_mode)
00164         {
00165                 case e320x240:
00166                         width = 320;
00167                         height = 240;
00168                         resolution = 1;
00169                 break;
00170                 
00171                 case e640x480:
00172                         width = 640;
00173                         height = 480;
00174                         resolution = 4;
00175                 break;
00176                 
00177                 case e1280x960:
00178                         width = 1280;
00179                         height = 960;
00180                         resolution = 5;
00181                 break;
00182                 
00183                 default:
00184                         return false;
00185         }
00186 
00187         m_nBytesPerPixel = 3;
00188         m_bColor = true;
00189   
00190         if (!svs_video->Open(m_nIndex))
00191                 return false;
00192 
00193         // idea: try to open cam with resolution and sampling that is dependent of the possible max resolution of the cam
00194         svs_video->SetSize(320, 240);
00195         svs_video->SetSample(2, 2);
00196         
00197         if (svs_video->Start())
00198         {
00199                 svs_video->Stop();
00200                 maxSizeFactor = 1; // cam has max resolution 1280x960
00201         }
00202         else
00203         {
00204                 maxSizeFactor = 2; // cam has max resolution 640x480
00205         }
00206 
00207         svsImageParams *ip = 0;
00208   
00209         switch (resolution)
00210         {
00211                 case 0:
00212                         // 320x240
00213                         svs_video->SetSize(320, 240);
00214                         svs_video->SetFrameDiv(1);
00215                         svs_video->SetSample(1, 4 / maxSizeFactor);
00216                 break;
00217 
00218                 case 1:
00219                         // 320x240
00220                         svs_video->SetSize(320, 240);
00221                         svs_video->SetFrameDiv(1);
00222                         svs_video->SetSample(2/maxSizeFactor, 2);
00223                 break;
00224                 
00225                 case 2:
00226                         // 320x240
00227                         svs_video->SetSize(320, 240);
00228                         svs_video->SetFrameDiv(1);
00229                         svs_video->SetSample(4 / (maxSizeFactor * maxSizeFactor), maxSizeFactor); // some kind of evil hack, because for some reason, SetSample(2,1) will not work with the 640x480 videre Cam, it has to be SetSample(1,2)...
00230                 break;
00231 
00232                 case 3:
00233                         // 640x480
00234                         svs_video->SetSize(640, 480);
00235                         svs_video->SetFrameDiv(1);
00236                         svs_video->SetSample(1, 2 / maxSizeFactor);
00237                 break;
00238                 
00239                 case 4:
00240                         // 640x480
00241                         svs_video->SetSize(640, 480);
00242                         svs_video->SetFrameDiv(1);
00243                         svs_video->SetSample(2 / maxSizeFactor, 1);
00244                 break;
00245                 
00246                 case 5:
00247                         // 1280x960
00248                         svs_video->SetSize(1280, 960);
00249                         svs_video->SetFrameDiv(1);
00250                         svs_video->SetSample(1, 1);
00251                         ip->ix = 0;
00252                         ip->iy = 0;
00253                         ip->vergence = 0;
00254                 break;
00255         }
00256   
00257         // set default values
00258         svs_video->SetBalance(false, 20, 10);
00259         svs_video->SetColor(true, true);
00260         svs_video->SetRect(false);
00261         svs_video->exposure = 100;
00262         svs_video->gain = 30;
00263         svs_video->SetRate(30);
00264         svs_video->SetDigitization();
00265 
00266         // start video acquisition
00267         if (!svs_video->Start())
00268         {
00269                 CloseCamera();
00270                 return false;
00271         }
00272         
00273         return true;
00274 }
00275 
00276 void CSVSCapture::SetRed(int val)
00277 {
00278         if (val < -40 || val > 40)
00279                 return;
00280                 
00281         svs_video->red = val;
00282         svs_video->SetDigitization();
00283 }
00284 
00285 void CSVSCapture::SetBlue(int val)
00286 {
00287         if (val < -40 || val > 40)
00288                 return;
00289         
00290         svs_video->blue = val;
00291         svs_video->SetDigitization();
00292 }
00293 
00294 void CSVSCapture::SetExposure(int val)
00295 {
00296         if (val < 0 || val > 100)
00297                 return;
00298 
00299         svs_video->exposure = val;
00300         svs_video->SetDigitization();
00301 }
00302 
00303 void CSVSCapture::SetGain(int val)
00304 {
00305         if (val < 0 || val > 100)
00306                 return;
00307                 
00308         svs_video->gain = val;
00309         svs_video->SetDigitization();
00310 }
00311 
00312 void CSVSCapture::SetColor(bool bColor)
00313 {       
00314         svs_video->SetColor(bColor, bColor);
00315         svs_video->SetDigitization();
00316                 
00317         if (bColor)
00318         {
00319                 m_nBytesPerPixel = 3;
00320         }
00321         else
00322         {
00323                 m_nBytesPerPixel = 1;
00324         }
00325         
00326         m_bColor = bColor;
00327 }
00328 
00329 void CSVSCapture::SetRectify(bool bRectify)
00330 {
00331         svs_video->SetRect(bRectify);
00332         svs_video->SetDigitization();
00333 }


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:58