-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Debaditya Sen
authored and
Debaditya Sen
committed
Aug 9, 2024
1 parent
d0b9800
commit 2d5dac7
Showing
16 changed files
with
554 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+54.5 KB
...diapipe/examples/android/solutions/.gradle/nb-cache/solutions-1214149408/project-info.ser
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...s/.gradle/nb-cache/trust/D574649DA6D8FAEA3AFAF373242814EAEAB93B6A628E41DCF6A4C252F832C623
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3171FAF7DD47CDFB3AB913B50ABB6C2E0D88D946B7F7EEF5558EA32E0F5AA11C |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.