Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
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
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
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
00103 svsStereoImage *svs_image = svs_video->GetImage(10);
00104 if (!svs_image)
00105 return false;
00106
00107 if (m_bColor)
00108 {
00109
00110 unsigned int *dstL = (unsigned int *) ppImages[0]->pixels;
00111 unsigned int *dstR = (unsigned int *) ppImages[1]->pixels;
00112
00113
00114 unsigned int *srcL = (unsigned int *) svs_image->color;
00115 unsigned int *srcR = (unsigned int *) svs_image->color_right;
00116
00117
00118 int max = width * height / 4;
00119
00120 while (max--)
00121 {
00122
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
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
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
00160 int maxSizeFactor = 0;
00161
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
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;
00201 }
00202 else
00203 {
00204 maxSizeFactor = 2;
00205 }
00206
00207 svsImageParams *ip = 0;
00208
00209 switch (resolution)
00210 {
00211 case 0:
00212
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
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
00227 svs_video->SetSize(320, 240);
00228 svs_video->SetFrameDiv(1);
00229 svs_video->SetSample(4 / (maxSizeFactor * maxSizeFactor), maxSizeFactor);
00230 break;
00231
00232 case 3:
00233
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
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
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
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
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