39 #include <visp3/core/vpConfig.h>
40 #include <visp3/core/vpImageConvert.h>
42 #if defined(VISP_HAVE_SIMDLIB)
43 #include <Simd/SimdLib.h>
46 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC)
95 dest.
resize(
static_cast<unsigned int>(src.rows),
static_cast<unsigned int>(src.cols));
96 unsigned int destRows = dest.
getRows();
97 unsigned int destCols = dest.
getCols();
98 const unsigned int index_0 = 0;
99 const unsigned int index_1 = 1;
100 const unsigned int index_2 = 2;
101 const unsigned int index_3 = 3;
102 if (src.type() == CV_8UC4) {
104 for (
unsigned int i = 0; i < destRows; ++i)
105 for (
unsigned int j = 0; j < destCols; ++j) {
106 cv::Vec4b tmp = src.at<cv::Vec4b>(
static_cast<int>(i),
static_cast<int>(j));
107 rgbaVal.
R = tmp[index_2];
108 rgbaVal.
G = tmp[index_1];
109 rgbaVal.
B = tmp[index_0];
110 rgbaVal.
A = tmp[index_3];
112 dest[destRows - i - 1][j] = rgbaVal;
115 dest[i][j] = rgbaVal;
119 else if (src.type() == CV_8UC3) {
120 #if defined(VISP_HAVE_SIMDLIB)
121 if (src.isContinuous() && (!flip)) {
122 SimdRgbToBgra(src.data, src.cols, src.rows, src.step[0],
reinterpret_cast<uint8_t *
>(dest.
bitmap),
129 for (
unsigned int i = 0; i < destRows; ++i) {
130 for (
unsigned int j = 0; j < destCols; ++j) {
131 cv::Vec3b tmp = src.at<cv::Vec3b>(
static_cast<int>(i),
static_cast<int>(j));
132 rgbaVal.
R = tmp[index_2];
133 rgbaVal.
G = tmp[index_1];
134 rgbaVal.
B = tmp[index_0];
136 dest[destRows - i - 1][j] = rgbaVal;
139 dest[i][j] = rgbaVal;
143 #if defined(VISP_HAVE_SIMDLIB)
147 else if (src.type() == CV_8UC1) {
148 #if defined(VISP_HAVE_SIMDLIB)
149 if (src.isContinuous() && (!flip)) {
150 SimdGrayToBgra(src.data, src.cols, src.rows, src.step[0],
reinterpret_cast<uint8_t *
>(dest.
bitmap),
156 for (
unsigned int i = 0; i < destRows; ++i) {
157 for (
unsigned int j = 0; j < destCols; ++j) {
158 rgbaVal = src.at<
unsigned char>(
static_cast<int>(i),
static_cast<int>(j));
161 dest[destRows - i - 1][j] = rgbaVal;
164 dest[i][j] = rgbaVal;
168 #if defined(VISP_HAVE_SIMDLIB)
215 if (src.type() == CV_8UC1) {
216 dest.
resize(
static_cast<unsigned int>(src.rows),
static_cast<unsigned int>(src.cols));
217 unsigned int destRows = dest.
getRows();
218 unsigned int destCols = dest.
getCols();
219 if (src.isContinuous() && (!flip)) {
220 memcpy(dest.
bitmap, src.data,
static_cast<size_t>(src.rows * src.cols));
224 for (
unsigned int i = 0; i < destRows; ++i) {
225 memcpy(dest.
bitmap + (i * destCols), src.data + ((destRows - i - 1) * src.step1()),
static_cast<size_t>(src.step));
229 for (
unsigned int i = 0; i < destRows; ++i) {
230 memcpy(dest.
bitmap + (i * destCols), src.data + (i * src.step1()),
static_cast<size_t>(src.step));
235 else if (src.type() == CV_8UC3) {
236 dest.
resize(
static_cast<unsigned int>(src.rows),
static_cast<unsigned int>(src.cols));
237 unsigned int destRows = dest.
getRows();
238 unsigned int destCols = dest.
getCols();
239 if (src.isContinuous()) {
240 BGRToGrey((
unsigned char *)src.data, (
unsigned char *)dest.
bitmap,
static_cast<unsigned int>(src.cols),
static_cast<unsigned int>(src.rows),
245 for (
unsigned int i = 0; i < destRows; ++i) {
246 BGRToGrey((
unsigned char *)src.data + (i * src.step1()),
247 (
unsigned char *)dest.
bitmap + ((destRows - i - 1) * destCols),
248 static_cast<unsigned int>(destCols), 1,
false);
252 for (
unsigned int i = 0; i < destRows; ++i) {
253 BGRToGrey((
unsigned char *)src.data + (i * src.step1()), (
unsigned char *)dest.
bitmap + (i * destCols),
254 static_cast<unsigned int>(destCols), 1,
false);
259 else if (src.type() == CV_8UC4) {
260 dest.
resize(
static_cast<unsigned int>(src.rows),
static_cast<unsigned int>(src.cols));
261 unsigned int destRows = dest.
getRows();
262 unsigned int destCols = dest.
getCols();
263 if (src.isContinuous()) {
264 BGRaToGrey((
unsigned char *)src.data, (
unsigned char *)dest.
bitmap,
static_cast<unsigned int>(src.cols),
265 static_cast<unsigned int>(src.rows), flip, nThreads);
269 for (
unsigned int i = 0; i < destRows; ++i) {
270 BGRaToGrey((
unsigned char *)src.data + (i * src.step1()),
271 (
unsigned char *)dest.
bitmap + ((destRows - i - 1) * destCols),
272 static_cast<unsigned int>(destCols), 1,
false);
276 for (
unsigned int i = 0; i < destRows; ++i) {
277 BGRaToGrey((
unsigned char *)src.data + (i * src.step1()), (
unsigned char *)dest.
bitmap + (i * destCols),
278 static_cast<unsigned int>(destCols), 1,
false);
294 dest.
resize(
static_cast<unsigned int>(src.rows),
static_cast<unsigned int>(src.cols));
295 unsigned int destRows = dest.
getRows();
296 unsigned int destCols = dest.
getCols();
298 if (src.type() == CV_32FC1) {
299 for (
unsigned int i = 0; i < destRows; ++i) {
300 for (
unsigned int j = 0; j < destCols; ++j) {
302 dest[dest.
getRows() - i - 1][j] = src.at<
float>(
static_cast<int>(i),
static_cast<int>(j));
305 dest[i][j] = src.at<
float>(
static_cast<int>(i),
static_cast<int>(j));
310 else if (src.type() == CV_16SC1) {
311 for (
unsigned int i = 0; i < destRows; ++i) {
312 for (
unsigned int j = 0; j < destCols; ++j) {
314 dest[dest.
getRows() - i - 1][j] = src.at<
short>(
static_cast<int>(i),
static_cast<int>(j));
317 dest[i][j] = src.at<
short>(
static_cast<int>(i),
static_cast<int>(j));
338 unsigned int nbRows =
static_cast<unsigned int>(src.rows);
339 unsigned int nbCols =
static_cast<unsigned int>(src.cols);
340 dest.
resize(nbRows, nbCols);
341 for (
unsigned int i = 0; i < nbRows; ++i) {
342 for (
unsigned int j = 0; j < nbCols; ++j) {
343 dest[i][j] = I_float[i][j];
357 dest.
resize(
static_cast<unsigned int>(src.rows),
static_cast<unsigned int>(src.cols));
358 unsigned int destRows = dest.
getRows();
359 unsigned int destCols = dest.
getCols();
361 if (src.type() == CV_16UC1) {
362 if (src.isContinuous()) {
363 memcpy(dest.
bitmap, src.data,
static_cast<size_t>(src.rows * src.cols) *
sizeof(uint16_t));
367 for (
unsigned int i = 0; i < destRows; ++i) {
368 memcpy(dest.
bitmap + (i * destCols), src.data + ((destRows - i - 1) * src.step1() *
sizeof(uint16_t)),
static_cast<size_t>(src.step));
372 for (
unsigned int i = 0; i < destRows; ++i) {
373 memcpy(dest.
bitmap + (i * destCols), src.data + (i * src.step1() *
sizeof(uint16_t)),
static_cast<size_t>(src.step));
392 dest.
resize(
static_cast<unsigned int>(src.rows),
static_cast<unsigned int>(src.cols));
393 unsigned int destRows = dest.
getRows();
394 unsigned int destCols = dest.
getCols();
395 const unsigned int index_0 = 0;
396 const unsigned int index_1 = 1;
397 const unsigned int index_2 = 2;
399 if (src.type() == CV_32FC3) {
401 for (
unsigned int i = 0; i < destRows; ++i)
402 for (
unsigned int j = 0; j < destCols; ++j) {
403 cv::Vec3f tmp = src.at<cv::Vec3f>(
static_cast<int>(i),
static_cast<int>(j));
404 rgbVal.
R = tmp[index_2];
405 rgbVal.
G = tmp[index_1];
406 rgbVal.
B = tmp[index_0];
408 dest[destRows - i - 1][j] = rgbVal;
462 cv::Mat vpToMat(
static_cast<int>(src.
getRows()),
static_cast<int>(src.
getCols()), CV_8UC4, (
void *)src.
bitmap);
463 cv::cvtColor(vpToMat, dest, cv::COLOR_RGBA2BGR);
511 cv::Mat tmpMap(
static_cast<int>(src.
getRows()),
static_cast<int>(src.
getCols()), CV_8UC1, (
void *)src.
bitmap);
512 dest = tmpMap.clone();
515 dest = cv::Mat(
static_cast<int>(src.
getRows()),
static_cast<int>(src.
getCols()), CV_8UC1, (
void *)src.
bitmap);
522 cv::Mat tmpMap(
static_cast<int>(src.
getRows()),
static_cast<int>(src.
getCols()), CV_32FC1, (
void *)src.
bitmap);
523 dest = tmpMap.clone();
526 dest = cv::Mat(
static_cast<int>(src.
getRows()),
static_cast<int>(src.
getCols()), CV_32FC1, (
void *)src.
bitmap);
532 unsigned int nbRows = src.
getRows();
533 unsigned int nbCols = src.
getCols();
535 for (
unsigned int i = 0; i < nbRows; ++i) {
536 for (
unsigned int j = 0; j < nbCols; ++j) {
537 I_float[i][j] =
static_cast<float>(src[i][j]);
540 convert(I_float, dest, copyData);
545 cv::Mat vpToMat(
static_cast<int>(src.
getRows()),
static_cast<int>(src.
getCols()), CV_32FC3, (
void *)src.
bitmap);
546 cv::cvtColor(vpToMat, dest, cv::COLOR_RGB2BGR);
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void BGRaToGrey(unsigned char *bgra, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false, unsigned int nThreads=0)
static void BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false, unsigned int nThreads=0)
unsigned int getWidth() const
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
unsigned int getCols() const
Type * bitmap
points toward the bitmap
unsigned int getRows() const
unsigned char B
Blue component.
unsigned char R
Red component.
unsigned char G
Green component.
unsigned char A
Additionnal component.