From 1926622a3e3462fde098d94e10277df0b1e5db5d Mon Sep 17 00:00:00 2001 From: squishyhuman Date: Wed, 4 Oct 2023 16:18:18 -0700 Subject: [PATCH] fixup! Import code for optical flow in the browser --- .clang-format | 92 ++++++++++++++++++++++++++ lib/kernels/cpu/cpu_imgproc.cpp | 32 ++++++--- lib/kernels/cpu/cpu_imgproc.hpp | 3 +- lib/kernels/cpu/cpu_reconstruction.cpp | 17 +++-- lib/kernels/cpu/cpu_reconstruction.hpp | 3 +- lib/kernels/cpu/cpu_scene.cpp | 20 +++--- lib/kernels/cpu/cpu_scene.hpp | 3 +- lib/kernels/cpu/cpu_video.cpp | 10 +-- lib/kernels/cpu/cpu_video.hpp | 3 +- 9 files changed, 150 insertions(+), 33 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..e29c658c7 --- /dev/null +++ b/.clang-format @@ -0,0 +1,92 @@ +--- +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: DontAlign +AlignOperands: true +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Allman +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 100 +CommentPragmas: '^ IWYU pragma:' +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 2 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '' + Priority: 6 + - Regex: '(["/]PlatformDefs|"(system|system_gl|system_egl))\.h"' + Priority: 5 + - Regex: '"platform/[^/]+/' + Priority: 2 + - Regex: '^<[a-z0-9_]+>$' + Priority: 3 + - Regex: '^<(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)\.h>$' + Priority: 3 + - Regex: '^<' + Priority: 4 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '$' +IndentCaseLabels: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60000 +PointerAlignment: Left +ReflowComments: false +SortIncludes: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 8 +UseTab: Never +... diff --git a/lib/kernels/cpu/cpu_imgproc.cpp b/lib/kernels/cpu/cpu_imgproc.cpp index d07110b95..e0851fbea 100644 --- a/lib/kernels/cpu/cpu_imgproc.cpp +++ b/lib/kernels/cpu/cpu_imgproc.cpp @@ -13,22 +13,34 @@ #include #include -namespace imgproc { +namespace imgproc +{ // Find good features -GAPI_OCV_KERNEL(GCPUGoodFeatures, GGoodFeatures){ - static void run(const cv::Mat &image, const cv::Scalar &maxCorners, - double qualityLevel, const cv::Scalar &minDistance, - const cv::Mat &mask, int blockSize, bool useHarrisDetector, - double k, std::vector &out){ - cv::goodFeaturesToTrack(image, out, static_cast(maxCorners[0]), - qualityLevel, minDistance[0], mask, blockSize, - useHarrisDetector, k); +GAPI_OCV_KERNEL(GCPUGoodFeatures, GGoodFeatures){static void run(const cv::Mat& image, + const cv::Scalar& maxCorners, + double qualityLevel, + const cv::Scalar& minDistance, + const cv::Mat& mask, + int blockSize, + bool useHarrisDetector, + double k, + std::vector& out){ + cv::goodFeaturesToTrack(image, + out, + static_cast(maxCorners[0]), + qualityLevel, + minDistance[0], + mask, + blockSize, + useHarrisDetector, + k); } // namespace imgproc } ; } -cv::gapi::GKernelPackage imgproc::kernels() { +cv::gapi::GKernelPackage imgproc::kernels() +{ static auto pkg = cv::gapi::kernels(); return pkg; diff --git a/lib/kernels/cpu/cpu_imgproc.hpp b/lib/kernels/cpu/cpu_imgproc.hpp index 33b865fbb..2939fc811 100644 --- a/lib/kernels/cpu/cpu_imgproc.hpp +++ b/lib/kernels/cpu/cpu_imgproc.hpp @@ -8,6 +8,7 @@ #include -namespace imgproc { +namespace imgproc +{ cv::gapi::GKernelPackage kernels(); } diff --git a/lib/kernels/cpu/cpu_reconstruction.cpp b/lib/kernels/cpu/cpu_reconstruction.cpp index 9f93b0b3e..a6f3349f9 100644 --- a/lib/kernels/cpu/cpu_reconstruction.cpp +++ b/lib/kernels/cpu/cpu_reconstruction.cpp @@ -13,12 +13,14 @@ #include #include -namespace reconstruction { +namespace reconstruction +{ // Reconstruct trajectory GAPI_OCV_KERNEL(GCPUReconstructTrajectory, GReconstructTrajectory){ - static void run(const std::vector> &pointHistory, - const cv::Mat &initialCameraMatrix, - cv::Mat &projectionMatrix, cv::Mat &updatedCameraMatrix){ + static void run(const std::vector>& pointHistory, + const cv::Mat& initialCameraMatrix, + cv::Mat& projectionMatrix, + cv::Mat& updatedCameraMatrix){ // If true, the cameras is supposed to be projective const bool isProjective = true; @@ -33,8 +35,8 @@ std::vector projections; std::vector estimated3dPoints; // Perform reconstruction -cv::sfm::reconstruct(pointHistory, projections, estimated3dPoints, - updatedCameraMatrix, isProjective); +cv::sfm::reconstruct( + pointHistory, projections, estimated3dPoints, updatedCameraMatrix, isProjective); // We are interested in the most recent projection projectionMatrix = projections.back(); @@ -43,7 +45,8 @@ projectionMatrix = projections.back(); ; } -cv::gapi::GKernelPackage reconstruction::kernels() { +cv::gapi::GKernelPackage reconstruction::kernels() +{ static auto pkg = cv::gapi::kernels(); return pkg; diff --git a/lib/kernels/cpu/cpu_reconstruction.hpp b/lib/kernels/cpu/cpu_reconstruction.hpp index 469170dd5..b9c6c60fd 100644 --- a/lib/kernels/cpu/cpu_reconstruction.hpp +++ b/lib/kernels/cpu/cpu_reconstruction.hpp @@ -8,6 +8,7 @@ #include -namespace reconstruction { +namespace reconstruction +{ cv::gapi::GKernelPackage kernels(); } diff --git a/lib/kernels/cpu/cpu_scene.cpp b/lib/kernels/cpu/cpu_scene.cpp index c133b6987..be26dd6a9 100644 --- a/lib/kernels/cpu/cpu_scene.cpp +++ b/lib/kernels/cpu/cpu_scene.cpp @@ -13,21 +13,25 @@ #include -namespace scene { +namespace scene +{ // Calculate the scene score given a frame and its previous frame -GAPI_OCV_KERNEL(GCPUCalcSceneScore, GCalcSceneScore){ - static void run(const cv::Mat &prevImg, const cv::Mat &nextImg, - double prevMafd, unsigned int width, unsigned int height, - double &nextMafd, double &sceneScore){ - nextMafd = ImageUtils::CalcSceneMAFD(prevImg.data, nextImg.data, width, - height); +GAPI_OCV_KERNEL(GCPUCalcSceneScore, GCalcSceneScore){static void run(const cv::Mat& prevImg, + const cv::Mat& nextImg, + double prevMafd, + unsigned int width, + unsigned int height, + double& nextMafd, + double& sceneScore){ + nextMafd = ImageUtils::CalcSceneMAFD(prevImg.data, nextImg.data, width, height); sceneScore = ImageUtils::CalcSceneScore(prevMafd, nextMafd); } // namespace scene } ; } -cv::gapi::GKernelPackage scene::kernels() { +cv::gapi::GKernelPackage scene::kernels() +{ static auto pkg = cv::gapi::kernels(); return pkg; diff --git a/lib/kernels/cpu/cpu_scene.hpp b/lib/kernels/cpu/cpu_scene.hpp index 34f97c09b..821bb548b 100644 --- a/lib/kernels/cpu/cpu_scene.hpp +++ b/lib/kernels/cpu/cpu_scene.hpp @@ -8,6 +8,7 @@ #include -namespace scene { +namespace scene +{ cv::gapi::GKernelPackage kernels(); } diff --git a/lib/kernels/cpu/cpu_video.cpp b/lib/kernels/cpu/cpu_video.cpp index 72ebea812..18b65b7dd 100644 --- a/lib/kernels/cpu/cpu_video.cpp +++ b/lib/kernels/cpu/cpu_video.cpp @@ -13,11 +13,12 @@ #include #include -namespace video { +namespace video +{ // Predict points for optical flow GAPI_OCV_KERNEL(GCPUPredictPoints, GPredictPoints){ - static void run(const std::vector> &pointHistory, - std::vector &predictedPoints){ + static void run(const std::vector>& pointHistory, + std::vector& predictedPoints){ predictedPoints.resize(pointHistory[0].size()); // TODO @@ -27,7 +28,8 @@ predictedPoints = pointHistory.back(); ; } -cv::gapi::GKernelPackage video::kernels() { +cv::gapi::GKernelPackage video::kernels() +{ static auto pkg = cv::gapi::kernels(); return pkg; diff --git a/lib/kernels/cpu/cpu_video.hpp b/lib/kernels/cpu/cpu_video.hpp index c97d0b8b6..12c2636a2 100644 --- a/lib/kernels/cpu/cpu_video.hpp +++ b/lib/kernels/cpu/cpu_video.hpp @@ -8,6 +8,7 @@ #include -namespace video { +namespace video +{ cv::gapi::GKernelPackage kernels(); }