10 #ifndef LIBALVISION_ALVISION_ALIMAGE_OPENCV_H_
11 #define LIBALVISION_ALVISION_ALIMAGE_OPENCV_H_
14 #include <opencv2/core/core.hpp>
16 #include <alerror/alerror.h>
29 static inline cv::Mat aLImageToCvMat(
const AL::ALImage & al_image,
int cv_type = -1)
33 unsigned char *data =
const_cast<unsigned char*
>(al_image.
getData());
41 if ((n_layers < 0) || (n_channels < 0)) {
43 ss <<
"Color space \"" << al_image.
getColorSpace() <<
"\" not supported";
44 throw AL::ALError(
"ALVision",
"aLImageToCvMat", ss.str());
47 switch (n_layers / n_channels)
60 ss <<
"Depth \"" << (n_layers / n_channels) <<
"\" not supported";
61 throw AL::ALError(
"ALVision",
"aLImageToCvMat", ss.str());
65 CV_MAKETYPE(cv_depth, n_channels), data);
74 static inline AL::ALImage* cvMatToALImage(
const cv::Mat & img,
int colorSpace,
75 float pLeftAngle = 0.0f,
float pTopAngle = 0.0f,
76 float pRightAngle = 0.0f,
float pBottomAngle = 0.0f)
80 throw AL::ALError(
"ALVision",
"cvMatToALImage",
81 "Channel number incompatibility between cv::Mat and colorSpace");
91 throw AL::ALError(
"ALVision",
"cvMatToALImage",
92 "Type incompatibility between cv::Mat and colorSpace");
97 pLeftAngle, pTopAngle, pRightAngle, pBottomAngle);
108 static inline AL::ALImage* cvMatToALImageCopy(
const cv::Mat & img,
110 float pLeftAngle = 0.0f,
float pTopAngle = 0.0f,
111 float pRightAngle = 0.0f,
float pBottomAngle = 0.0f)
115 throw AL::ALError(
"ALVision",
"cvMatToALImage",
116 "Channel number incompatibility between cv::Mat and colorSpace");
126 throw AL::ALError(
"ALVision",
"cvMatToALImage",
127 "Type incompatibility between cv::Mat and colorSpace");
131 size_t data_size = img.cols * img.rows * img.elemSize();
132 unsigned char *data =
new unsigned char[data_size];
133 std::memcpy(data, img.data, data_size);
137 pLeftAngle, pTopAngle, pRightAngle, pBottomAngle);
int getNumLayersInColorSpace(const int colorSpace)
Utility function that returns the number of layers for a given color space.
int getNumChannelsInColorSpace(const int colorSpace)
Utility function that returns the number of channels for a given color space.
const unsigned char * getData() const
return the reference to the image data.
void setData(unsigned char *pData)
set the image data pointer to point to the specified buffer.
int getColorSpace(void) const
int getHeight(void) const