libvisiontransfer
10.8.0
visiontransfer
imageset-opencv.h
1
/*******************************************************************************
2
* Copyright (c) 2024 Allied Vision Technologies GmbH
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a copy
5
* of this software and associated documentation files (the "Software"), to deal
6
* in the Software without restriction, including without limitation the rights
7
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
* copies of the Software, and to permit persons to whom the Software is
9
* furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice shall be included in
12
* all copies or substantial portions of the Software.
13
*******************************************************************************/
14
15
#ifndef VISIONTRANSFER_IMAGESET_OPENCV_H
16
#define VISIONTRANSFER_IMAGESET_OPENCV_H
17
18
#ifdef CV_MAJOR_VERSION
19
20
namespace
visiontransfer {
21
22
/*
23
* OpenCV-specific implementations that need to be inlined in order to avoid
24
* dependencies for projects that do not make use of OpenCV
25
*/
26
27
inline
void
ImageSet::toOpenCVImage
(
int
imageNumber, cv::Mat& dest,
bool
convertRgbToBgr) {
28
assert(imageNumber >= 0 && imageNumber <
getNumberOfImages
());
29
30
switch
(
getPixelFormat
(imageNumber)) {
31
case
ImageSet::FORMAT_12_BIT_MONO
:
32
dest= cv::Mat_<unsigned short>(
getHeight
(),
getWidth
(),
33
reinterpret_cast<
unsigned
short
*
>
(
getPixelData
(imageNumber)),
getRowStride
(imageNumber));
34
break
;
35
case
ImageSet::FORMAT_8_BIT_MONO
:
36
dest = cv::Mat_<unsigned char>(
getHeight
(),
getWidth
(),
37
getPixelData
(imageNumber),
getRowStride
(imageNumber));
38
break
;
39
case
ImageSet::FORMAT_8_BIT_RGB
:
40
dest = cv::Mat_<cv::Vec3b>(
getHeight
(),
getWidth
(),
41
reinterpret_cast<
cv::Vec3b*
>
(
getPixelData
(imageNumber)),
getRowStride
(imageNumber));
42
if
(convertRgbToBgr) {
43
cv::cvtColor(dest, dest, cv::COLOR_RGB2BGR);
44
}
45
break
;
46
}
47
}
48
49
}
// namespace
50
51
#endif
52
#endif
visiontransfer::ImageSet::getHeight
int getHeight() const
Returns the height of each image.
Definition:
imageset.cpp:533
visiontransfer::ImageSet::toOpenCVImage
void toOpenCVImage(int imageNumber, cv::Mat &dest, bool convertRgbToBgr=true)
Converts one image of the set to an OpenCV image.
Definition:
imageset-opencv.h:39
visiontransfer::ImageSet::getWidth
int getWidth() const
Returns the width of each image.
Definition:
imageset.cpp:529
visiontransfer::ImageSet::getRowStride
int getRowStride(int imageNumber) const
Returns the row stride for the pixel data of one image.
Definition:
imageset.cpp:537
visiontransfer::ImageSet::getNumberOfImages
int getNumberOfImages() const
Returns the number of images in this set.
Definition:
imageset.cpp:601
visiontransfer::ImageSet::getPixelData
unsigned char * getPixelData(int imageNumber) const
Returns the pixel data for the given image.
Definition:
imageset.cpp:553
visiontransfer::ImageSet::FORMAT_8_BIT_RGB
@ FORMAT_8_BIT_RGB
8-bit RGB format
Definition:
imageset.h:79
visiontransfer::ImageSet::FORMAT_12_BIT_MONO
@ FORMAT_12_BIT_MONO
Definition:
imageset.h:83
visiontransfer::ImageSet::FORMAT_8_BIT_MONO
@ FORMAT_8_BIT_MONO
8-bit greyscale format
Definition:
imageset.h:76
visiontransfer::ImageSet::getPixelFormat
ImageFormat getPixelFormat(int imageNumber) const
Returns the pixel format for the given image.
Definition:
imageset.cpp:545
Allied Vision