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 #include "TriclopsCapture.h"
00047 #include "Image/ByteImage.h"
00048
00049
00050
00051
00052
00053
00054
00055 CTriclopsCapture::CTriclopsCapture(VideoMode mode) : m_mode(mode)
00056 {
00057 m_nImageWidth = -1;
00058 m_nImageHeight = -1;
00059
00060 m_digiclopsContext = 0;
00061 m_triclopsContext = 0;
00062 }
00063
00064 CTriclopsCapture::~CTriclopsCapture()
00065 {
00066 CloseCamera();
00067 }
00068
00069
00070
00071
00072
00073
00074 bool CTriclopsCapture::OpenCamera()
00075 {
00076 if (m_mode != e640x480 && m_mode != e320x240)
00077 return false;
00078
00079 digiclopsCreateContext(&m_digiclopsContext);
00080 digiclopsInitialize(m_digiclopsContext, 0);
00081
00082
00083 digiclopsGetTriclopsContextFromCamera(m_digiclopsContext, &m_triclopsContext);
00084
00085
00086 digiclopsSetImageTypes(m_digiclopsContext, LEFT_IMAGE | RIGHT_IMAGE);
00087
00088
00089 switch (m_mode)
00090 {
00091 case e640x480:
00092 m_nImageWidth = 640;
00093 m_nImageHeight = 480;
00094 digiclopsSetImageResolution(m_digiclopsContext, DIGICLOPS_FULL);
00095 break;
00096
00097 case e320x240:
00098 m_nImageWidth = 320;
00099 m_nImageHeight = 240;
00100 digiclopsSetImageResolution(m_digiclopsContext, DIGICLOPS_HALF);
00101 break;
00102 }
00103
00104
00105 digiclopsSetCameraProperty(m_digiclopsContext, DIGICLOPS_WHITEBALANCE, 117, 145, false);
00106 digiclopsSetMaxFrameRate(m_digiclopsContext, DIGICLOPS_FRAMERATE_100);
00107
00108
00109 digiclopsStart(m_digiclopsContext);
00110
00111
00112 triclopsSetResolution(m_triclopsContext, m_nImageHeight, m_nImageWidth);
00113
00114 return true;
00115 }
00116
00117 void CTriclopsCapture::CloseCamera()
00118 {
00119 if (m_digiclopsContext)
00120 {
00121 digiclopsDestroyContext(m_digiclopsContext);
00122 m_digiclopsContext = 0;
00123 }
00124
00125 if (m_triclopsContext)
00126 {
00127 triclopsDestroyContext(m_triclopsContext);
00128 m_triclopsContext = 0;
00129 }
00130 }
00131
00132 bool CTriclopsCapture::CaptureImage(CByteImage **ppImages)
00133 {
00134 if (!ppImages || !ppImages[0] || !ppImages[1] ||
00135 ppImages[0]->width != width || ppImages[0]->height != height ||
00136 ppImages[1]->width != width || ppImages[1]->height != height ||
00137 ppImages[0]->type != CByteImage::eRGB24 || ppImages[1]->type != CByteImage::eRGB24)
00138 return false;
00139
00140
00141 if (digiclopsGrabImage(m_digiclopsContext) != 0)
00142 return false;
00143
00144 digiclopsExtractTriclopsInput(m_digiclopsContext, LEFT_IMAGE, &m_colorDataLeft);
00145 digiclopsExtractTriclopsInput(m_digiclopsContext, RIGHT_IMAGE, &m_colorDataRight);
00146
00147 triclopsRectifyColorImage(m_triclopsContext, TriCam_LEFT, &m_colorDataLeft, &m_colorImageLeft);
00148 triclopsRectifyColorImage(m_triclopsContext, TriCam_RIGHT, &m_colorDataRight, &m_colorImageRight);
00149
00150 ConvertImages(ppImages);
00151
00152 return true;
00153 }
00154
00155 void CTriclopsCapture::ConvertImages(CByteImage **ppImages)
00156 {
00157 unsigned char *pLeftData = ppImages[0]->pixels;
00158 unsigned char *pRightData = ppImages[1]->pixels;
00159 unsigned char *pLeftRed = (unsigned char *) m_colorImageLeft.red;
00160 unsigned char *pLeftGreen = (unsigned char *) m_colorImageLeft.green;
00161 unsigned char *pLeftBlue = (unsigned char *) m_colorImageLeft.blue;
00162 unsigned char *pRightRed = (unsigned char *) m_colorImageRight.red;
00163 unsigned char *pRightGreen = (unsigned char *) m_colorImageRight.green;
00164 unsigned char *pRightBlue = (unsigned char *) m_colorImageRight.blue;
00165
00166 #ifdef __linux
00167 int offset = 0;
00168 #else
00169 int offset = 3 * (m_nImageWidth * m_nImageHeight - m_nImageWidth);
00170 #endif
00171
00172 for (int y = 0; y < m_nImageHeight; y++)
00173 {
00174 for (int x = 0; x < m_nImageWidth; x++, offset += 3)
00175 {
00176 pLeftData[offset] = pLeftRed[x];
00177 pLeftData[offset + 1] = pLeftGreen[x];
00178 pLeftData[offset + 2] = pLeftBlue[x];
00179 pRightData[offset] = pRightRed[x];
00180 pRightData[offset + 1] = pRightGreen[x];
00181 pRightData[offset + 2] = pRightBlue[x];
00182 }
00183
00184 pLeftRed += m_colorImageLeft.rowinc;
00185 pLeftGreen += m_colorImageLeft.rowinc;
00186 pLeftBlue += m_colorImageLeft.rowinc;
00187
00188 pRightRed += m_colorImageLeft.rowinc;
00189 pRightGreen += m_colorImageLeft.rowinc;
00190 pRightBlue += m_colorImageLeft.rowinc;
00191
00192 #ifndef __linux
00193 offset -= 6 * m_nImageWidth;
00194 #endif
00195 }
00196 }
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