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 #include <new>
00042
00043 #include "ImageAccessCV.h"
00044 #include "IplImageAdaptor.h"
00045 #include "ByteImage.h"
00046
00047 #include <stdio.h>
00048
00049
00050
00051 bool ImageAccessCV::LoadFromFile(CByteImage *pImage, const char *pFilePath)
00052 {
00053 IplImage *pIplImage = cvLoadImage(pFilePath);
00054 if (!pIplImage)
00055 return false;
00056
00057 if (pIplImage->nChannels != 3 && pIplImage->nChannels != 1)
00058 {
00059 cvReleaseImage(&pIplImage);
00060 return false;
00061 }
00062
00063 if (pImage->pixels && pImage->m_bOwnMemory)
00064 delete [] pImage->pixels;
00065
00066 pImage->type = pIplImage->nChannels == 1 ? CByteImage::eGrayScale : CByteImage::eRGB24;
00067 pImage->width = pIplImage->width;
00068 pImage->height = pIplImage->height;
00069 pImage->bytesPerPixel = pIplImage->nChannels;
00070 pImage->pixels = new unsigned char[pImage->width * pImage->height * pImage->bytesPerPixel];
00071 pImage->m_bOwnMemory = true;
00072
00073 const int nPaddingBytes = pIplImage->widthStep - pImage->bytesPerPixel * pIplImage->width;
00074 const unsigned char *input = (unsigned char *) pIplImage->imageData;
00075 unsigned char *output = pImage->pixels;
00076 const int width = pImage->width;
00077 const int height = pImage->height;
00078
00079 if (pImage->type == CByteImage::eGrayScale)
00080 {
00081 for (int y = 0, i_input = 0, i_output = 0; y < height; y++, i_input += nPaddingBytes)
00082 {
00083 for (int x = 0; x < width; x++, i_input++, i_output++)
00084 output[i_output] = input[i_input];
00085 }
00086 }
00087 else if (pImage->type == CByteImage::eRGB24)
00088 {
00089 for (int y = 0, i_input = 0, i_output = 0; y < height; y++, i_input += nPaddingBytes)
00090 {
00091 for (int x = 0; x < width; x++, i_input += 3, i_output += 3)
00092 {
00093 output[i_output] = input[i_input + 2];
00094 output[i_output + 1] = input[i_input + 1];
00095 output[i_output + 2] = input[i_input];
00096 }
00097 }
00098 }
00099 else
00100 {
00101 printf("error: CByteImage::eRGB24Split not supported by ImageAccessCV::LoadFromFile\n");
00102 }
00103
00104 cvReleaseImage(&pIplImage);
00105
00106 return true;
00107 }
00108
00109
00110 bool ImageAccessCV::SaveToFile(const CByteImage *pImage, const char *pFilePath)
00111 {
00112 int nRet;
00113
00114 if (pImage->type == CByteImage::eGrayScale)
00115 {
00116 IplImage *pIplImage = IplImageAdaptor::Adapt(pImage);
00117 nRet = cvSaveImage(pFilePath, pIplImage);
00118 cvReleaseImageHeader(&pIplImage);
00119 }
00120 else if (pImage->type == CByteImage::eRGB24)
00121 {
00122 const int width = pImage->width;
00123 const int height = pImage->height;
00124 const int nBytes = width * height * 3;
00125
00126 CByteImage tempImage(width, height, pImage->type);
00127
00128 const unsigned char *input = pImage->pixels;
00129 unsigned char *output = tempImage.pixels;
00130
00131 for (int i = 0; i < nBytes; i += 3)
00132 {
00133 output[i] = input[i + 2];
00134 output[i + 1] = input[i + 1];
00135 output[i + 2] = input[i];
00136 }
00137
00138 IplImage *pIplImage = IplImageAdaptor::Adapt(&tempImage);
00139 nRet = cvSaveImage(pFilePath, pIplImage);
00140 cvReleaseImageHeader(&pIplImage);
00141 }
00142 else
00143 {
00144 printf("error: CByteImage::eRGB24Split not supported by ImageAccessCV::SaveToFile\n");
00145 }
00146
00147
00148 return nRet != 0;
00149 }
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