Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | bcfd09a | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | #ifndef ARM_COMPUTE_GC /* Needed by Utils.cpp to handle OpenGL ES exceptions properly */ |
| 26 | #error "This example needs to be built with -DARM_COMPUTE_GC" |
| 27 | #endif /* ARM_COMPUTE_GC */ |
| 28 | |
| 29 | #include "arm_compute/core/Types.h" |
| 30 | #include "arm_compute/runtime/GLES_COMPUTE/GCFunctions.h" |
| 31 | #include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h" |
Georgios Pinitas | 7c3b924 | 2018-06-21 19:01:25 +0100 | [diff] [blame] | 32 | #include "utils/ImageLoader.h" |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 33 | #include "utils/Utils.h" |
| 34 | |
| 35 | using namespace arm_compute; |
| 36 | using namespace utils; |
| 37 | |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 38 | class GCAbsDiffExample : public Example |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 39 | { |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 40 | public: |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 41 | bool do_setup(int argc, char **argv) override |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 42 | { |
Michalis Spyrou | bcfd09a | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 43 | PPMLoader ppm1{}; |
| 44 | PPMLoader ppm2{}; |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 45 | |
| 46 | GCScheduler::get().default_init(); |
| 47 | if(argc < 2) |
| 48 | { |
| 49 | // Print help |
| 50 | std::cout << "Usage: " << argv[0] << " [input0_image.ppm] [input1_image.ppm] \n\n"; |
| 51 | std::cout << "No input_image provided, creating two dummy 640x480 images\n"; |
| 52 | // Create two empty grayscale 640x480 images |
| 53 | src1.allocator()->init(TensorInfo(640, 480, Format::U8)); |
| 54 | src2.allocator()->init(TensorInfo(640, 480, Format::U8)); |
| 55 | } |
| 56 | else if(argc < 3) |
| 57 | { |
| 58 | // Print help |
| 59 | std::cout << "Usage: " << argv[0] << " [input0_image.ppm] [input1_image.ppm] \n\n"; |
| 60 | std::cout << "Only one input_image provided, creating a dummy 640x480 image\n"; |
| 61 | ppm1.open(argv[1]); |
| 62 | ppm1.init_image(src1, Format::U8); |
| 63 | // Create an empty grayscale 640x480 image |
| 64 | src2.allocator()->init(TensorInfo(640, 480, Format::U8)); |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | ppm1.open(argv[1]); |
| 69 | ppm1.init_image(src1, Format::U8); |
| 70 | ppm2.open(argv[2]); |
| 71 | ppm2.init_image(src2, Format::U8); |
| 72 | } |
| 73 | |
| 74 | // Configure the temporary and destination images |
| 75 | dst.allocator()->init(*src1.info()); |
| 76 | |
| 77 | absdiff.configure(&src1, &src2, &dst); |
| 78 | |
| 79 | // Allocate all the images |
| 80 | src1.allocator()->allocate(); |
| 81 | src2.allocator()->allocate(); |
| 82 | dst.allocator()->allocate(); |
| 83 | |
| 84 | // Fill the input image with the content of the PPM image if a filename was provided: |
| 85 | if(ppm1.is_open()) |
| 86 | { |
| 87 | ppm1.fill_image(src1); |
| 88 | output_filename = std::string(argv[1]) + "_out.ppm"; |
| 89 | } |
| 90 | if(ppm2.is_open()) |
| 91 | { |
| 92 | ppm2.fill_image(src2); |
| 93 | } |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 94 | |
| 95 | return true; |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 96 | } |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 97 | void do_run() override |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 98 | { |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 99 | // Execute the functions: |
| 100 | absdiff.run(); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 101 | } |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 102 | void do_teardown() override |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 103 | { |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 104 | // Save the result to file: |
| 105 | if(!output_filename.empty()) |
| 106 | { |
| 107 | // save_to_ppm maps and unmaps the image to store as PPM |
| 108 | // The GCTensor::map call inside the save_to_ppm will block until all pending operations on that image have completed |
| 109 | save_to_ppm(dst, output_filename); |
| 110 | } |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 113 | private: |
| 114 | GCImage src1{}, src2{}, dst{}; |
| 115 | GCAbsoluteDifference absdiff{}; |
| 116 | std::string output_filename{}; |
| 117 | }; |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 118 | |
| 119 | /** Main program for absdiff test |
| 120 | * |
| 121 | * @param[in] argc Number of arguments |
| 122 | * @param[in] argv Arguments ( [optional] Path to the first PPM image to process, [optional] Path the the second PPM image to process ) |
| 123 | */ |
Anthony Barbier | 6db0ff5 | 2018-01-05 10:59:12 +0000 | [diff] [blame] | 124 | int main(int argc, char **argv) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 125 | { |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 126 | return utils::run_example<GCAbsDiffExample>(argc, argv); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 127 | } |