1 // This file is part of OpenCV project. 2 // It is subject to the license terms in the LICENSE file found in the top-level directory 3 // of this distribution and at http://opencv.org/license.html. 4 // 5 // 6 // License Agreement 7 // For Open Source Computer Vision Library 8 // 9 // Copyright(C) 2020, Huawei Technologies Co.,Ltd. All rights reserved. 10 // Third party copyrights are property of their respective owners. 11 // 12 // Licensed under the Apache License, Version 2.0 (the "License"); 13 // you may not use this file except in compliance with the License. 14 // You may obtain a copy of the License at 15 // 16 // http://www.apache.org/licenses/LICENSE-2.0 17 // 18 // Unless required by applicable law or agreed to in writing, software 19 // distributed under the License is distributed on an "AS IS" BASIS, 20 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 // See the License for the specific language governing permissions and 22 // limitations under the License. 23 // 24 // Author: Longbu Wang <wanglongbu@huawei.com.com> 25 // Jinheng Zhang <zhangjinheng1@huawei.com> 26 // Chenqi Shan <shanchenqi@huawei.com> 27 28 #include "operations.hpp" 29 #include "utils.hpp" 30 namespace cv { 31 namespace ccm { 32 operator ()(Mat & abc)33Mat Operation::operator()(Mat& abc) 34 { 35 if (!linear) 36 { 37 return f(abc); 38 } 39 if (M.empty()) 40 { 41 return abc; 42 } 43 return multiple(abc, M); 44 }; 45 add(const Operation & other)46void Operation::add(const Operation& other) 47 { 48 if (M.empty()) 49 { 50 M = other.M.clone(); 51 } 52 else 53 { 54 M = M * other.M; 55 } 56 }; 57 clear()58void Operation::clear() 59 { 60 M = Mat(); 61 }; 62 add(const Operations & other)63Operations& Operations::add(const Operations& other) 64 { 65 ops.insert(ops.end(), other.ops.begin(), other.ops.end()); 66 return *this; 67 }; 68 run(Mat abc)69Mat Operations::run(Mat abc) 70 { 71 Operation hd; 72 for (auto& op : ops) 73 { 74 if (op.linear) 75 { 76 hd.add(op); 77 } 78 else 79 { 80 abc = hd(abc); 81 hd.clear(); 82 abc = op(abc); 83 } 84 } 85 abc = hd(abc); 86 return abc; 87 }; 88 89 } 90 } // namespace cv::ccm