@@ -48,7 +48,7 @@ DBReader::DBReader(const std::string & databasePath,
48
48
bool ignoreGoalDelay,
49
49
bool goalsIgnored,
50
50
int startId,
51
- int cameraIndex ,
51
+ const std::vector< unsigned int > & cameraIndices ,
52
52
int stopId,
53
53
bool intermediateNodesIgnored,
54
54
bool landmarksIgnored,
@@ -63,7 +63,7 @@ DBReader::DBReader(const std::string & databasePath,
63
63
_goalsIgnored (goalsIgnored),
64
64
_startId (startId),
65
65
_stopId (stopId),
66
- _cameraIndex (cameraIndex ),
66
+ _cameraIndices (cameraIndices ),
67
67
_intermediateNodesIgnored (intermediateNodesIgnored),
68
68
_landmarksIgnored (landmarksIgnored),
69
69
_featuresIgnored (featuresIgnored),
@@ -94,7 +94,7 @@ DBReader::DBReader(const std::list<std::string> & databasePaths,
94
94
bool ignoreGoalDelay,
95
95
bool goalsIgnored,
96
96
int startId,
97
- int cameraIndex ,
97
+ const std::vector< unsigned int > & cameraIndices ,
98
98
int stopId,
99
99
bool intermediateNodesIgnored,
100
100
bool landmarksIgnored,
@@ -109,7 +109,7 @@ DBReader::DBReader(const std::list<std::string> & databasePaths,
109
109
_goalsIgnored (goalsIgnored),
110
110
_startId (startId),
111
111
_stopId (stopId),
112
- _cameraIndex (cameraIndex ),
112
+ _cameraIndices (cameraIndices ),
113
113
_intermediateNodesIgnored (intermediateNodesIgnored),
114
114
_landmarksIgnored (landmarksIgnored),
115
115
_featuresIgnored (featuresIgnored),
@@ -557,34 +557,77 @@ SensorData DBReader::getNextData(SensorCaptureInfo * info)
557
557
}
558
558
559
559
data.uncompressData ();
560
- if (data.cameraModels ().size () > 1 &&
561
- _cameraIndex >= 0 )
560
+ std::map<int , int > cameraOldNewIndices;
561
+ std::vector<CameraModel> dbModels = data.cameraModels ();
562
+ if (dbModels.empty () && !data.stereoCameraModels ().empty ())
562
563
{
563
- if (_cameraIndex < ( int ) data.cameraModels ().size ())
564
+ for ( size_t i= 0 ; i< data.stereoCameraModels ().size (); ++i )
564
565
{
565
- // select one camera
566
- int subImageWidth = data.imageRaw ().cols /data.cameraModels ().size ();
567
- cv::Mat image;
566
+ dbModels.push_back (data.stereoCameraModels ()[i].left ());
567
+ }
568
+ }
569
+ if (dbModels.size () > 1 &&
570
+ !_cameraIndices.empty ())
571
+ {
572
+ cv::Mat combinedImages;
573
+ cv::Mat combinedDepthImages;
574
+ std::vector<CameraModel> combinedModels;
575
+ std::vector<StereoCameraModel> combinedStereoModels;
576
+ for (size_t i=0 ; i<_cameraIndices.size (); ++i)
577
+ {
578
+ UASSERT_MSG (_cameraIndices[i] < dbModels.size (), uFormat (" DBReader: camera index %ld is not valid (should be between 0 and %ld)" ,
579
+ _cameraIndices[i], dbModels.size ()-1 ).c_str ());
580
+
581
+ int addedCameras = std::max (combinedModels.size (), combinedStereoModels.size ());
582
+
583
+ int subImageWidth = data.imageRaw ().cols /dbModels.size ();
568
584
UASSERT (!data.imageRaw ().empty () &&
569
- data.imageRaw ().cols % data.cameraModels ().size () == 0 &&
570
- _cameraIndex*subImageWidth < data.imageRaw ().cols );
571
- image= cv::Mat (data.imageRaw (),
572
- cv::Rect (_cameraIndex*subImageWidth, 0 , subImageWidth, data.imageRaw ().rows )).clone ();
585
+ data.imageRaw ().cols % dbModels.size () == 0 &&
586
+ (int )_cameraIndices[i]*subImageWidth < data.imageRaw ().cols );
587
+ if (combinedImages.empty ())
588
+ {
589
+ // initialize with first camera
590
+ combinedImages = cv::Mat (data.imageRaw ().rows , subImageWidth*(_cameraIndices.size ()-i), data.imageRaw ().type ());
591
+ }
592
+
593
+ cv::Mat fromROI = cv::Mat (data.imageRaw (), cv::Rect (_cameraIndices[i]*subImageWidth, 0 , subImageWidth, data.imageRaw ().rows ));
594
+ cv::Mat toROI = cv::Mat (combinedImages, cv::Rect (addedCameras*subImageWidth, 0 , subImageWidth, combinedImages.rows ));
595
+ fromROI.copyTo (toROI);
573
596
574
597
cv::Mat depth;
575
598
if (!data.depthOrRightRaw ().empty ())
576
599
{
577
- UASSERT (data.depthOrRightRaw ().cols % data.cameraModels ().size () == 0 &&
578
- subImageWidth == data.depthOrRightRaw ().cols /(int )data.cameraModels ().size () &&
579
- _cameraIndex*subImageWidth < data.depthOrRightRaw ().cols );
580
- depth = cv::Mat (data.depthOrRightRaw (),
581
- cv::Rect (_cameraIndex*subImageWidth, 0 , subImageWidth, data.depthOrRightRaw ().rows )).clone ();
600
+ subImageWidth = data.depthOrRightRaw ().cols /dbModels.size ();
601
+ UASSERT (data.depthOrRightRaw ().cols % dbModels.size () == 0 &&
602
+ subImageWidth == data.depthOrRightRaw ().cols /(int )dbModels.size () &&
603
+ (int )_cameraIndices[i]*subImageWidth < data.depthOrRightRaw ().cols );
604
+ if (combinedDepthImages.empty ())
605
+ {
606
+ // initialize with first camera
607
+ combinedDepthImages = cv::Mat (data.depthOrRightRaw ().rows , subImageWidth*(_cameraIndices.size ()-i), data.depthOrRightRaw ().type ());
608
+ }
609
+ fromROI = cv::Mat (data.depthOrRightRaw (), cv::Rect (_cameraIndices[i]*subImageWidth, 0 , subImageWidth, data.depthOrRightRaw ().rows ));
610
+ toROI = cv::Mat (combinedDepthImages, cv::Rect (addedCameras*subImageWidth, 0 , subImageWidth, combinedDepthImages.rows ));
611
+ fromROI.copyTo (toROI);
612
+ }
613
+
614
+ if (!data.cameraModels ().empty ())
615
+ {
616
+ combinedModels.push_back (data.cameraModels ()[_cameraIndices[i]]);
617
+ }
618
+ else
619
+ {
620
+ combinedStereoModels.push_back (data.stereoCameraModels ()[_cameraIndices[i]]);
582
621
}
583
- data.setRGBDImage (image, depth, data.cameraModels ().at (_cameraIndex));
622
+ cameraOldNewIndices.insert (std::make_pair (_cameraIndices[i], i));
623
+ }
624
+ if (!combinedModels.empty ())
625
+ {
626
+ data.setRGBDImage (combinedImages, combinedDepthImages, combinedModels);
584
627
}
585
628
else
586
629
{
587
- UWARN ( " DBReader: Camera index %d doesn't exist! Camera models = %d. " , _cameraIndex, ( int )data. cameraModels (). size () );
630
+ data. setStereoImage (combinedImages, combinedDepthImages, combinedStereoModels );
588
631
}
589
632
}
590
633
data.setId (seq);
@@ -623,7 +666,40 @@ SensorData DBReader::getNextData(SensorCaptureInfo * info)
623
666
(keypoints3D.empty () || keypoints.size () == keypoints3D.size ()) &&
624
667
(descriptors.empty () || (int )keypoints.size () == descriptors.rows ))
625
668
{
626
- data.setFeatures (keypoints, keypoints3D, descriptors);
669
+ if (!cameraOldNewIndices.empty ())
670
+ {
671
+ cv::Mat newDescriptors;
672
+ std::vector<cv::KeyPoint> newKeypoints;
673
+ std::vector<cv::Point3f> newKeypoints3D;
674
+ UASSERT (!dbModels.empty () && dbModels[0 ].imageWidth ()>0 );
675
+ int subImageWidth = dbModels[0 ].imageWidth ();
676
+ for (size_t i = 0 ; i<keypoints.size (); ++i)
677
+ {
678
+ int cameraIndex = int (keypoints.at (i).pt .x / subImageWidth);
679
+ UASSERT_MSG (cameraIndex >= 0 && cameraIndex < (int )dbModels.size (),
680
+ uFormat (" cameraIndex=%d, db models=%d, kpt.x=%f, image width=%d" ,
681
+ cameraIndex, (int )dbModels.size (), keypoints[i].pt .x , subImageWidth).c_str ());
682
+ if (cameraOldNewIndices.find (cameraIndex) != cameraOldNewIndices.end ())
683
+ {
684
+ int newCameraIndex = cameraOldNewIndices.at (cameraIndex);
685
+ newKeypoints.push_back (keypoints[i]);
686
+ newKeypoints.back ().pt .x += (newCameraIndex-cameraIndex)*subImageWidth;
687
+ if (!keypoints3D.empty ())
688
+ {
689
+ newKeypoints3D.push_back (keypoints3D.at (i));
690
+ }
691
+ if (!descriptors.empty ())
692
+ {
693
+ newDescriptors.push_back (descriptors.row (i));
694
+ }
695
+ }
696
+ }
697
+ data.setFeatures (newKeypoints, newKeypoints3D, newDescriptors);
698
+ }
699
+ else
700
+ {
701
+ data.setFeatures (keypoints, keypoints3D, descriptors);
702
+ }
627
703
}
628
704
else if (!_featuresIgnored && !keypoints.empty () && (!keypoints3D.empty () || !descriptors.empty ()))
629
705
{
0 commit comments