Skip to content

Commit

Permalink
motionvector
Browse files Browse the repository at this point in the history
  • Loading branch information
Debaditya Sen authored and Debaditya Sen committed Aug 9, 2024
1 parent d0b9800 commit 2d5dac7
Show file tree
Hide file tree
Showing 16 changed files with 554 additions and 69 deletions.
14 changes: 12 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,15 @@
"*.ipp": "cpp",
"slist": "cpp",
"shared_mutex": "cpp",
"__mutex_base": "cpp"
"__mutex_base": "cpp",
"fft": "cpp",
"*.traits": "cpp",
"nnls": "cpp",
"format": "cpp",
"__memory": "cpp",
"filesystem": "cpp",
"alignedvector3": "cpp",
"*.expression": "cpp"
},
"java.compile.nullAnalysis.mode": "automatic",
"java.completion.favoriteStaticMembers": [
Expand Down Expand Up @@ -137,7 +145,9 @@
"bazel-bin": false,
"bazel-mediapipe": false,
"bazel-out": false,
"bazel-testlogs": false
"bazel-testlogs": false,
"bin": false,
"com": false
},
"java.configuration.updateBuildConfiguration": "automatic"
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3171FAF7DD47CDFB3AB913B50ABB6C2E0D88D946B7F7EEF5558EA32E0F5AA11C
26 changes: 24 additions & 2 deletions mediapipe/calculators/image/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,27 @@ cc_library(
)

cc_library(
name = "overlay_calculator_custom",
srcs = ["overlay_calculator.cc"],
name = "frame_joiner_calculator",
srcs = ["frame_joiner_calculator.cc"],
deps = [
":feature_detector_calculator_cc_proto",
"//mediapipe/framework:calculator_framework",
"//mediapipe/framework/formats:image_frame",
"//mediapipe/framework/formats:image_frame_opencv",
"//mediapipe/framework/port:integral_types",
"//mediapipe/framework/port:logging",
"//mediapipe/framework/port:opencv_core",
"//mediapipe/framework/port:opencv_imgproc",
"//mediapipe/framework/port:ret_check",
"//mediapipe/framework/port:status",
"//mediapipe/framework/tool:options_util",
],
alwayslink = 1,
)

cc_library(
name = "tracking_calculator",
srcs = ["tracking_calculator.cc"],
deps = [
":feature_detector_calculator_cc_proto",
"//mediapipe/framework:calculator_framework",
Expand All @@ -682,13 +701,16 @@ cc_library(
"//mediapipe/framework/port:integral_types",
"//mediapipe/framework/port:logging",
"//mediapipe/framework/port:opencv_core",
"//mediapipe/framework/port:opencv_video",
"//mediapipe/framework/port:opencv_features2d",
"//mediapipe/framework/port:opencv_calib3d",
"//mediapipe/framework/port:opencv_imgproc",
"//mediapipe/framework/port:ret_check",
"//mediapipe/framework/port:status",
"//mediapipe/framework/port:threadpool",
"//mediapipe/framework/tool:options_util",
"//mediapipe/util/tracking",
"//mediapipe/util/tracking:box_tracker",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/synchronization",
],
Expand Down
79 changes: 79 additions & 0 deletions mediapipe/calculators/image/frame_joiner_calculator.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "mediapipe/framework/calculator_framework.h"
#include "mediapipe/framework/formats/image_frame.h"
#include "mediapipe/framework/formats/image_frame_opencv.h"
#include "mediapipe/framework/port/opencv_core_inc.h"
#include "mediapipe/framework/port/opencv_imgproc_inc.h"
#include "mediapipe/framework/port/ret_check.h"
#include "mediapipe/framework/port/status.h"
#include "mediapipe/framework/tool/options_util.h"

namespace mediapipe
{

class FrameJoinerCalculator : public CalculatorBase
{
public:
static absl::Status GetContract(CalculatorContract *cc)
{
// cc->SetInputStreamHandler("ImmediateInputStreamHandler");
if (cc->Inputs().HasTag("FRAME"))
{
cc->Inputs().Tag("FRAME").Set<ImageFrame>();
}
if (cc->Inputs().HasTag("OVERLAY"))
{
cc->Inputs().Tag("OVERLAY").Set<ImageFrame>();
}
if (cc->Outputs().HasTag("COMBINED"))
{
cc->Outputs().Tag("COMBINED").Set<ImageFrame>();
}

return absl::OkStatus();
}

absl::Status Open(CalculatorContext *cc) override
{
cc->SetOffset(::mediapipe::TimestampDiff(0));
return absl::OkStatus();
}

absl::Status Process(CalculatorContext *cc) override
{
if (!cc->Inputs().Tag("OVERLAY").IsEmpty())
{
cv::Mat overlayed_image;
const auto &IFFrame = cc->Inputs().Tag("FRAME").Get<ImageFrame>();
const auto &IFOverlay = cc->Inputs().Tag("OVERLAY").Get<ImageFrame>();
cv::Mat frame = formats::MatView(&IFFrame);
cv::Mat overlay = formats::MatView(&IFOverlay);
if (overlay.cols == 0)
{
cc->Outputs()
.Tag("COMBINED")
.AddPacket(cc->Inputs().Tag("FRAME").Value());
return absl::OkStatus();
}
cv::cvtColor(frame, frame, cv::COLOR_BGRA2BGR);
cv::cvtColor(overlay, overlay, cv::COLOR_BGRA2BGR);
cv::addWeighted(frame, 1.0, overlay, 1.0, 0, overlayed_image);
std::unique_ptr<ImageFrame> output_image_frame =
absl::make_unique<ImageFrame>(ImageFormat::SRGB, overlayed_image.cols,
overlayed_image.rows, ImageFrame::kGlDefaultAlignmentBoundary);
overlayed_image.copyTo(formats::MatView(output_image_frame.get()));
cc->Outputs()
.Tag("COMBINED")
.Add(output_image_frame.release(), cc->InputTimestamp());
return absl::OkStatus();
}
if (!cc->Inputs().Tag("FRAME").IsEmpty())
{
cc->Outputs().Tag("COMBINED").AddPacket(cc->Inputs().Tag("FRAME").Value());
return absl::OkStatus();
}

return absl::OkStatus();
}
};
REGISTER_CALCULATOR(FrameJoinerCalculator);
} // namespace mediapipe
2 changes: 1 addition & 1 deletion mediapipe/calculators/image/reranking_calculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace mediapipe

// Find the index with the maximum match count
int max_index = -1;
int max_count = 8;
int max_count = 10;
for (int i = 0; i < match_counts.size(); ++i)
{
if (match_counts[i] > max_count)
Expand Down
Loading

0 comments on commit 2d5dac7

Please sign in to comment.