• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 Huawei Technologies Co., Ltd
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 #ifndef TESTS_DATASET_UT_CORE_COMMON_DE_UT_BBOXOP_COMMON_H_
17 #define TESTS_DATASET_UT_CORE_COMMON_DE_UT_BBOXOP_COMMON_H_
18 
19 #include "cvop_common.h"
20 #include "minddata/dataset/util/path.h"
21 
22 namespace UT {
23 namespace CVOP {
24 namespace BBOXOP {
25 
26 class BBoxOpCommon : public CVOpCommon {
27  public:
28   enum FileType {
29     kExpected,
30     kActual
31   };
32 
33   BBoxOpCommon();
34 
35   ~BBoxOpCommon();
36 
37   /// \brief Sets up the class's variable, images_and_annotations
38   void SetUp() override;
39 
40   /// \brief Get all images and annotations in images_and_annotations TensorTable from dir
41   /// \param[in] dir directory containing images and annotation folders
42   /// \param[in] num_of_samples number of rows to fetch (default = 1)
43   void GetInputImagesAndAnnotations(const std::string &dir, std::size_t num_of_samples = 1);
44 
45   /// \brief Save the given tensor table
46   /// \param[in] type type of images to be stored (e.g. Expected or Actual)
47   /// \param[in] op_name name of op being tested
48   /// \param[in] table rows of images and corresponding annotations
49   void SaveImagesWithAnnotations(FileType type, const std::string &op_name, const TensorTable &table);
50 
51   /// \brief Compare actual and expected results. The images will have the bounding boxes on them
52   ///    Log if images don't match
53   /// \param[in] op_name name of op being tested
54   void CompareActualAndExpected(const std::string &op_name);
55 
56   /// \brief Load BBox data from an XML file into a Tensor
57   /// \param[in] path path to XML bbox data file
58   /// \param[in, out] target_BBox pointer to a Tensor to load
59   /// \return True if file loaded successfully, false if error -> logged to STD out
60   bool LoadAnnotationFile(const std::string &path, std::shared_ptr<Tensor> *target_BBox);
61 
62   TensorTable images_and_annotations_;
63 
64  private:
65   // directory of image_folder when the dataset/data gets transferred to build
66   std::string image_folder_build_;
67   // directory of image_folder in the source project (used to store expected results)
68   std::string image_folder_src_;
69 };
70 }  // namespace BBOXOP
71 }  // namespace CVOP
72 }  // namespace UT
73 
74 #endif  // TESTS_DATASET_UT_CORE_COMMON_DE_UT_BBOXOP_COMMON_H_
75