Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Adding images via gRPC: The labels aren't added to core correctly… #317

Merged
merged 2 commits into from
Jul 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix Adding images via gRPC: The labels aren't added to core correctly #…
  • Loading branch information
Mark-Niemeyer committed Jul 25, 2023
commit b38b294355599fac6a61d2f38ec733616ccebe16
Original file line number Diff line number Diff line change
@@ -10,7 +10,23 @@
from seerep.fb import point_service_grpc_fb as pointService
from seerep.fb import tf_service_grpc_fb as tfService
from seerep.util.common import get_gRPC_channel
from seerep.util.fb_helper import getOrCreateProject
from seerep.util.fb_helper import (
createBoundingBox2d,
createBoundingBox2dLabeled,
createBoundingBox2DLabeledWithCategory,
createHeader,
createImage,
createLabelWithCategory,
createLabelWithInstance,
createPoint,
createPoint2d,
createPointStamped,
createQuaternion,
createTimeStamp,
createTransformStamped,
createVector3,
getOrCreateProject,
)


class LoadSimulatedDataWithInstancePosition:
@@ -66,16 +82,16 @@ def __createPointForInstance(self, pointCloudData, instanceUuid, label, imageX,
pixelX = int(img.shape[1] * imageX)
pixelY = int(img.shape[0] * imageY)
position = pointCloudData[pixelY][pixelX]
point = util_fb.createPoint(builder, position[0], position[1], position[2])
point = createPoint(builder, position[0], position[1], position[2])

labelGeneral = []
labelGeneral.append(util_fb.createLabelWithInstance(builder, label, 1.0, instanceUuid))
labelGeneralCategory = util_fb.createLabelWithCategory(builder, [self.labelCategory], [labelGeneral])
labelGeneral.append(createLabelWithInstance(builder, label, 1.0, instanceUuid))
labelGeneralCategory = createLabelWithCategory(builder, [self.labelCategory], [labelGeneral])

timestamp = util_fb.createTimeStamp(builder, time)
header = util_fb.createHeader(builder, timestamp, frame, self.projectUuid)
timestamp = createTimeStamp(builder, time)
header = createHeader(builder, timestamp, frame, self.projectUuid)

pointStamped = util_fb.createPointStamped(builder, point, header, labelGeneralCategory)
pointStamped = createPointStamped(builder, point, header, labelGeneralCategory)
builder.Finish(pointStamped)

self.points.append(bytes(builder.Output()))
@@ -90,22 +106,20 @@ def __createBoundingBox2dCategory(self, builder, baseAnnotationPath, basePointCl
print("uuid: " + instanceUuid)

label = self.labelSwitch.get(int(round(labelFloat)))
labelWithInstance = util_fb.createLabelWithInstance(builder, label, 1.0, instanceUuid)
centerPoint = util_fb.createPoint2d(builder, x, y)
spatialExtent = util_fb.createPoint2d(builder, xExtent, yExtent)
boundingBox2D = util_fb.createBoundingBox2d(builder, centerPoint, spatialExtent)
labelWithInstance = createLabelWithInstance(builder, label, 1.0, instanceUuid)
centerPoint = createPoint2d(builder, x, y)
spatialExtent = createPoint2d(builder, xExtent, yExtent)
boundingBox2D = createBoundingBox2d(builder, centerPoint, spatialExtent)

boundingBox2dLabeledVector.append(
util_fb.createBoundingBox2dLabeled(builder, labelWithInstance, boundingBox2D)
)
boundingBox2dLabeledVector.append(createBoundingBox2dLabeled(builder, labelWithInstance, boundingBox2D))

if instanceUuid not in self.instanceUuidSet:
self.__createPointForInstance(pointCloudData, instanceUuid, label, x, y, time, frame, img)
self.instanceUuidSet.append(instanceUuid)
categoryString = builder.CreateString(self.labelCategory)
boundingBox2dCategoryVector = []
boundingBox2dCategoryVector.append(
util_fb.createBoundingBox2DLabeledWithCategory(self.builder, categoryString, boundingBox2dLabeledVector)
createBoundingBox2DLabeledWithCategory(self.builder, categoryString, boundingBox2dLabeledVector)
)
return boundingBox2dCategoryVector

@@ -140,10 +154,10 @@ def __loadImages(self):
bb2dWithCategory = self.__createBoundingBox2dCategory(
self.builder, baseAnnotationPath, basePointcloudPath, timeThisIteration, self.CAMERA_FRAME, img
)
timestamp = util_fb.createTimeStamp(self.builder, timeThisIteration)
header = util_fb.createHeader(self.builder, timestamp, self.CAMERA_FRAME, self.projectUuid)
timestamp = createTimeStamp(self.builder, timeThisIteration)
header = createHeader(self.builder, timestamp, self.CAMERA_FRAME, self.projectUuid)

imageMsg = util_fb.createImage(self.builder, img, header, self.IMAGE_ENCODING, bb2dWithCategory)
imageMsg = createImage(self.builder, img, header, self.IMAGE_ENCODING, bb2dWithCategory)

self.builder.Finish(imageMsg)
yield bytes(self.builder.Output())
@@ -155,10 +169,10 @@ def __createTransformFromQuaternion(self, builder, extrinsics):

r = calib_e[:3, :3]
quat = quaternion.from_rotation_matrix(r)
rotation = util_fb.createQuaternion(builder, quat)
rotation = createQuaternion(builder, quat)

t = calib_e[:3, -1]
translation = util_fb.createVector3(builder, t)
translation = createVector3(builder, t)

Transform.Start(builder)
Transform.AddTranslation(builder, translation)
@@ -177,9 +191,9 @@ def __loadTf(self):
with open(baseFilePath + self.EXTRINSICS_FILE_EXTENSION, "r") as extrinsics:
try:
transform = self.__createTransformFromQuaternion(builder, extrinsics)
timestamp = util_fb.createTimeStamp(builder, timeThisIteration)
headerTf = util_fb.createHeader(builder, timestamp, self.MAP_FRAME, self.projectUuid)
tf = util_fb.createTransformStamped(builder, self.CAMERA_FRAME, headerTf, transform)
timestamp = createTimeStamp(builder, timeThisIteration)
headerTf = createHeader(builder, timestamp, self.MAP_FRAME, self.projectUuid)
tf = createTransformStamped(builder, self.CAMERA_FRAME, headerTf, transform)

builder.Finish(tf)
yield bytes(builder.Output())
37 changes: 30 additions & 7 deletions seerep_srv/seerep_core_fb/src/core_fb_conversion.cpp
Original file line number Diff line number Diff line change
@@ -593,10 +593,22 @@ void CoreFbConversion::fromFbDataLabelsGeneral(
{
for (auto labelsCategories : *labelsGeneral)
{
std::vector<seerep_core_msgs::LabelWithInstance> labelWithInstanceVector;
std::vector<seerep_core_msgs::LabelWithInstance>* labelWithInstanceVector;

auto catMap = labelsWithInstancesWithCategory.find(labelsCategories->category()->c_str());
if (catMap != labelsWithInstancesWithCategory.end())
{
labelWithInstanceVector = &catMap->second;
}
else
{
std::vector<seerep_core_msgs::LabelWithInstance> labelVector;
auto entry = labelsWithInstancesWithCategory.emplace(labelsCategories->category()->c_str(), labelVector);
labelWithInstanceVector = &entry.first->second;
}

if (labelsCategories->labelsWithInstance())
{
labelWithInstanceVector.reserve(labelsCategories->labelsWithInstance()->size());
for (auto label : *labelsCategories->labelsWithInstance())
{
boost::uuids::string_generator gen;
@@ -610,12 +622,11 @@ void CoreFbConversion::fromFbDataLabelsGeneral(
uuidInstance = boost::uuids::nil_uuid();
}

labelWithInstanceVector.push_back(
labelWithInstanceVector->push_back(
seerep_core_msgs::LabelWithInstance{ .label = label->label()->label()->str(),
.labelConfidence = label->label()->confidence(),
.uuidInstance = uuidInstance });
}
labelsWithInstancesWithCategory.emplace(labelsCategories->category()->c_str(), labelWithInstanceVector);
}
}
}
@@ -629,7 +640,20 @@ void CoreFbConversion::fromFbDataLabelsBb2d(
{
for (auto labelsCategories : *labelsBB2d)
{
std::vector<seerep_core_msgs::LabelWithInstance> labelWithInstanceVector;
std::vector<seerep_core_msgs::LabelWithInstance>* labelWithInstanceVector;

auto catMap = labelsWithInstancesWithCategory.find(labelsCategories->category()->c_str());
if (catMap != labelsWithInstancesWithCategory.end())
{
labelWithInstanceVector = &catMap->second;
}
else
{
std::vector<seerep_core_msgs::LabelWithInstance> labelVector;
auto entry = labelsWithInstancesWithCategory.emplace(labelsCategories->category()->c_str(), labelVector);
labelWithInstanceVector = &entry.first->second;
}

for (auto label : *labelsCategories->boundingBox2dLabeled())
{
boost::uuids::string_generator gen;
@@ -643,12 +667,11 @@ void CoreFbConversion::fromFbDataLabelsBb2d(
uuidInstance = boost::uuids::nil_uuid();
}

labelWithInstanceVector.push_back(
labelWithInstanceVector->push_back(
seerep_core_msgs::LabelWithInstance{ .label = label->labelWithInstance()->label()->label()->str(),
.labelConfidence = label->labelWithInstance()->label()->confidence(),
.uuidInstance = uuidInstance });
}
labelsWithInstancesWithCategory.emplace(labelsCategories->category()->c_str(), labelWithInstanceVector);
}
}
}
20 changes: 16 additions & 4 deletions seerep_srv/seerep_core_pb/src/core_pb_conversion.cpp
Original file line number Diff line number Diff line change
@@ -87,7 +87,21 @@ seerep_core_msgs::DatasetIndexable CorePbConversion::fromPb(const seerep::pb::Im
{
for (auto labelsCategories : img.labels_bb())
{
std::vector<seerep_core_msgs::LabelWithInstance> labelWithInstanceVector;
std::vector<seerep_core_msgs::LabelWithInstance>* labelWithInstanceVector;

auto catMap = dataForIndices.labelsWithInstancesWithCategory.find(labelsCategories.category().c_str());
if (catMap != dataForIndices.labelsWithInstancesWithCategory.end())
{
labelWithInstanceVector = &catMap->second;
}
else
{
std::vector<seerep_core_msgs::LabelWithInstance> labelVector;
auto entry =
dataForIndices.labelsWithInstancesWithCategory.emplace(labelsCategories.category().c_str(), labelVector);
labelWithInstanceVector = &entry.first->second;
}

if (!labelsCategories.boundingbox2dlabeled().empty())
{
for (auto label : labelsCategories.boundingbox2dlabeled())
@@ -103,14 +117,12 @@ seerep_core_msgs::DatasetIndexable CorePbConversion::fromPb(const seerep::pb::Im
uuidInstance = boost::uuids::nil_uuid();
}

labelWithInstanceVector.push_back(
labelWithInstanceVector->push_back(
seerep_core_msgs::LabelWithInstance{ .label = label.labelwithinstance().label().label(),
.labelConfidence = label.labelwithinstance().label().confidence(),
.uuidInstance = uuidInstance });
}
}
dataForIndices.labelsWithInstancesWithCategory.emplace(labelsCategories.category().c_str(),
labelWithInstanceVector);
}
}