SMACC2
Loading...
Searching...
No Matches
smacc2_client_library
cl_rgb
include
cl_rgb
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
>
18
#include <
cl_rgb/table_survey.hpp
>
19
20
#include <opencv2/core.hpp>
21
22
#include <optional>
23
24
namespace
cl_rgb
25
{
26
27
// A box standing on the table: its centre on the table plane and how it is turned.
28
struct
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
37
struct
BoxFitParams
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.
56
std::optional<BoxFit>
fitBoxOnTable
(
57
const
Blob
& blob,
const
PinholeCamera
& camera,
double
tableZ,
const
BoxFitParams
& params);
58
59
}
// namespace cl_rgb
geometry.hpp
cl_rgb
Definition
box_fit.hpp:25
cl_rgb::fitBoxOnTable
std::optional< BoxFit > fitBoxOnTable(const Blob &blob, const PinholeCamera &camera, double tableZ, const BoxFitParams ¶ms)
Definition
box_fit.cpp:130
cl_rgb::Blob
Definition
table_survey.hpp:29
cl_rgb::BoxFitParams
Definition
box_fit.hpp:38
cl_rgb::BoxFitParams::tryTopBelow
double tryTopBelow
Definition
box_fit.hpp:46
cl_rgb::BoxFitParams::yawStepRad
double yawStepRad
Definition
box_fit.hpp:42
cl_rgb::BoxFitParams::minOverlap
double minOverlap
Definition
box_fit.hpp:43
cl_rgb::BoxFitParams::searchM
double searchM
Definition
box_fit.hpp:40
cl_rgb::BoxFitParams::sizeM
cv::Vec3d sizeM
Definition
box_fit.hpp:39
cl_rgb::BoxFitParams::minChromaFraction
double minChromaFraction
Definition
box_fit.hpp:51
cl_rgb::BoxFitParams::stepM
double stepM
Definition
box_fit.hpp:41
cl_rgb::BoxFit
Definition
box_fit.hpp:29
cl_rgb::BoxFit::y
double y
Definition
box_fit.hpp:31
cl_rgb::BoxFit::yawRad
double yawRad
Definition
box_fit.hpp:32
cl_rgb::BoxFit::overlap
double overlap
Definition
box_fit.hpp:33
cl_rgb::BoxFit::x
double x
Definition
box_fit.hpp:30
cl_rgb::BoxFit::topOnly
bool topOnly
Definition
box_fit.hpp:34
cl_rgb::PinholeCamera
Definition
geometry.hpp:27
table_survey.hpp
Generated by
1.12.0