27 #include <VisionX/interface/components/Calibration.h>
33 #include <DataStructures/DynamicArray.h>
34 #include <Calibration/StereoCalibration.h>
36 #include <Image/ImageProcessor.h>
37 #include <Image/PrimitivesDrawer.h>
52 #include <QStringList>
53 #include <QSortFilterProxyModel>
62 qRegisterMetaType<CByteImage**>(
"CByteImage**");
64 QPointer<QWidget> widgetPointer = getWidget();
65 this->widgetPointer = widgetPointer.data();
67 widget.setupUi(widgetPointer);
71 proxyFinder->setSearchMask(
"*Provider|*Result");
73 widget.chooseProviderLayout->addWidget(proxyFinder);
76 QSizePolicy sizePoli(QSizePolicy::Expanding, QSizePolicy::Expanding);
77 sizePoli.setVerticalStretch(15);
78 imageViewer->setSizePolicy(sizePoli);
80 widget.imageViewerLayout_2->addWidget(imageViewer);
84 featureLearningObjectChooserWidget->hide();
88 featureLearningSaveToMemoryWidget->hide();
112 proxyFinder->setIceManager(this->getIceManager(), proxyFinder->getSelectedProxyName().isEmpty());
114 points = Eigen::ArrayX2f::Zero(4, 2);
115 numSelectedPoints = 0;
118 connect(imageViewer, SIGNAL(selected(
int,
float,
float)),
this, SLOT(addPolygonPoint(
int,
float,
float)));
119 connect(widget.connectButton, SIGNAL(clicked(
bool)),
this, SLOT(connectButtonClicked(
bool)));
120 connect(widget.loadFeaturesButton, SIGNAL(clicked(
bool)),
this, SLOT(loadFeaturesButtonClicked(
bool)));
121 connect(widget.saveFeaturesButton, SIGNAL(clicked(
bool)),
this, SLOT(saveFeaturesButtonClicked(
bool)));
122 connect(widget.pausePlayButton, SIGNAL(clicked(
bool)),
this, SLOT(pausePlayButtonClicked(
bool)));
123 connect(widget.disconnectButton, SIGNAL(clicked(
bool)),
this, SLOT(disconnectButtonClicked(
bool)));
124 connect(widget.addFeaturesButton, SIGNAL(clicked(
bool)),
this, SLOT(addFeaturesButtonClicked(
bool)));
125 connect(widget.clearFeaturesButton, SIGNAL(clicked(
bool)),
this, SLOT(clearFeaturesButtonClicked(
bool)));
126 connect(widget.objectChooserButton, SIGNAL(clicked(
bool)),
this, SLOT(objectChooserButtonClicked(
bool)));
127 connect(widget.saveToMemoryButton, SIGNAL(clicked(
bool)),
this, SLOT(saveToMemoryButtonClicked(
bool)));
128 connect(featureLearningObjectChooserWidget, SIGNAL(accepted()),
this, SLOT(objectChooserAccepted()));
129 connect(featureLearningSaveToMemoryWidget, SIGNAL(accepted()),
this, SLOT(saveToMemoryAccepted()));
139 objectFeatureSet =
new CTexturedFeatureSet(
"objectFeatureSet");
140 viewFeatureSet =
new CTexturedFeatureSet(
"viewFeatureSet");
142 featureCalculator =
new CHarrisSIFTFeatureCalculator(0.01, 1, 10000);
149 int FeatureLearningWidgetController::addFeatures()
152 for (
int i = 0; i < viewFeatureSet->GetSize(); i++)
154 CFeatureEntry* copiedEntry = viewFeatureSet->GetFeature(i)->Clone();
155 Math2d::ApplyHomography(homography, copiedEntry->point, copiedEntry->point);
156 bool addedSuccessfully = objectFeatureSet->AddFeature(copiedEntry,
false);
157 if (addedSuccessfully)
165 void FeatureLearningWidgetController::clearFeatures()
167 objectFeatureSet->Clear();
172 void FeatureLearningWidgetController::loadFeatureSet(QString filePath)
174 std::string filePathStr = filePath.toStdString();
175 const char* filePathCStr = filePathStr.c_str();
176 if (!objectFeatureSet->LoadFromFile(filePathCStr))
178 ARMARX_ERROR <<
" could not load feature set from file " << filePath;
179 widget.lastActionInfoLabel->setText(
"Loading features failed!");
183 ARMARX_INFO <<
"loaded feature set with " << objectFeatureSet->GetSize() <<
" features";
186 mySettings.setValue(
"default_load_dir", currentDir.absoluteFilePath(filePath));
188 widget.lastActionInfoLabel->setText(
"Loaded feature set with " + QString::number(objectFeatureSet->GetSize()) +
" features");
190 float x = fabsf(2.f * objectFeatureSet->m_3dPoint2.x);
191 float y = fabsf(2.f * objectFeatureSet->m_3dPoint2.y);
192 float z = fabsf(2.f * objectFeatureSet->m_3dPoint2.z);
198 widget.widthLineEdit->setText(QString::number(xInt));
199 widget.heightLineEdit->setText(QString::number(yInt));
200 widget.depthLineEdit->setText(QString::number(zInt));
203 points = Eigen::ArrayX2f::Zero(4, 2);
204 numSelectedPoints = 0;
208 void FeatureLearningWidgetController::saveFeatureSet(QString filePath,
float w,
float h,
float d)
215 Math3d::SetVec(objectFeatureSet->m_3dPoint1, -w / 2.0f, -h / 2.0f, -d / 2.0f);
216 Math3d::SetVec(objectFeatureSet->m_3dPoint2, w / 2.0f, -h / 2.0f, -d / 2.0f);
217 Math3d::SetVec(objectFeatureSet->m_3dPoint3, w / 2.0f, h / 2.0f, -d / 2.0f);
218 Math3d::SetVec(objectFeatureSet->m_3dPoint4, -w / 2.0f, h / 2.0f, -d / 2.0f);
220 std::string filePathStr = filePath.toStdString();
221 const char* filePathCStr = filePathStr.c_str();
225 if (!objectFeatureSet->SaveToFile(filePathCStr))
227 ARMARX_ERROR <<
" could not save feature set to file " << filePath;
228 widget.lastActionInfoLabel->setText(
"Saving features failed!");
232 ARMARX_INFO <<
" saved feature set with " << objectFeatureSet->GetSize() <<
" features to file " << filePathCStr;
235 std::string matPath = filePath.toStdString();
236 const unsigned int n = matPath.find_last_of(
".dat");
237 matPath.resize(n - 2);
240 CFloatMatrix*
object = createCuboid(w, h, d);
241 object->SaveToFile(matPath.c_str());
245 mySettings.setValue(
"default_save_dir", currentDir.absoluteFilePath(filePath));
246 widget.lastActionInfoLabel->setText(
"Saved " + QString::number(objectFeatureSet->GetSize()) +
" features into file");
257 points = Eigen::ArrayX2f::Zero(4, 2);
261 for (
int i = 0; i < numImages; i++)
263 delete cameraImages[i];
266 delete [] cameraImages;
268 delete visualizationImage;
272 delete featureCalculator;
274 delete objectFeatureSet;
275 delete viewFeatureSet;
291 double ba0 = b.x -
a.x;
292 double ba1 = b.y -
a.y;
294 double p1a0 = p1.x -
a.x;
295 double p1a1 = p1.y -
a.y;
297 double p2a0 = p2.x -
a.x;
298 double p2a1 = p2.y -
a.y;
300 double cp1 = ba0 * p1a1 - ba1 * p1a0;
301 double cp2 = ba0 * p2a1 - ba1 * p2a0;
303 return cp1 * cp2 >= 0;
308 return SameSide(p,
a, b,
c) && SameSide(p, b,
a,
c) && SameSide(p,
c,
a, b);
311 static double DistancePointStraightLine(
const Vec2d&
a,
const Vec2d& b,
const Vec2d p)
313 Vec2d n = { b.y -
a.y,
a.x - b.x };
314 Math2d::NormalizeVec(n);
316 return std::fabs(Math2d::ScalarProduct(n, p) - Math2d::ScalarProduct(n,
a));
320 void FeatureLearningWidgetController::updateFeatures()
322 if (numSelectedPoints == 0)
324 viewFeatureSet->Clear();
329 if (numSelectedPoints < 4)
334 Vec2d sourcePoints[4];
336 for (
int i = 0; i < numSelectedPoints; i++)
338 sourcePoints[i].x = points(i, 0) * grayImage->width;
339 sourcePoints[i].y = points(i, 1) * grayImage->height;
342 const float w = widget.widthLineEdit->text().toFloat();
343 const float h = widget.heightLineEdit->text().toFloat();
345 Vec2d targetPoints[4];
346 Math2d::SetVec(targetPoints[0], 0, 0);
347 Math2d::SetVec(targetPoints[1], w, 0);
348 Math2d::SetVec(targetPoints[2], w, h);
349 Math2d::SetVec(targetPoints[3], 0, h);
351 LinearAlgebra::DetermineHomography(sourcePoints, targetPoints, 4, homography,
true);
353 objectFeatureSet->SetCornerPoints(targetPoints[0], targetPoints[1], targetPoints[2], targetPoints[3]);
355 CDynamicArray dynamic_array(500);
356 featureCalculator->SetThreshold(0.0001);
357 const int nFeatures = featureCalculator->CalculateFeatures(grayImage, &dynamic_array);
358 viewFeatureSet->Clear();
360 for (
int i = 0; i < nFeatures; i++)
362 CFeatureEntry* pFeatureEntry = (CFeatureEntry*) dynamic_array.GetElement(i);
364 if (PointInPoly(pFeatureEntry->point, sourcePoints[0], sourcePoints[1], sourcePoints[2]) || PointInPoly(pFeatureEntry->point, sourcePoints[2], sourcePoints[3], sourcePoints[0]))
366 const double dThreshold = 10;
368 if (DistancePointStraightLine(sourcePoints[0], sourcePoints[1], pFeatureEntry->point) > dThreshold &&
369 DistancePointStraightLine(sourcePoints[1], sourcePoints[2], pFeatureEntry->point) > dThreshold &&
370 DistancePointStraightLine(sourcePoints[2], sourcePoints[3], pFeatureEntry->point) > dThreshold &&
371 DistancePointStraightLine(sourcePoints[3], sourcePoints[0], pFeatureEntry->point) > dThreshold)
373 viewFeatureSet->AddFeature(pFeatureEntry->Clone(),
false);
381 void FeatureLearningWidgetController::updateSelection()
383 Vec2d sourcePoints[4];
388 for (
int i = 0; i < numSelectedPoints; i++)
390 float relativeX = points(i, 0);
391 float relativeY = points(i, 1);
393 sourcePoints[i].x = relativeX * visualizationImage->width;
394 sourcePoints[i].y = relativeY * visualizationImage->height;
399 if (numSelectedPoints >= 1)
401 PrimitivesDrawer::DrawCircle(visualizationImage, sourcePoints[0], 3, 255, 0, 0, -1);
404 if (numSelectedPoints >= 2)
406 PrimitivesDrawer::DrawCircle(visualizationImage, sourcePoints[1], 3, 255, 0, 0, -1);
407 PrimitivesDrawer::DrawLine(visualizationImage, sourcePoints[0], sourcePoints[1], 0, 0, 255);
410 if (numSelectedPoints >= 3)
412 PrimitivesDrawer::DrawCircle(visualizationImage, sourcePoints[2], 3, 255, 0, 0, -1);
413 PrimitivesDrawer::DrawLine(visualizationImage, sourcePoints[1], sourcePoints[2], 0, 0, 255);
416 if (numSelectedPoints >= 4)
418 PrimitivesDrawer::DrawCircle(visualizationImage, sourcePoints[3], 3, 255, 0, 0, -1);
419 PrimitivesDrawer::DrawLine(visualizationImage, sourcePoints[2], sourcePoints[3], 0, 0, 255);
420 PrimitivesDrawer::DrawLine(visualizationImage, sourcePoints[3], sourcePoints[0], 0, 0, 255);
426 if (numSelectedPoints >= 4)
428 for (
int i = 0; i < viewFeatureSet->GetSize(); i++)
430 const CFeatureEntry* pFeatureEntry = viewFeatureSet->GetFeature(i);
431 PrimitivesDrawer::DrawCircle(visualizationImage, pFeatureEntry->point, 2, 0, 255, 0, -1);
440 std::unique_lock lock(imageMutex);
442 if (!lock.owns_lock())
454 armarx::MetaInfoSizeBasePtr info;
459 if (!waitForImages(imageProviderName))
464 if (getImages(imageProviderName, cameraImages, info) != numImages)
474 ::ImageProcessor::ConvertImage(cameraImages[0], grayImage);
475 ::ImageProcessor::CopyImage(cameraImages[0], visualizationImage);
484 CByteImage** images =
new CByteImage* {visualizationImage};
485 imageViewer->setImages(1, images, IceUtil::Time::microSeconds(info->timeProvided), timeReceived);
519 if (numSelectedPoints >= 4)
521 numSelectedPoints = 0;
524 points(numSelectedPoints, 0) = x;
525 points(numSelectedPoints, 1) = y;
540 QString previousLoadDirectory = mySettings.value(
"default_load_dir").toString();
541 if (previousLoadDirectory ==
"")
543 QString previousSaveDirectory = mySettings.value(
"default_save_dir").toString();
544 if (previousSaveDirectory ==
"")
546 previousLoadDirectory =
"~";
550 previousLoadDirectory = previousSaveDirectory;
553 QString filePath = QFileDialog::getOpenFileName(widgetPointer,
"Load Features", previousLoadDirectory,
"(*.dat)");
554 loadFeatureSet(filePath);
561 if (objectFeatureSet->GetSize() < 1)
563 QMessageBox emptyFeatureSetBox;
564 emptyFeatureSetBox.setText(
"Cannot save empty feature set!");
565 emptyFeatureSetBox.setWindowTitle(
"Feature set empty");
566 emptyFeatureSetBox.exec();
569 float width = widget.widthLineEdit->text().toFloat();
570 float height = widget.heightLineEdit->text().toFloat();
571 float depth = widget.depthLineEdit->text().toFloat();
573 if (width <= 0.f || height <= 0.f || depth <= 0.f)
575 QMessageBox invalidDimensionsBox;
576 invalidDimensionsBox.setText(
"Cannot save feature set with object dimensions <= 0!");
577 invalidDimensionsBox.setWindowTitle(
"Invalid object dimensions");
578 invalidDimensionsBox.exec();
582 QString previousSaveDirectory = mySettings.value(
"default_save_dir").toString();
583 if (previousSaveDirectory ==
"")
585 QString previousLoadDirectory = mySettings.value(
"default_load_dir").toString();
586 if (previousLoadDirectory ==
"")
588 previousSaveDirectory =
"~";
592 previousSaveDirectory = previousLoadDirectory;
595 QString filePath = QFileDialog::getSaveFileName(widgetPointer,
"Save Features", previousSaveDirectory,
"(*.dat)");
596 if (filePath.right(4) !=
".dat")
600 saveFeatureSet(filePath, width, height, depth);
611 isPaused = !isPaused;
613 updateImageMonitorUI();
619 std::unique_lock lock(imageMutex);
621 disconnectFromProvider();
635 void FeatureLearningWidgetController::connectToProvider()
643 imageProviderName = proxyFinder->getSelectedProxyName().toStdString();
644 ARMARX_INFO <<
"Trying to connect to provider " << imageProviderName;
648 usingImageProvider(imageProviderName);
650 catch (Ice::NotRegisteredException& e)
652 ARMARX_ERROR <<
"Cannot connect to the given image provider called " << imageProviderName;
654 QMessageBox cannotConnectToProviderBox;
655 QString cannotConnectToProviderString =
"Cannot connect to the given image provider called " + QString::fromStdString(imageProviderName);
656 cannotConnectToProviderBox.setText(cannotConnectToProviderString);
657 cannotConnectToProviderBox.setWindowTitle(
"Cannot connect to Image Provider");
658 cannotConnectToProviderBox.exec();
661 catch (armarx::LocalException& e)
663 ARMARX_ERROR <<
"Image Provider field is empty, cannot connect!" << imageProviderName;
665 QMessageBox noProviderGivenBox;
666 QString cannotConnectToProviderString =
"Cannot connect to an image provider since the field is empty.";
667 noProviderGivenBox.setText(cannotConnectToProviderString);
668 noProviderGivenBox.setWindowTitle(
"No Provider given");
669 noProviderGivenBox.exec();
673 ARMARX_INFO << getName() <<
" connecting to " << imageProviderName;
679 imageProviderPrx = imageProviderInfo.proxy;
680 numImages = imageProviderInfo.numberImages;
682 StereoCalibrationProviderInterfacePrx calibrationProvider = StereoCalibrationProviderInterfacePrx::checkedCast(imageProviderInfo.proxy);
684 if (!calibrationProvider)
686 ARMARX_WARNING <<
"image provider does not have a stereo calibration interface";
690 undistortImages = calibrationProvider->getImagesAreUndistorted();
691 if (!undistortImages)
693 ARMARX_ERROR <<
"Images expected to be undistorted, but the calibration returns that the images are distorted";
702 std::unique_lock lock(imageMutex);
703 cameraImages =
new CByteImage*[numImages];
705 for (
int i = 0 ; i < numImages ; i++)
712 grayImage =
new CByteImage(imageProviderInfo.imageFormat.dimension.width, imageProviderInfo.imageFormat.dimension.height, CByteImage::eGrayScale);
716 timeProvided = IceUtil::Time::seconds(0);
720 updateImageMonitorUI();
724 emit imageProviderConnected(
true);
729 void FeatureLearningWidgetController::disconnectFromProvider()
737 std::unique_lock lock(imageMutex);
741 for (
int i = 0 ; i < numImages ; i++)
743 delete cameraImages[i];
746 delete [] cameraImages;
748 delete visualizationImage;
752 releaseImageProvider(imageProviderName);
754 imageProviderPrx = 0;
758 numSelectedPoints = 0;
760 QString emptyFeaturesInfoText =
"";
761 widget.lastActionInfoLabel->setText(emptyFeaturesInfoText);
763 updateImageMonitorUI();
766 emit imageProviderConnected(
false);
770 void FeatureLearningWidgetController::updatePausePlayButtonText()
774 widget.pausePlayButton->setText(
"Play");
777 widget.pausePlayButton->setText(
"Pause");
780 void FeatureLearningWidgetController::updateImageMonitorUI()
782 updatePausePlayButtonText();
784 widget.disconnectButton->setEnabled(connected);
785 widget.pausePlayButton->setEnabled(connected);
789 QString providerName = imageProviderName.c_str();
790 QString statusString =
"Status: connected to image provider " + providerName;
793 statusString = statusString +
" - PAUSED";
795 widget.imageMonitorStatusLabel->setText(statusString);
799 widget.imageMonitorStatusLabel->setText(
"Status: not connected");
806 disconnectFromProvider();
811 int numFeaturesAdded = addFeatures();
812 QString featuresString =
" features";
813 if (numFeaturesAdded == 1)
815 featuresString =
" feature";
817 QString addedFeaturesText =
"Added " + QString::number(numFeaturesAdded) + featuresString +
" to the selection";
818 widget.lastActionInfoLabel->setText(addedFeaturesText);
825 QString clearedFeaturesText =
"Cleared the selected features";
826 widget.lastActionInfoLabel->setText(clearedFeaturesText);
832 void FeatureLearningWidgetController::updateFeaturesUI()
836 widget.addFeaturesButton->setEnabled(
false);
837 widget.clearFeaturesButton->setEnabled(
false);
838 widget.featuresInRegionLabel->setText(
"");
839 widget.featuresSelectedLabel->setText(
"");
842 widget.addFeaturesButton->setEnabled(
true);
843 widget.clearFeaturesButton->setEnabled(
true);
844 QString featuresInRegionString =
"Features in Region: ";
845 if (numSelectedPoints == 4)
847 featuresInRegionString += QString::number(viewFeatureSet->GetSize());
849 widget.featuresInRegionLabel->setText(featuresInRegionString);
851 QString featuresSelectedString =
"Features selected: " + QString::number(objectFeatureSet->GetSize());
852 widget.featuresSelectedLabel->setText(featuresSelectedString);
856 CFloatMatrix* FeatureLearningWidgetController::createCuboid(
float w,
float h,
float d)
858 CFloatMatrix*
object =
new CFloatMatrix(6, 36);
861 addRectangle(
object, offset, 0, 0, 0, w, 0, 0, w, h, 0, 0, h, 0, 0, 0, -1);
862 addRectangle(
object, offset, 0, 0, d, w, 0, d, w, h, d, 0, h, d, 0, 0, 1);
863 addRectangle(
object, offset, 0, 0, 0, 0, 0, d, 0, h, d, 0, h, 0, -1, 0, 0);
864 addRectangle(
object, offset, w, 0, 0, w, 0, d, w, h, d, w, h, 0, 1, 0, 0);
865 addRectangle(
object, offset, 0, 0, 0, 0, 0, d, w, 0, d, w, 0, 0, 0, -1, 0);
866 addRectangle(
object, offset, 0, h, 0, 0, h, d, w, h, d, w, h, 0, 0, 1, 0);
868 for (
int i = 0; i < 36; i++)
870 const int offset = 6 * i;
871 object->data[offset + 3] -= w / 2.0;
872 object->data[offset + 4] -= h / 2.0;
873 object->data[offset + 5] -= d / 2.0;
880 void FeatureLearningWidgetController::addRectangle(CFloatMatrix*
object,
int& offset,
881 float x1,
float y1,
float z1,
882 float x2,
float y2,
float z2,
883 float x3,
float y3,
float z3,
884 float x4,
float y4,
float z4,
885 float n1,
float n2,
float n3)
887 addTriangle(
object, offset, x1, y1, z1, x2, y2, z2, x3, y3, z3, n1, n2, n3);
888 addTriangle(
object, offset, x4, y4, z4, x1, y1, z1, x3, y3, z3, n1, n2, n3);
891 void FeatureLearningWidgetController::addTriangle(CFloatMatrix*
object,
int& offset,
892 float x1,
float y1,
float z1,
893 float x2,
float y2,
float z2,
894 float x3,
float y3,
float z3,
895 float n1,
float n2,
float n3)
897 float*
data =
object->data;
899 data[offset + 0] = n1;
900 data[offset + 1] = n2;
901 data[offset + 2] = n3;
902 data[offset + 3] = x1;
903 data[offset + 4] = y1;
904 data[offset + 5] = z1;
907 data[offset + 0] = n1;
908 data[offset + 1] = n2;
909 data[offset + 2] = n3;
910 data[offset + 3] = x2;
911 data[offset + 4] = y2;
912 data[offset + 5] = z2;
915 data[offset + 0] = n1;
916 data[offset + 1] = n2;
917 data[offset + 2] = n3;
918 data[offset + 3] = x3;
919 data[offset + 4] = y3;
920 data[offset + 5] = z3;
927 memoryx::PersistentObjectClassSegmentBasePrx classesSegmentPrx;
930 if (!connectToPriorMemory(classesSegmentPrx, fileManager))
935 memoryx::EntityIdList idList = classesSegmentPrx->getAllEntityIds();
937 ARMARX_INFO <<
"Found " << idList.size() <<
" object classes in the class segments: " << classesSegmentPrx->getReadCollectionsNS();
940 QComboBox* comboBox = featureLearningObjectChooserWidget->getWidget()->objectComboBox;
945 comboBox->addItem(
"",
"");
949 for (memoryx::EntityIdList::iterator iter = idList.begin(); iter != idList.end(); iter++)
951 memoryx::EntityPtr entity = memoryx::EntityPtr::dynamicCast(classesSegmentPrx->getEntityById(*iter));
954 QString objectName = QString::fromStdString(objectClass->getName());
963 if (entity->hasAttribute(
"featureFile"))
966 std::string featureFileName = recognitionWrapper->getFeatureFile();
968 QString datFileName = QString::fromStdString(featureFileName);
970 comboBox->addItem(objectName, datFileName);
979 QSortFilterProxyModel* proxy =
new QSortFilterProxyModel(comboBox);
980 proxy->setSourceModel(comboBox->model());
981 comboBox->model()->setParent(proxy);
982 comboBox->setModel(proxy);
983 comboBox->model()->sort(0);
988 featureLearningObjectChooserWidget->setModal(
true);
989 featureLearningObjectChooserWidget->show();
996 if (objectFeatureSet->GetSize() < 1)
998 QMessageBox emptyFeatureSetBox;
999 emptyFeatureSetBox.setText(
"Cannot save empty feature set!");
1000 emptyFeatureSetBox.setWindowTitle(
"Feature set empty");
1001 emptyFeatureSetBox.exec();
1005 memoryx::PersistentObjectClassSegmentBasePrx classesSegmentPrx;
1008 if (!connectToPriorMemory(classesSegmentPrx, fileManager))
1014 memoryx::EntityIdList idList = classesSegmentPrx->getAllEntityIds();
1016 ARMARX_INFO <<
"Found " << idList.size() <<
" object classes in the class segments: " << classesSegmentPrx->getReadCollectionsNS();
1019 QComboBox* comboBox = featureLearningSaveToMemoryWidget->getWidget()->objectComboBox;
1023 comboBox->addItem(
"",
"");
1025 QMap<QString, bool> hasFeatureFileAlready;
1027 for (memoryx::EntityIdList::iterator iter = idList.begin(); iter != idList.end(); iter++)
1029 memoryx::EntityPtr entity = memoryx::EntityPtr::dynamicCast(classesSegmentPrx->getEntityById(*iter));
1038 QString objectName = QString::fromStdString(entity->getName());
1039 QString objectId = QString::fromStdString(entity->getId());
1042 comboBox->addItem(objectName, objectId);
1044 hasFeatureFileAlready[objectId] = entity->hasAttribute(
"featureFile");
1049 QSortFilterProxyModel* proxy =
new QSortFilterProxyModel(comboBox);
1050 proxy->setSourceModel(comboBox->model());
1051 comboBox->model()->setParent(proxy);
1052 comboBox->setModel(proxy);
1053 comboBox->model()->sort(0);
1055 featureLearningSaveToMemoryWidget->setOverwriteWarningMap(hasFeatureFileAlready);
1057 featureLearningSaveToMemoryWidget->setModal(
true);
1058 featureLearningSaveToMemoryWidget->show();
1063 QString objectPath = featureLearningObjectChooserWidget->getWidget()->objectComboBox->itemData(featureLearningObjectChooserWidget->getWidget()->objectComboBox->currentIndex()).toString();
1065 CTexturedFeatureSet* tempFeatureSet =
new CTexturedFeatureSet(
"tempFeatureSet");
1067 if (objectPath ==
"")
1069 widget.lastActionInfoLabel->setText(
"No object choosen!");
1070 delete tempFeatureSet;
1074 if (!featureLearningObjectChooserWidget->getWidget()->loadFeaturesCheckBox->isChecked())
1076 loadFeatureSet(objectPath);
1077 delete tempFeatureSet;
1081 const char* filePathCStr = objectPath.toStdString().c_str();
1082 if (!tempFeatureSet->LoadFromFile(filePathCStr))
1084 ARMARX_ERROR <<
" could not load .dat file to extract feature dimensions from file " << filePathCStr;
1085 widget.lastActionInfoLabel->setText(
"Loading object dimensions failed!");
1091 widget.lastActionInfoLabel->setText(
"Loaded object dimensions");
1093 float x = fabsf(2.f * tempFeatureSet->m_3dPoint2.x);
1094 float y = fabsf(2.f * tempFeatureSet->m_3dPoint2.y);
1095 float z = fabsf(2.f * tempFeatureSet->m_3dPoint2.z);
1101 widget.widthLineEdit->setText(QString::number(xInt));
1102 widget.heightLineEdit->setText(QString::number(yInt));
1103 widget.depthLineEdit->setText(QString::number(zInt));
1108 delete tempFeatureSet;
1114 QString objectName = featureLearningSaveToMemoryWidget->getWidget()->objectComboBox->itemText(featureLearningSaveToMemoryWidget->getWidget()->objectComboBox->currentIndex());
1115 QString objectId = featureLearningSaveToMemoryWidget->getWidget()->objectComboBox->itemData(featureLearningSaveToMemoryWidget->getWidget()->objectComboBox->currentIndex()).toString();
1120 widget.lastActionInfoLabel->setText(
"No object choosen!");
1125 memoryx::PersistentObjectClassSegmentBasePrx classesSegmentPrx;
1128 if (!connectToPriorMemory(classesSegmentPrx, fileManager))
1136 memoryx::EntityPtr entity = memoryx::EntityPtr::dynamicCast(classesSegmentPrx->getEntityById(objectId.toStdString()));
1147 const std::string ns = classesSegmentPrx->getWriteCollectionNS();
1148 const size_t found = ns.find_first_of(
'.');
1149 std::string filesDBName = (found != std::string::npos) ? ns.substr(0, found) :
"";
1151 QString tempDatFilePath = QDir::tempPath();
1153 tempDatFilePath +=
"/" + objectName +
"_temp.dat";
1156 float w = widget.widthLineEdit->text().toFloat();
1157 float h = widget.heightLineEdit->text().toFloat();
1158 float d = widget.depthLineEdit->text().toFloat();
1160 Math3d::SetVec(objectFeatureSet->m_3dPoint1, -w / 2.0f, -h / 2.0f, -d / 2.0f);
1161 Math3d::SetVec(objectFeatureSet->m_3dPoint2, w / 2.0f, -h / 2.0f, -d / 2.0f);
1162 Math3d::SetVec(objectFeatureSet->m_3dPoint3, w / 2.0f, h / 2.0f, -d / 2.0f);
1163 Math3d::SetVec(objectFeatureSet->m_3dPoint4, -w / 2.0f, h / 2.0f, -d / 2.0f);
1167 if (!objectFeatureSet->SaveToFile(tempDatFilePath.toStdString().c_str()))
1169 ARMARX_ERROR <<
" could not save temp feature set to file " << tempDatFilePath;
1170 widget.lastActionInfoLabel->setText(
"Saving features to memory failed!");
1174 ARMARX_INFO <<
" saved temp feature set with " << objectFeatureSet->GetSize() <<
" features to file " << tempDatFilePath;
1178 recognitionWrapper->setFeatureFile(tempDatFilePath.toStdString(), filesDBName);
1179 objectRecognitionWrapper->setRecognitionMethod(
"TexturedObjectRecognition");
1180 classesSegmentPrx->updateEntity(objectClass->getId(), objectClass);
1184 bool FeatureLearningWidgetController::connectToPriorMemory(memoryx::PersistentObjectClassSegmentBasePrx& classesSegmentPrx,
memoryx::GridFileManagerPtr& fileManager)
1188 std::string priorKnowledgeProxyName =
"PriorKnowledge";
1191 memoryx::PriorKnowledgeInterfacePrx priorKnowledgePrx;
1192 memoryx::PersistentObjectClassSegmentBasePrx classesSegmentPrxTemp;
1193 memoryx::CommonStorageInterfacePrx databasePrx;
1196 priorKnowledgePrx = getProxy<memoryx::PriorKnowledgeInterfacePrx>(priorKnowledgeProxyName);
1197 classesSegmentPrxTemp = priorKnowledgePrx->getObjectClassesSegment();
1198 databasePrx = priorKnowledgePrx->getCommonStorage();
1201 memoryx::CollectionInterfacePrx coll = databasePrx->requestCollection(
"memdb.Prior_Objects");
1203 classesSegmentPrxTemp->addReadCollection(coll);
1208 classesSegmentPrx = classesSegmentPrxTemp;
1209 fileManager = fileManagerTemp;
1212 catch (Ice::Exception& e)
1216 QMessageBox priorMemoryNotConnectedBox;
1217 priorMemoryNotConnectedBox.setText(
"Cannot connect to PriorMemory! Ensure that PriorMemory is present.");
1218 priorMemoryNotConnectedBox.setWindowTitle(
"PriorMemory not available");
1219 priorMemoryNotConnectedBox.exec();