VisionCpp  0.0.1
opencvinterop.hpp
Go to the documentation of this file.
1 // This file is part of VisionCpp, a lightweight C++ template library
2 // for computer vision and image processing.
3 //
4 // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved.
5 //
6 // Contact: visioncpp@codeplay.com
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 
20 /// \file opencvinterop.hpp
21 /// \brief This header gathers all interoperability with OpenCV operations.
22 
23 namespace visioncpp {
24 /// \struct OP_CVBGRToRGB
25 /// \brief This node is a utility node that does a conversion from cv::Mat (
26 /// unsigned char storage; channel order BGR ) to float with order of RGB
27 /// normalise from opencv format to VisionCpp internal format [0, 255] to
28 /// [0.0f, 1.0f]
29 struct OP_CVBGRToRGB {
30  /// \param in
31  /// \return F32C3
33  visioncpp::pixel::F32C3 out(static_cast<float>(in[2] / 255.0f),
34  static_cast<float>(in[1] / 255.0f),
35  static_cast<float>(in[0] / 255.0f));
36  return out;
37  }
38 };
39 
40 /// \struct OP_RGBToCVBGR
41 /// \brief This node is a utility node that does a conversion from float with
42 /// order of RGB to cv::Mat ( unsigned char storage; channel order BGR )
43 /// denormalise from VisionCpp base format ( \ref F32C3 ) to opencv 8UC3
44 /// (three channel unsigned char)
45 struct OP_RGBToCVBGR {
46  /// \param in
47  /// \return U8C3
49  visioncpp::pixel::U8C3 out(static_cast<unsigned char>(in[2] * 255.0f),
50  static_cast<unsigned char>(in[1] * 255.0f),
51  static_cast<unsigned char>(in[0] * 255.0f));
52  return out;
53  }
54 };
55 
56 /// \struct OP_GREYToCVBGR
57 /// \brief float between [0.0f, 1.0f] to [0, 255]
58 /// One channel GREY ( float ) is going to be converted to one channel cv::Mat
60  /// \param in
61  /// \return U8C1
62  unsigned char operator()(float in) {
63  return static_cast<unsigned char>(in * 255);
64  }
65 };
66 }
VisionCpp namespace.
Definition: sycl/device.hpp:24
This node is a utility node that does a conversion from cv::Mat ( unsigned char storage; channel orde...
visioncpp::pixel::F32C3 operator()(visioncpp::pixel::U8C3 in)
float between [0.0f, 1.0f] to [0, 255] One channel GREY ( float ) is going to be converted to one cha...
unsigned char operator()(float in)
This node is a utility node that does a conversion from float with order of RGB to cv::Mat ( unsigned...
visioncpp::pixel::U8C3 operator()(visioncpp::pixel::F32C3 in)