Scanner C++ API
frame.h
1 /* Copyright 2016 Carnegie Mellon University
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 
16 #pragma once
17 
18 #include "scanner/metadata.pb.h"
19 #include "scanner/util/common.h"
20 #include "scanner/util/profiler.h"
21 
22 #include <vector>
23 
24 namespace scanner {
25 
26 // Currently supports U8, U16, F32, F64
27 using proto::FrameType;
28 
29 size_t size_of_frame_type(FrameType type);
30 
31 const i32 FRAME_DIMS = 3;
32 
34 struct FrameInfo {
35  FrameInfo() = default;
36  FrameInfo(const FrameInfo& info) = default;
37  FrameInfo(FrameInfo&& info) = default;
38  FrameInfo& operator=(const FrameInfo&) = default;
39 
40  FrameInfo(int shape0, int shape1, int shape2, FrameType type);
41  FrameInfo(const std::vector<int> shapes, FrameType type);
42 
43  bool operator==(const FrameInfo& other) const;
44  bool operator!=(const FrameInfo& other) const;
45 
46  size_t size() const;
47 
49  int width() const;
50 
52  int height() const;
53 
55  int channels() const;
56 
57  int shape[FRAME_DIMS];
58  FrameType type;
59 };
60 
62 class Frame {
63  public:
64  Frame(FrameInfo info, u8* buffer);
65 
66  FrameInfo as_frame_info() const;
67 
68  size_t size() const;
69 
71  int width() const;
72 
74  int height() const;
75 
77  int channels() const;
78 
79  int shape[FRAME_DIMS];
80  FrameType type;
81  u8* data;
82 };
83 
84 Frame* new_frame(DeviceHandle device, FrameInfo info);
85 
86 void delete_frame(DeviceHandle device, u8* buffer);
87 
88 std::vector<Frame*> new_frames(DeviceHandle device, FrameInfo info, i32 num);
89 }
int height() const
Only valid when the dimensions are (height, width, channels)
Definition: frame.cpp:83
int width() const
Only valid when the dimensions are (height, width, channels)
Definition: frame.cpp:81
Frame.
Definition: frame.h:62
Definition: common.h:53
Definition: database.cpp:36
FrameInfo.
Definition: frame.h:34
int channels() const
Only valid when the dimensions are (height, width, channels)
Definition: frame.cpp:86