aboutsummaryrefslogtreecommitdiff
path: root/examples/neon_cartoon_effect.cpp
diff options
context:
space:
mode:
authorMichalis Spyrou <michalis.spyrou@arm.com>2018-01-10 14:08:50 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:43:10 +0000
commit2b5f0f2574551f59970bb9d710bafad2bc4bbd4a (patch)
treefd586f56b1285f0d6c52ecefc174eba0a9c8f157 /examples/neon_cartoon_effect.cpp
parent571b18a1fca4a5ed4dd24a38cb619f4de43ba3ed (diff)
downloadComputeLibrary-2b5f0f2574551f59970bb9d710bafad2bc4bbd4a.tar.gz
COMPMID-782 Port examples to the new format
Change-Id: Ib178a97c080ff650094d02ee49e2a0aa22376dd0 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/115717 Reviewed-by: Anthony Barbier <anthony.barbier@arm.com> Tested-by: Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'examples/neon_cartoon_effect.cpp')
-rw-r--r--examples/neon_cartoon_effect.cpp109
1 files changed, 59 insertions, 50 deletions
diff --git a/examples/neon_cartoon_effect.cpp b/examples/neon_cartoon_effect.cpp
index 0ecd9410a1..da8ce3f84f 100644
--- a/examples/neon_cartoon_effect.cpp
+++ b/examples/neon_cartoon_effect.cpp
@@ -30,67 +30,76 @@
using namespace arm_compute;
using namespace utils;
-void main_neon_cartoon_effect(int argc, char **argv)
+class NEONCartoonEffectExample : public Example
{
- // Open PPM file
- PPMLoader ppm;
- Image src_img;
- Image dst_img;
- Image gaus5x5_img;
- Image canny_edge_img;
-
- if(argc < 2)
- {
- // Print help
- std::cout << "Usage: ./build/neon_cartoon_effect [input_image.ppm]\n\n";
- std::cout << "No input_image provided, creating a dummy 640x480 image\n";
- // Create an empty grayscale 640x480 image
- src_img.allocator()->init(TensorInfo(640, 480, Format::U8));
- }
- else
+public:
+ void do_setup(int argc, char **argv) override
{
- ppm.open(argv[1]);
- ppm.init_image(src_img, Format::U8);
- }
+ // Open PPM file
+ PPMLoader ppm;
- // Initialize just the dimensions and format of the images:
- gaus5x5_img.allocator()->init(*src_img.info());
- canny_edge_img.allocator()->init(*src_img.info());
- dst_img.allocator()->init(*src_img.info());
+ if(argc < 2)
+ {
+ // Print help
+ std::cout << "Usage: ./build/neon_cartoon_effect [input_image.ppm]\n\n";
+ std::cout << "No input_image provided, creating a dummy 640x480 image\n";
+ // Create an empty grayscale 640x480 image
+ src_img.allocator()->init(TensorInfo(640, 480, Format::U8));
+ }
+ else
+ {
+ ppm.open(argv[1]);
+ ppm.init_image(src_img, Format::U8);
+ }
- NEGaussian5x5 gaus5x5;
- NECannyEdge canny_edge;
- NEArithmeticSubtraction sub;
+ // Initialize just the dimensions and format of the images:
+ gaus5x5_img.allocator()->init(*src_img.info());
+ canny_edge_img.allocator()->init(*src_img.info());
+ dst_img.allocator()->init(*src_img.info());
- // Configure the functions to call
- gaus5x5.configure(&src_img, &gaus5x5_img, BorderMode::REPLICATE);
- canny_edge.configure(&src_img, &canny_edge_img, 100, 80, 3, 1, BorderMode::REPLICATE);
- sub.configure(&gaus5x5_img, &canny_edge_img, &dst_img, ConvertPolicy::SATURATE);
+ // Configure the functions to call
+ gaus5x5.configure(&src_img, &gaus5x5_img, BorderMode::REPLICATE);
+ canny_edge.configure(&src_img, &canny_edge_img, 100, 80, 3, 1, BorderMode::REPLICATE);
+ sub.configure(&gaus5x5_img, &canny_edge_img, &dst_img, ConvertPolicy::SATURATE);
- // Now that the padding requirements are known we can allocate the images:
- src_img.allocator()->allocate();
- dst_img.allocator()->allocate();
- gaus5x5_img.allocator()->allocate();
- canny_edge_img.allocator()->allocate();
+ // Now that the padding requirements are known we can allocate the images:
+ src_img.allocator()->allocate();
+ dst_img.allocator()->allocate();
+ gaus5x5_img.allocator()->allocate();
+ canny_edge_img.allocator()->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_img);
+ // Fill the input image with the content of the PPM image if a filename was provided:
+ if(ppm.is_open())
+ {
+ ppm.fill_image(src_img);
+ output_filename = std::string(argv[1]) + "_out.ppm";
+ }
}
- // Execute the functions:
- gaus5x5.run();
- canny_edge.run();
- sub.run();
+ void do_run() override
+ {
+ // Execute the functions:
+ gaus5x5.run();
+ canny_edge.run();
+ sub.run();
+ }
- // Save the result to file:
- if(ppm.is_open())
+ void do_teardown() override
{
- const std::string output_filename = std::string(argv[1]) + "_out.ppm";
- save_to_ppm(dst_img, output_filename);
+ // Save the result to file:
+ if(!output_filename.empty())
+ {
+ save_to_ppm(dst_img, output_filename); // save_to_ppm maps and unmaps the image to store as PPM
+ }
}
-}
+
+private:
+ Image src_img{}, dst_img{}, gaus5x5_img{}, canny_edge_img{};
+ NEGaussian5x5 gaus5x5{};
+ NECannyEdge canny_edge{};
+ NEArithmeticSubtraction sub{};
+ std::string output_filename{};
+};
/** Main program for cartoon effect test
*
@@ -99,5 +108,5 @@ void main_neon_cartoon_effect(int argc, char **argv)
*/
int main(int argc, char **argv)
{
- return utils::run_example(argc, argv, main_neon_cartoon_effect);
+ return utils::run_example<NEONCartoonEffectExample>(argc, argv);
}