nareshmlx/opencv-pr huggingface dataset:
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
At least that'd be good to have a constructor from `cv::Matx<_Tp, 3, 3>`
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
typo: could
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
The description can be extended by the following: "dot(a, b) is a good metric of how close the quaternions are. Indeed, consider the unit quaternion difference `a^-1 * b`, its real part is dot(a, b). At the same time its real part is equal to `cos(beta/2)` where beta is an angle of rotation between a and b. Therefore, the closer dot(a, b) to 1, the smaller rotation between them."
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
The description can be extended: "The interpolation will always choose the shortest path but the constant speed is not guaranteed."
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
The dot in code samples is confusing. A typo?
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
You mean to keep this way of my usage without changing the code, right?
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
I mean remove "using std::*" from headers. Use full namespace names where it is required.
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
1. Our original intention of designing this parameter is to speed up some calculations. If a user knows about this param, they'll get an extra potential performance, otherwise the code will just work. If we make it as a templeta param, user will have to determine whether it is a unit one when construct a quaternion and other operations. I think this may not be friendly. 2. Before implementing quaternion, Vadim and Rostislav agreed that there is only one class to represent quaternions and unit quaternions. here is the main content between Rostislav and Vadim ![1017](https://user-images.githubusercontent.com/49099366/96288719-7731a800-1016-11eb-80ca-8441fdb2799f.png) ![101702](https://user-images.githubusercontent.com/49099366/96288742-7f89e300-1016-11eb-885f-f3577da02434.png) Rostislav to me ![101703](https://user-images.githubusercontent.com/49099366/96288765-87498780-1016-11eb-8715-c530b44d1533.png) ![101704](https://user-images.githubusercontent.com/49099366/96289226-3c7c3f80-1017-11eb-9f37-08b0355edd3b.png)
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
OK. I tested it just now and confused with no error mentioned above during compilation...
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
Need to provide an explanation of what is meant by Rodrigues vector
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
A quaternion contains cos and sin of half angle, here we have full angle. Need to do one of the following: * divide angle by 2 * add a note into description that this function accepts half angle by axis as an argument
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
The matrix layout is not compatible with the `Affine3`'s matrix layout (as well as with a lot of OpenCV functions from calib3d, see [this ](https://docs.opencv.org/master/d9/d0c/group__calib3d.html#ga41b1a8dd70eae371eba707d101729c36)for example). It's the last row and the last column to contain zeros and ones, not the first ones as in your code.
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
typo: transform
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
typo: Rodrigues
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
There shouldn't be any warnings (about performance, I guess?), we do not guarantee good performance for quaternions which are not normalized.
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
Referring to the paper [Rotations with Rodrigues' vector](https://www.researchgate.net/publication/231052227_Rotations_with_Rodrigues'_vector) of formula (8), rvec is defined as: r = tan(psi / 2) * n where n represents normalized axis vector. At line 1198, in fact, the var angle is the half angle, i.e., angle = psi / 2. I think quaternion can also be constructed by this angle.
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
OK. This is commented before I write the function description earlier
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
Yes, I forgot that peculiarity of Rodrigues vector. In that case we should add a note into description about half angle.
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
Not sure to have understood everything correctly. --- For me, by default Rodrigues rotation vector should be `angle x axis()` (vector of size 3) and not `tan(psi / 2) * n` or `tan(angle/2) x axis()`. I believe `rvec = angle x axis()` is the convention that is used in the [calib3d](https://docs.opencv.org/4.5.0/d9/d0c/group__calib3d.html#ga61585db663d9da06b68e70cfbf6a1eac) module, and similar to the [Rodrigues' rotation formula](https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula) wiki page. This would be more or less consistent with `Eigen::AngleAxis` type, see for instance this [conversion code](https://gitlab.com/libeigen/eigen/-/blob/4a77eda1fdaebd7f92d587dfc0158a20dc0d2625/Eigen/src/Geometry/Quaternion.h#L560-569). --- In any case, description of the expected Rodrigues vector is needed to avoid confusion.
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
Rodrigues' rotation formula just illustrates the transformation from axis angle to the rotation vector, maybe not Rodrigues vector. So far, there are three ways to represent a rotation vector - `angle * axis()` just used in calib3d module. It is called [rotation vector ](https://en.wikipedia.org/wiki/Axis%E2%80%93angle_representation#Rotation_vector)in wiki - a struct of angle and axis, in [Eigen::AngleAxis](https://gitlab.com/libeigen/eigen/-/blob/4a77eda1fdaebd7f92d587dfc0158a20dc0d2625/Eigen/src/Geometry/AngleAxis.h) - `tan(psi / 2) * n` ,used here, called Rodrigues vector(RF vector) if needed, we could add a method from `angle * axis()` to quaternion. Anyway, we will add description to avoid confusion
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
You can use `std::is_floating_point` and instead of SFINAE `static_assert` gives more informative output to the user with the same check: ```cpp static_assert(std::is_floating_point<T>::value, "some informative message"); using value_type = T; ```
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
It can be implemented without friendship, because there is public method `exp`.
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
It can be implemented without friendship, because there is public method `log`.
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
It can be implemented without friendship, because there is public method `power`.
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
It can be implemented without friendship, because there is public method `sqrt`.
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
It can be implemented without friendship, because there is public method `crossProduct`.
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
It can be implemented without friendship, because there is public method `inv`.
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
What is the purpose to make this function static, but not free function?
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
Since `w, x, y, z` are public `operator<<` can be free function too.
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
`break` is unnecessary.
**File:** modules/core/include/opencv2/core/quaternion.hpp
**Change Type:** added
**Context:** PR #18335: Ordinary quaternion

**Code Changes:**
```diff
@@ -0,0 +1,1194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved.
```

Review comment:
It is better to write a transposed variant and avoid `MatExpr` creation.