Skip to content

Commit f6eb169

Browse files
janherlingmeta-codesync[bot]
authored andcommitted
Added template-free base class for FREAKDescriptor
Summary: The base class simplifies the usage. Reviewed By: enpe Differential Revision: D87610837 Privacy Context Container: L1192943 fbshipit-source-id: 70db20a4d1a01189b7469983eb1c2a4371c6e100
1 parent 122dfc0 commit f6eb169

File tree

6 files changed

+199
-165
lines changed

6 files changed

+199
-165
lines changed

build/visual_studio/android/vc143/ocean/cv/detector/cvdetector.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\FASTFeatureDetector.cpp" />
103103
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\FeatureDetector.cpp" />
104104
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\FrameChangeDetector.cpp" />
105+
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\FREAKDescriptor.cpp" />
105106
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\HarrisCornerDetector.cpp" />
106107
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\HemiCube.cpp" />
107108
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\LineDetectorHough.cpp" />
@@ -115,4 +116,4 @@
115116
</ItemGroup>
116117
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
117118
<ImportGroup Label="ExtensionTargets" />
118-
</Project>
119+
</Project>

build/visual_studio/android/vc143/ocean/cv/detector/cvdetector.vcxproj.filters

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,8 @@
128128
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\FASTFeatureDetector.cpp">
129129
<Filter>Source Files</Filter>
130130
</ClCompile>
131+
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\FREAKDescriptor.cpp">
132+
<Filter>Source Files</Filter>
133+
</ClCompile>
131134
</ItemGroup>
132-
</Project>
135+
</Project>

build/visual_studio/win/vc143/ocean/cv/detector/cvdetector.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\FASTFeatureDetector.cpp" />
186186
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\FeatureDetector.cpp" />
187187
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\FrameChangeDetector.cpp" />
188+
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\FREAKDescriptor.cpp" />
188189
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\HarrisCornerDetector.cpp" />
189190
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\HemiCube.cpp" />
190191
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\LineDetectorHough.cpp" />
@@ -226,4 +227,4 @@
226227
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
227228
<ImportGroup Label="ExtensionTargets">
228229
</ImportGroup>
229-
</Project>
230+
</Project>

build/visual_studio/win/vc143/ocean/cv/detector/cvdetector.vcxproj.filters

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\FrameChangeDetector.cpp">
5454
<Filter>Source Files</Filter>
5555
</ClCompile>
56+
<ClCompile Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\FREAKDescriptor.cpp">
57+
<Filter>Source Files</Filter>
58+
</ClCompile>
5659
</ItemGroup>
5760
<ItemGroup>
5861
<ClInclude Include="..\..\..\..\..\..\..\impl\ocean\cv\detector\Detector.h">
@@ -131,4 +134,4 @@
131134
<Filter>Header Files</Filter>
132135
</ClInclude>
133136
</ItemGroup>
134-
</Project>
137+
</Project>
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/*
2+
* Portions Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "ocean/cv/detector/FREAKDescriptor.h"
9+
10+
namespace Ocean
11+
{
12+
13+
namespace CV
14+
{
15+
16+
namespace Detector
17+
{
18+
19+
FREAKDescriptor::PinholeCameraDerivativeFunctor::PinholeCameraDerivativeFunctor(const PinholeCamera& pinholeCamera, const unsigned int pyramidLevels)
20+
{
21+
ocean_assert(pinholeCamera.isValid());
22+
ocean_assert(pyramidLevels != 0u);
23+
24+
cameras_.reserve(pyramidLevels);
25+
cameras_.emplace_back(pinholeCamera);
26+
27+
unsigned int width = pinholeCamera.width();
28+
unsigned int height = pinholeCamera.height();
29+
30+
for (unsigned int level = 1u; level < pyramidLevels; ++level)
31+
{
32+
width /= 2u;
33+
height /= 2u;
34+
35+
if (width == 0u || height == 0u)
36+
{
37+
break;
38+
}
39+
40+
cameras_.emplace_back(width, height, pinholeCamera);
41+
}
42+
43+
cameras_.shrink_to_fit();
44+
}
45+
46+
FREAKDescriptor::CameraDerivativeData FREAKDescriptor::PinholeCameraDerivativeFunctor::computeCameraDerivativeData(const Eigen::Vector2f& point, const unsigned int pointPyramidLevel, float& inverseFocalLength) const
47+
{
48+
ocean_assert(pointPyramidLevel < cameras_.size());
49+
50+
inverseFocalLength = float(cameras_[pointPyramidLevel].inverseFocalLengthX() + cameras_[pointPyramidLevel].inverseFocalLengthY()) * 0.5f;
51+
52+
return computeCameraDerivativeData(cameras_[pointPyramidLevel], point);
53+
}
54+
55+
unsigned int FREAKDescriptor::PinholeCameraDerivativeFunctor::supportedPyramidLevels() const
56+
{
57+
return (unsigned int)(cameras_.size());
58+
}
59+
60+
FREAKDescriptor::CameraDerivativeData FREAKDescriptor::PinholeCameraDerivativeFunctor::computeCameraDerivativeData(const PinholeCamera& pinholeCamera, const Eigen::Vector2f& point)
61+
{
62+
const Vector3 unprojectRayIF = pinholeCamera.vectorIF(Vector2(point.x(), point.y()));
63+
ocean_assert(Numeric::isEqualEps((Vector3((Scalar(point.x()) - pinholeCamera.principalPointX()) * pinholeCamera.inverseFocalLengthX(), (Scalar(point.y()) - pinholeCamera.principalPointY()) * pinholeCamera.inverseFocalLengthY(), 1.0f).normalized() - unprojectRayIF).length()));
64+
65+
// TODOX Revisit this when enabling camera distortions
66+
ocean_assert(pinholeCamera.hasDistortionParameters() == false);
67+
68+
Scalar jacobianX[3];
69+
Scalar jacobianY[3];
70+
Geometry::Jacobian::calculatePointJacobian2x3(jacobianX, jacobianY, pinholeCamera, HomogenousMatrix4(true), unprojectRayIF, /* distort */ false);
71+
72+
CameraDerivativeData data;
73+
74+
data.unprojectRayIF = Eigen::Vector3f(float(unprojectRayIF.x()), float(unprojectRayIF.y()), float(unprojectRayIF.z()));
75+
76+
// Note: the assignment below is row-major order but Eigen memory will be column-major. I know ...
77+
data.pointJacobianMatrixIF << float(jacobianX[0]), float(jacobianX[1]), float(jacobianX[2]), float(jacobianY[0]), float(jacobianY[1]), float(jacobianY[2]);
78+
ocean_assert(data.pointJacobianMatrixIF.IsRowMajor == false);
79+
80+
return data;
81+
}
82+
83+
FREAKDescriptor::AnyCameraDerivativeFunctor::AnyCameraDerivativeFunctor(const SharedAnyCamera& camera, const unsigned int pyramidLevels)
84+
{
85+
ocean_assert(camera && camera->isValid());
86+
ocean_assert(pyramidLevels != 0u);
87+
88+
cameras_.reserve(pyramidLevels);
89+
cameras_.emplace_back(camera);
90+
91+
unsigned int width = camera->width();
92+
unsigned int height = camera->height();
93+
94+
for (unsigned int level = 1u; level < pyramidLevels; ++level)
95+
{
96+
width /= 2u;
97+
height /= 2u;
98+
99+
if (width == 0u || height == 0u)
100+
{
101+
break;
102+
}
103+
104+
cameras_.emplace_back(cameras_.back()->clone(width, height));
105+
}
106+
107+
inverseFocalLengths_.reserve(pyramidLevels);
108+
for (const SharedAnyCamera& levelCamera : cameras_)
109+
{
110+
ocean_assert(levelCamera && levelCamera->isValid());
111+
112+
const float inverseFocalLength = float(levelCamera->inverseFocalLengthX() + levelCamera->inverseFocalLengthY()) * 0.5f;
113+
114+
inverseFocalLengths_.emplace_back(inverseFocalLength);
115+
}
116+
}
117+
118+
FREAKDescriptor::CameraDerivativeData FREAKDescriptor::AnyCameraDerivativeFunctor::computeCameraDerivativeData(const Eigen::Vector2f& point, const unsigned int pointPyramidLevel, float& inverseFocalLength) const
119+
{
120+
ocean_assert(pointPyramidLevel < cameras_.size());
121+
ocean_assert(cameras_.size() == inverseFocalLengths_.size());
122+
123+
inverseFocalLength = inverseFocalLengths_[pointPyramidLevel];
124+
125+
return computeCameraDerivativeData(*cameras_[pointPyramidLevel], point);
126+
}
127+
128+
unsigned int FREAKDescriptor::AnyCameraDerivativeFunctor::supportedPyramidLevels() const
129+
{
130+
return (unsigned int)(cameras_.size());
131+
}
132+
133+
FREAKDescriptor::CameraDerivativeData FREAKDescriptor::AnyCameraDerivativeFunctor::computeCameraDerivativeData(const AnyCamera& camera, const Eigen::Vector2f& point)
134+
{
135+
const Vector3 unprojectRayIF = camera.vectorIF(Vector2(point.x(), point.y()));
136+
137+
Scalar jacobianX[3];
138+
Scalar jacobianY[3];
139+
camera.pointJacobian2x3IF(unprojectRayIF, jacobianX, jacobianY);
140+
141+
CameraDerivativeData data;
142+
143+
data.unprojectRayIF = Eigen::Vector3f(float(unprojectRayIF.x()), float(unprojectRayIF.y()), float(unprojectRayIF.z()));
144+
145+
// Note: the assignment below is row-major order but Eigen memory will be column-major. I know ...
146+
data.pointJacobianMatrixIF << float(jacobianX[0]), float(jacobianX[1]), float(jacobianX[2]), float(jacobianY[0]), float(jacobianY[1]), float(jacobianY[2]);
147+
ocean_assert(data.pointJacobianMatrixIF.IsRowMajor == false);
148+
149+
return data;
150+
}
151+
152+
}
153+
154+
}
155+
156+
}

0 commit comments

Comments
 (0)