SMACC2
Loading...
Searching...
No Matches
box_fit.hpp
Go to the documentation of this file.
1// Copyright 2026 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <cl_rgb/geometry.hpp>
19
20#include <opencv2/core.hpp>
21
22#include <optional>
23
24namespace cl_rgb
25{
26
27// A box standing on the table: its centre on the table plane and how it is turned.
28struct BoxFit
29{
30 double x = 0.0; // m, world frame
31 double y = 0.0;
32 double yawRad = 0.0; // of the box's x side about the vertical, in [0, pi/2) for a square box
33 double overlap = 0.0; // of the box's outline with the blob, 0 to 1 (intersection over union)
34 bool topOnly = false; // fitted to the top face alone: the sides were not part of the blob
35};
36
38{
39 cv::Vec3d sizeM{0.035, 0.035, 0.035}; // along the box's x, y and the vertical
40 double searchM = 0.012; // the centre is looked for this far around the first guess
41 double stepM = 0.002;
42 double yawStepRad = 0.0436; // 2.5 degrees
43 double minOverlap = 0.6; // below this there is no fit
44 // A side face that looks like the table (or its shadow) is missing from the blob. When the
45 // whole outline fits worse than this, the top face alone is tried as well and the better kept.
46 double tryTopBelow = 0.85;
47 // For a box of one strong colour: blob pixels that are darker than the blob's middle
48 // lightness and have less than this fraction of its strong chroma (the 90th percentile) are
49 // left out of the fit. They are shadow, which near a coloured box takes on some of its colour.
50 // A pale but bright face of the box is kept. 0 uses the whole blob.
51 double minChromaFraction = 0.0;
52};
53
54// Finds the place and the turn of a box of known size whose outline, as the camera would see
55// it, covers the blob best. The first guess of the centre comes from the blob's centroid.
56std::optional<BoxFit> fitBoxOnTable(
57 const Blob & blob, const PinholeCamera & camera, double tableZ, const BoxFitParams & params);
58
59} // namespace cl_rgb
std::optional< BoxFit > fitBoxOnTable(const Blob &blob, const PinholeCamera &camera, double tableZ, const BoxFitParams &params)
Definition box_fit.cpp:130
double yawRad
Definition box_fit.hpp:32
double overlap
Definition box_fit.hpp:33