SMACC2
Loading...
Searching...
No Matches
table_survey.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
19#include <opencv2/core.hpp>
20
21#include <string>
22#include <vector>
23
24namespace cl_rgb
25{
26
27// One connected region of the image that does not look like table.
28struct Blob
29{
30 int id = 0;
31 cv::Rect box; // pixels
32 int areaPx = 0;
33 cv::Point2d centroidPx;
34 // Where the ray through the centroid meets the table. For an object with height this lies
35 // behind the object as seen from the camera; see CpTablePlane::pointUnderPixel for the
36 // correction when the height is known.
37 cv::Vec3d tablePoint{0.0, 0.0, 0.0};
38 // Where the blob's point nearest to the camera meets the table: the object's near edge.
39 cv::Vec3d nearPoint{0.0, 0.0, 0.0};
40 double axisRad = 0.0; // direction of the long axis on the table, world frame, in [-pi/2, pi/2)
41 double lengthM = 0.0; // extent of the footprint along the long axis
42 double widthM = 0.0; // and across it
43 cv::Vec3d meanLab{0.0, 0.0, 0.0}; // L 0 to 100, a and b around 0
44 cv::Vec3d meanBgr{0.0, 0.0, 0.0};
45 cv::Mat mask; // box-sized, 255 on the blob
46 cv::Mat crop; // box-sized copy of the image
47};
48
50{
51 // without a reference image: distance from the table's own colour
52 double threshold = 3.5; // in robust standard deviations
53 double lightnessWeight = 0.4; // lightness counts this much against the two colour channels
54 // with a reference image of the empty scene: distance from that image, pixel by pixel
55 std::string referenceImagePath; // empty: no reference
56 double referenceThreshold = 14.0; // in Lab units
57 // Against a reference picture: a pixel that is the reference dimmed, alike in blue, green and
58 // red, to no less than this fraction is a shadow and not an object; 0 keeps shadows.
59 double shadowDarkest = 0.0;
60 double shadowSpread = 0.25; // how far the three channels' dimming may differ in a shadow
61 double referenceLightnessWeight = 1.3; // shading changes lightness more than colour
62 int openPx = 3; // removes specks smaller than this
63 int closePx = 5; // closes gaps smaller than this
64};
65
67{
68 int minAreaPx = 40;
69 int maxBlobs = 64; // the largest ones are kept
70 // Objects of different colour that touch in the image are cut apart where the hue changes by
71 // more than this over two pixels. Hue and not brightness: the lit and the shaded face of one
72 // object stay together. 0 leaves touching objects joined.
73 double colourEdgeHueDeg = 0.0;
74 double colourEdgeMinChroma = 12.0; // Lab units; below this a pixel has no hue to compare
75};
76
77// The pixels that see the table top, 255 inside.
78cv::Mat tableRegionMask(
79 const PinholeCamera & camera, const cv::Size & size, const TableParams & table);
80
81// The pixels of the table region whose colour is far from the table's own. The table's colour
82// is taken from the region itself (median and spread in Lab), so the table must fill most of it.
83cv::Mat segmentForeground(
84 const cv::Mat & bgr, const cv::Mat & tableMask, const SegmenterParams & params);
85
86// The pixels of the table region that differ from a reference image of the empty scene, taken
87// by the same camera from the same place. Whatever the reference shows besides the table (a
88// fixture, the robot at rest) is no foreground as long as it has not moved.
90 const cv::Mat & bgr, const cv::Mat & referenceBgr, const cv::Mat & tableMask,
91 const SegmenterParams & params);
92
93// Groups the foreground into blobs and places each on the table.
94std::vector<Blob> findBlobs(
95 const cv::Mat & bgr, const cv::Mat & foreground, const PinholeCamera & camera,
96 const TableParams & table, const BlobParams & params);
97
98} // namespace cl_rgb
cv::Mat segmentAgainstReference(const cv::Mat &bgr, const cv::Mat &referenceBgr, const cv::Mat &tableMask, const SegmenterParams &params)
std::vector< Blob > findBlobs(const cv::Mat &bgr, const cv::Mat &foreground, const PinholeCamera &camera, const TableParams &table, const BlobParams &params)
cv::Mat segmentForeground(const cv::Mat &bgr, const cv::Mat &tableMask, const SegmenterParams &params)
cv::Mat tableRegionMask(const PinholeCamera &camera, const cv::Size &size, const TableParams &table)
cv::Vec3d meanLab
cv::Vec3d nearPoint
cv::Point2d centroidPx
cv::Vec3d tablePoint
cv::Vec3d meanBgr