-
Notifications
You must be signed in to change notification settings - Fork 2
/
fastorb.cpp
79 lines (65 loc) · 2.69 KB
/
fastorb.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "arm_compute/runtime/NEON/NEFunctions.h"
#include "arm_compute/runtime/NEON/NEScheduler.h"
#include "arm_compute/core/Types.h"
#include "utils/ImageLoader.h"
//#include "utils/Utils.h"
//using namespace arm_compute;
//using namespace utils;
int main(int argc, char **argv)
{
arm_compute::utils::PPMLoader ppm;
arm_compute::Image src{};
arm_compute::Pyramid dst{};
arm_compute::NEGaussianPyramidOrb scale{};
std::string output_filename{};
std::cout << "threads " << arm_compute::NEScheduler::get().num_threads() << std::endl;
std::cout << "suggest " << arm_compute::NEScheduler::get().num_threads_hint() << " threads" << std::endl;
arm_compute::NEScheduler::get().set_num_threads(4);
std::cout << "threads " << arm_compute::NEScheduler::get().num_threads() << std::endl;
if(argc < 2)
{
// Print help
std::cout << "Usage: ./build/neon_scale[input_image.ppm]\n\n";
std::cout << "No input_image provided, creating a dummy 640x480 image\n";
// Create an empty grayscale 640x480 image
src.allocator()->init(arm_compute::TensorInfo(640, 480, arm_compute::Format::U8));
}
else
{
ppm.open(argv[1]);
ppm.init_image(src, arm_compute::Format::U8);
}
constexpr int scale_factor = 2;
//arm_compute::TensorInfo dst_tensor_info(src.info()->dimension(0) / scale_factor, src.info()->dimension(1) / scale_factor,
// arm_compute::Format::U8);
arm_compute::PyramidInfo dst_info(4, 1.2, src.info()->dimension(0), src.info()->dimension(1), arm_compute::Format::U8);
// Configure the destination image
//dst.allocator()->init(dst_tensor_info);
dst.init(dst_info);
// Configure Scale function object:
scale.configure(&src, &dst, arm_compute::BorderMode::UNDEFINED, 16);
// Allocate all the images
src.allocator()->allocate();
//dst.allocator()->allocate();
dst.allocate();
// Fill the input image with the content of the PPM image if a filename was provided:
if(ppm.is_open())
{
ppm.fill_image(src);
output_filename = std::string(argv[1]) + "_out.ppm";
}
std::clock_t begin = std::clock();
// Run the scale operation:
const int LOOP = 1000;
for (int i = 0; i < LOOP; ++i) {
scale.run();
}
std::clock_t end = std::clock();
std::cout << "CPU Time: " << (end - begin) / ((double)(CLOCKS_PER_SEC / 1000) * 100) << " ms" << std::endl;
// Save the result to file:
if(!output_filename.empty())
{
arm_compute::Tensor * t = dst.get_pyramid_level(0);
arm_compute::utils::save_to_ppm((*t), output_filename); // save_to_ppm maps and unmaps the image to store as PPM
}
}