Skip to content

Commit

Permalink
~
Browse files Browse the repository at this point in the history
  • Loading branch information
pabssen1 committed Aug 20, 2024
1 parent 2d5dac7 commit 905d61f
Show file tree
Hide file tree
Showing 19 changed files with 1,613 additions and 1,392 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@
"__memory": "cpp",
"filesystem": "cpp",
"alignedvector3": "cpp",
"*.expression": "cpp"
"*.expression": "cpp",
"text_encoding": "cpp"
},
"java.compile.nullAnalysis.mode": "automatic",
"java.completion.favoriteStaticMembers": [
Expand Down
Binary file added 0.binarypb
Binary file not shown.
13 changes: 13 additions & 0 deletions mediapipe/calculators/image/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,19 @@ cc_library(
alwayslink = 1,
)

cc_library(
name = "box_to_floats_calculator",
srcs = ["box_to_floats_calculator.cc"],
deps = [
"//mediapipe/framework:calculator_framework",
"//mediapipe/framework/port:status",
"//mediapipe/util/tracking",
"//mediapipe/util/tracking:box_tracker",
"@com_google_absl//absl/memory",
],
alwayslink = 1,
)

cc_library(
name = "tracking_calculator",
srcs = ["tracking_calculator.cc"],
Expand Down
84 changes: 84 additions & 0 deletions mediapipe/calculators/image/box_to_floats_calculator.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include <vector>

#include "mediapipe/framework/calculator_framework.h"
#include "mediapipe/util/tracking/box_tracker.pb.h"
#include "mediapipe/util/tracking/box_tracker.h"
#include "absl/status/status.h"

namespace mediapipe
{
class BoxToFloatsCalculator : public CalculatorBase
{
public:
static absl::Status GetContract(CalculatorContract *cc)
{
cc->Inputs().Tag("BOXES").Set<TimedBoxProtoList>();
cc->Inputs().Tag("PROPS").Set<std::pair<int, int>>();
cc->Outputs().Tag("BFLOATS").Set<std::vector<float>>();
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("BOXES").IsEmpty() || cc->Inputs().Tag("PROPS").IsEmpty())
{
return absl::OkStatus();
}
try
{
const auto &box_list = cc->Inputs().Tag("BOXES").Get<TimedBoxProtoList>();
const auto &input_props = cc->Inputs().Tag("PROPS").Get<std::pair<int, int>>();

// Input validation
if (box_list.box_size() > 0 && input_props.first > 0 && input_props.second > 0)
{
// Convert TimedBoxProto to TimedBox
TimedBox currentBox;
try
{
currentBox = TimedBox::FromProto(box_list.box(0));
}
catch (const std::exception &e)
{
ABSL_LOG(ERROR) << "Error converting TimedBoxProto: " << e.what();
// Handle the error (e.g., skip this box or send an empty vector)
return absl::OkStatus();
}

// Calculate box corners
std::array<Vector2_f, 4> corners = currentBox.Corners(input_props.first, input_props.second);

// Create and send output
std::vector<float> output_boxes;
for (const auto &corner : corners)
{
output_boxes.push_back(corner.x());
output_boxes.push_back(corner.y());
}
auto output_floats = absl::make_unique<std::vector<float>>(output_boxes);
cc->Outputs().Tag("BFLOATS").Add(output_floats.release(), cc->InputTimestamp());
}
else
{
// Handle the case where input data is invalid
// (e.g., send an empty vector or log a message).
}
}
catch (const std::exception &e)
{
ABSL_LOG(ERROR) << "Exception: " << e.what();
}

return absl::OkStatus();
}
};

REGISTER_CALCULATOR(BoxToFloatsCalculator);

} // namespace mediapipe
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace mediapipe
.GetExtension(FeatureDetectorCalculatorOptions::ext);
feature_detector_ = cv::ORB::create(
options_.max_features(), options_.scale_factor(),
options_.pyramid_level(), kPatchSize - 1, 0, 2, cv::ORB::FAST_SCORE);
options_.pyramid_level(), kPatchSize - 1, 0, 2, cv::ORB::HARRIS_SCORE);
cc->SetOffset(TimestampDiff(0));
return absl::OkStatus();
}
Expand Down
4 changes: 2 additions & 2 deletions mediapipe/calculators/image/reranking_calculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace mediapipe
int localMatchCount = 0;
for (const auto &match : matches)
{
if (match.size() == 2 && match[0].distance < 0.7f * match[1].distance)
if (match.size() == 2 && match[0].distance < 0.75f * match[1].distance)
{
localMatchCount++;
}
Expand All @@ -94,7 +94,7 @@ namespace mediapipe

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

0 comments on commit 905d61f

Please sign in to comment.