Apollo 11.0
自动驾驶开放平台
frame_list.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16#pragma once
17
18#include <memory>
19#include <string>
20#include <vector>
21
22#include "Eigen/Core"
23
26
27namespace apollo {
28namespace perception {
29namespace camera {
30
31struct alignas(16) PatchIndicator {
32 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
34 frame_id = patch_id = -1;
35 sensor_name = "";
36 }
37
39 this->frame_id = frame_id;
40 this->patch_id = patch_id;
41 sensor_name = "";
42 }
43 PatchIndicator(int frame_id, int patch_id, const std::string &sensor_name) {
44 this->frame_id = frame_id;
45 this->patch_id = patch_id;
46 this->sensor_name = sensor_name;
47 }
48 bool operator==(const PatchIndicator &indicator) {
49 return (frame_id == indicator.frame_id && patch_id == indicator.patch_id);
50 }
51
52 std::string to_string() const {
53 std::stringstream str;
54 str << sensor_name << " | " << frame_id << " (" << patch_id << ")";
55 return str.str();
56 }
57
60 std::string sensor_name;
61};
62
63struct alignas(16) SimilarMap {
64 public:
65 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
66 bool Init(int dim, int gpu_id = 0, int init_size = 128) {
67 if (dim == 0) {
68 return false;
69 }
70
72
73 this->dim = dim;
74 map_sim.resize(dim);
75 for (int i = 0; i < dim; ++i) {
76 map_sim[i].resize(dim);
77 for (int j = 0; j < dim; ++j) {
78 map_sim[i][j].reset(new base::Blob<float>);
79 map_sim[i][j]->Reshape({init_size, init_size});
80 // allocate CPU/GPU memory
81 map_sim[i][j]->cpu_data();
82 map_sim[i][j]->gpu_data();
83 }
84 }
85 return true;
86 }
87
88 void set(int frame1, int frame2, std::shared_ptr<base::Blob<float>> sim) {
89 map_sim[frame1 % dim][frame2 % dim] = sim;
90 }
91
92 const std::shared_ptr<base::Blob<float>> get(int frame1, int frame2) const {
93 return map_sim[frame1 % dim][frame2 % dim];
94 }
95
96 float sim(const PatchIndicator &p1, const PatchIndicator &p2) const {
97 auto blob = get(p1.frame_id, p2.frame_id);
98 return *(blob->cpu_data() + blob->offset(p1.patch_id, p2.patch_id));
99 }
100
101 std::vector<std::vector<std::shared_ptr<base::Blob<float>>>> map_sim;
102 int dim;
103};
104
105} // namespace camera
106} // namespace perception
107} // namespace apollo
A wrapper around SyncedMemory holders serving as the basic computational unit for images,...
Definition blob.h:88
static bool set_device_id(int device_id)
for dynamic models (perfect model excluded)
class register implement
Definition arena_queue.h:37
PatchIndicator(int frame_id, int patch_id, const std::string &sensor_name)
Definition frame_list.h:43
EIGEN_MAKE_ALIGNED_OPERATOR_NEW PatchIndicator()
Definition frame_list.h:33
bool operator==(const PatchIndicator &indicator)
Definition frame_list.h:48
PatchIndicator(int frame_id, int patch_id)
Definition frame_list.h:38
void set(int frame1, int frame2, std::shared_ptr< base::Blob< float > > sim)
Definition frame_list.h:88
std::vector< std::vector< std::shared_ptr< base::Blob< float > > > > map_sim
Definition frame_list.h:101
float sim(const PatchIndicator &p1, const PatchIndicator &p2) const
Definition frame_list.h:96
const std::shared_ptr< base::Blob< float > > get(int frame1, int frame2) const
Definition frame_list.h:92
EIGEN_MAKE_ALIGNED_OPERATOR_NEW bool Init(int dim, int gpu_id=0, int init_size=128)
Definition frame_list.h:66