Skip to content

Commit

Permalink
fixup! Import code for optical flow in the browser
Browse files Browse the repository at this point in the history
  • Loading branch information
squishyhuman committed Oct 4, 2023
1 parent 3015ee1 commit 1926622
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 33 deletions.
92 changes: 92 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -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: '<EGL/.*\.h>'
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
...
32 changes: 22 additions & 10 deletions lib/kernels/cpu/cpu_imgproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,34 @@
#include <opencv2/gapi/cpu/gcpukernel.hpp>
#include <opencv2/imgproc.hpp>

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<cv::Point2f> &out){
cv::goodFeaturesToTrack(image, out, static_cast<int>(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<cv::Point2f>& out){
cv::goodFeaturesToTrack(image,
out,
static_cast<int>(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<GCPUGoodFeatures>();

return pkg;
Expand Down
3 changes: 2 additions & 1 deletion lib/kernels/cpu/cpu_imgproc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <opencv2/gapi/gkernel.hpp>

namespace imgproc {
namespace imgproc
{
cv::gapi::GKernelPackage kernels();
}
17 changes: 10 additions & 7 deletions lib/kernels/cpu/cpu_reconstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
#include <opencv2/gapi/cpu/gcpukernel.hpp>
#include <opencv2/sfm/reconstruct.hpp>

namespace reconstruction {
namespace reconstruction
{
// Reconstruct trajectory
GAPI_OCV_KERNEL(GCPUReconstructTrajectory, GReconstructTrajectory){
static void run(const std::vector<std::vector<cv::Point2f>> &pointHistory,
const cv::Mat &initialCameraMatrix,
cv::Mat &projectionMatrix, cv::Mat &updatedCameraMatrix){
static void run(const std::vector<std::vector<cv::Point2f>>& pointHistory,
const cv::Mat& initialCameraMatrix,
cv::Mat& projectionMatrix,
cv::Mat& updatedCameraMatrix){
// If true, the cameras is supposed to be projective
const bool isProjective = true;

Expand All @@ -33,8 +35,8 @@ std::vector<cv::Mat> projections;
std::vector<cv::Point3f> 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();
Expand All @@ -43,7 +45,8 @@ projectionMatrix = projections.back();
;
}

cv::gapi::GKernelPackage reconstruction::kernels() {
cv::gapi::GKernelPackage reconstruction::kernels()
{
static auto pkg = cv::gapi::kernels<GCPUReconstructTrajectory>();

return pkg;
Expand Down
3 changes: 2 additions & 1 deletion lib/kernels/cpu/cpu_reconstruction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <opencv2/gapi/gkernel.hpp>

namespace reconstruction {
namespace reconstruction
{
cv::gapi::GKernelPackage kernels();
}
20 changes: 12 additions & 8 deletions lib/kernels/cpu/cpu_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@

#include <opencv2/gapi/cpu/gcpukernel.hpp>

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<GCPUCalcSceneScore>();

return pkg;
Expand Down
3 changes: 2 additions & 1 deletion lib/kernels/cpu/cpu_scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <opencv2/gapi/gkernel.hpp>

namespace scene {
namespace scene
{
cv::gapi::GKernelPackage kernels();
}
10 changes: 6 additions & 4 deletions lib/kernels/cpu/cpu_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
#include <opencv2/gapi/cpu/gcpukernel.hpp>
#include <opencv2/gapi/cpu/imgproc.hpp>

namespace video {
namespace video
{
// Predict points for optical flow
GAPI_OCV_KERNEL(GCPUPredictPoints, GPredictPoints){
static void run(const std::vector<std::vector<cv::Point2f>> &pointHistory,
std::vector<cv::Point2f> &predictedPoints){
static void run(const std::vector<std::vector<cv::Point2f>>& pointHistory,
std::vector<cv::Point2f>& predictedPoints){
predictedPoints.resize(pointHistory[0].size());

// TODO
Expand All @@ -27,7 +28,8 @@ predictedPoints = pointHistory.back();
;
}

cv::gapi::GKernelPackage video::kernels() {
cv::gapi::GKernelPackage video::kernels()
{
static auto pkg = cv::gapi::kernels<GCPUPredictPoints>();

return pkg;
Expand Down
3 changes: 2 additions & 1 deletion lib/kernels/cpu/cpu_video.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <opencv2/gapi/gkernel.hpp>

namespace video {
namespace video
{
cv::gapi::GKernelPackage kernels();
}

0 comments on commit 1926622

Please sign in to comment.