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 #include "OpenCVCapture.h"
00043 #include "Image/ImageProcessor.h"
00044 #include "Image/ByteImage.h"
00045
00046
00047
00048
00049
00050
00051
00052 COpenCVCapture::COpenCVCapture(int nIndex, const char *pFilename) : m_nIndex(nIndex)
00053 {
00054 m_pCapture = 0;
00055 m_pIplImage = 0;
00056
00057 m_sFilename = "";
00058
00059 if (pFilename)
00060 m_sFilename += pFilename;
00061 }
00062
00063 COpenCVCapture::~COpenCVCapture()
00064 {
00065 CloseCamera();
00066 }
00067
00068
00069
00070
00071
00072
00073 bool COpenCVCapture::OpenCamera()
00074 {
00075 CloseCamera();
00076
00077 if (m_sFilename.length() > 0)
00078 m_pCapture = cvCaptureFromFile(m_sFilename.c_str());
00079 else
00080 m_pCapture = cvCaptureFromCAM(m_nIndex);
00081 if (!m_pCapture)
00082 return false;
00083
00084 cvSetCaptureProperty(m_pCapture, CV_CAP_PROP_FPS, 30);
00085 cvSetCaptureProperty(m_pCapture, CV_CAP_PROP_FRAME_WIDTH, 640);
00086 cvSetCaptureProperty(m_pCapture, CV_CAP_PROP_FRAME_HEIGHT, 480);
00087
00088 m_pIplImage = cvQueryFrame(m_pCapture);
00089
00090 return true;
00091 }
00092
00093 void COpenCVCapture::CloseCamera()
00094 {
00095 cvReleaseCapture(&m_pCapture);
00096 m_pIplImage = 0;
00097 }
00098
00099 bool COpenCVCapture::CaptureImage(CByteImage **ppImages)
00100 {
00101 m_pIplImage = cvQueryFrame(m_pCapture);
00102 if (!m_pIplImage)
00103 return false;
00104
00105 CByteImage *pImage = ppImages[0];
00106 if (!pImage || pImage->width != m_pIplImage->width || pImage->height != m_pIplImage->height)
00107 return false;
00108
00109 if (m_pIplImage->depth != IPL_DEPTH_8U)
00110 return false;
00111 else if (m_pIplImage->nChannels != 1 && m_pIplImage->nChannels != 3)
00112 return false;
00113 else if (m_pIplImage->nChannels == 1 && pImage->type != CByteImage::eGrayScale)
00114 return false;
00115 else if (m_pIplImage->nChannels == 3 && pImage->type != CByteImage::eRGB24)
00116 return false;
00117
00118 const int nBytes = pImage->width * pImage->height * pImage->bytesPerPixel;
00119 unsigned char *input = (unsigned char *) m_pIplImage->imageData;
00120 unsigned char *output = pImage->pixels;
00121
00122 if (pImage->type == CByteImage::eGrayScale)
00123 {
00124 memcpy(output, input, nBytes);
00125 }
00126 else if (pImage->type == CByteImage::eRGB24)
00127 {
00128 for (int i = 0; i < nBytes; i += 3)
00129 {
00130 output[i] = input[i + 2];
00131 output[i + 1] = input[i + 1];
00132 output[i + 2] = input[i];
00133 }
00134 }
00135
00136 #ifdef WIN32
00137 ImageProcessor::FlipY(pImage, pImage);
00138 #endif
00139
00140 return true;
00141 }
00142
00143
00144 int COpenCVCapture::GetWidth()
00145 {
00146 return m_pIplImage ? m_pIplImage->width : -1;
00147 }
00148
00149 int COpenCVCapture::GetHeight()
00150 {
00151 return m_pIplImage ? m_pIplImage->height : -1;
00152 }
00153
00154 CByteImage::ImageType COpenCVCapture::GetType()
00155 {
00156 return m_pIplImage ? (m_pIplImage->nChannels == 3 ? CByteImage::eRGB24 : CByteImage::eGrayScale) : (CByteImage::ImageType) -1;
00157 }
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