| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| |
| /*! |
| * Copyright (c) 2015 by Contributors |
| * \file image_augmenter.h |
| * \brief Interface of opencv based image augmenter |
| */ |
| #ifndef MXNET_IO_IMAGE_AUGMENTER_H_ |
| #define MXNET_IO_IMAGE_AUGMENTER_H_ |
| |
| #include <dmlc/registry.h> |
| |
| #if MXNET_USE_OPENCV |
| #include <opencv2/opencv.hpp> |
| #include <vector> // NOLINT(*) |
| #include <utility> // NOLINT(*) |
| #include <string> // NOLINT(*) |
| |
| #include "../common/utils.h" |
| |
| namespace mxnet { |
| namespace io { |
| /*! |
| * \brief OpenCV based Image augmenter, |
| * The augmenter can contain internal temp state. |
| */ |
| class ImageAugmenter { |
| public: |
| /*! |
| * \brief Initialize the Operator by setting the parameters |
| * This function need to be called before all other functions. |
| * \param kwargs the keyword arguments parameters |
| */ |
| virtual void Init(const std::vector<std::pair<std::string, std::string> >& kwargs) = 0; |
| /*! |
| * \brief augment src image. |
| * this function is not thread safe, and will only be called by one thread |
| * however, it will tries to re-use memory space as much as possible |
| * \param src the source image |
| * \param prnd pointer to random number generator. |
| * \return The processed image. |
| */ |
| virtual cv::Mat Process(const cv::Mat &src, std::vector<float> *label, |
| common::RANDOM_ENGINE *prnd) = 0; |
| // virtual destructor |
| virtual ~ImageAugmenter() {} |
| /*! |
| * \brief factory function |
| * \param name Name of the augmenter |
| * \return The created augmenter. |
| */ |
| static ImageAugmenter* Create(const std::string& name); |
| }; |
| |
| /*! \brief typedef the factory function of data iterator */ |
| typedef std::function<ImageAugmenter *()> ImageAugmenterFactory; |
| /*! |
| * \brief Registry entry for DataIterator factory functions. |
| */ |
| struct ImageAugmenterReg |
| : public dmlc::FunctionRegEntryBase<ImageAugmenterReg, |
| ImageAugmenterFactory> { |
| }; |
| //-------------------------------------------------------------- |
| // The following part are API Registration of Iterators |
| //-------------------------------------------------------------- |
| /*! |
| * \brief Macro to register image augmenter |
| * |
| * \code |
| * // example of registering a mnist iterator |
| * REGISTER_IMAGE_AUGMENTER(aug_default) |
| * .describe("default augmenter") |
| * .set_body([]() { |
| * return new DefaultAugmenter(); |
| * }); |
| * \endcode |
| */ |
| #define MXNET_REGISTER_IMAGE_AUGMENTER(name) \ |
| DMLC_REGISTRY_REGISTER(::mxnet::io::ImageAugmenterReg, ImageAugmenterReg, name) |
| } // namespace io |
| } // namespace mxnet |
| #endif // MXNET_USE_OPENCV |
| |
| namespace mxnet { |
| namespace io { |
| /*! \return the parameter of default augmenter */ |
| std::vector<dmlc::ParamFieldInfo> ListDefaultAugParams(); |
| std::vector<dmlc::ParamFieldInfo> ListDefaultDetAugParams(); |
| } // namespace io |
| } // namespace mxnet |
| #endif // MXNET_IO_IMAGE_AUGMENTER_H_ |