AWViz-ROS
Loading...
Searching...
No Matches
collection_adapter.hpp
Go to the documentation of this file.
1// Copyright 2024 Kotaro Uetake.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef AWVIZ_PLUGIN__IMAGE__COLLECTION_ADAPTER_HPP_
16#define AWVIZ_PLUGIN__IMAGE__COLLECTION_ADAPTER_HPP_
17
18#include <opencv2/opencv.hpp>
19#include <rerun.hpp>
20#include <rerun/collection.hpp>
21
22#include <utility>
23#include <vector>
24
25namespace rerun
26{
30template <typename TElement>
31struct CollectionAdapter<TElement, cv::Mat>
32{
34 Collection<TElement> operator()(const cv::Mat & img)
35 {
36 return Collection<TElement>::borrow(
37 reinterpret_cast<TElement *>(img.data), img.total() * img.channels());
38 }
39
40 // Do a full copy for temporaries (otherwise the data might be deleted when the temporary is
41 // destroyed).
42 Collection<TElement> operator()(cv::Mat && img)
43 {
44 std::vector<TElement> img_vec(img.total() * img.channels());
45 img_vec.assign(img.data, img.data + img.total() * img.channels());
46 return Collection<TElement>::take_ownership(std::move(img_vec));
47 }
48};
49} // namespace rerun
50
51namespace awviz_plugin
52{
59inline rerun::Collection<rerun::TensorDimension> tensor_shape(const cv::Mat & img)
60{
61 return {
62 static_cast<size_t>(img.rows), static_cast<size_t>(img.cols),
63 static_cast<size_t>(img.channels())};
64}
65} // namespace awviz_plugin
66
67#endif // AWVIZ_PLUGIN__IMAGE__IMAGE_COMPRESSED_IMAGE_DISPLAY_HPP_
Definition: detected_objects_display.hpp:23
rerun::Collection< rerun::TensorDimension > tensor_shape(const cv::Mat &img)
Return image tensor shape as rerun::Collection.
Definition: collection_adapter.hpp:59
Definition: collection_adapter.hpp:26
Collection< TElement > operator()(cv::Mat &&img)
Definition: collection_adapter.hpp:42
Collection< TElement > operator()(const cv::Mat &img)
Borrow for non-temporary.
Definition: collection_adapter.hpp:34