40 #include <pcl/common/common.h>
41 #include <pcl/common/centroid.h>
42 #include <pcl/common/io.h>
55 bool unknownSpaceFilled,
58 cv::Point3f viewpoint(0,0,0);
72 const cv::Point3f & viewpoint,
76 bool unknownSpaceFilled,
83 const cv::Mat & scanHitIn,
84 const cv::Mat & scanNoHitIn,
85 const cv::Point3f & viewpoint,
89 bool unknownSpaceFilled,
92 if(scanHitIn.empty() && scanNoHitIn.empty())
99 if(scanHitIn.channels()>2)
101 std::vector<cv::Mat> channels;
102 cv::split(scanHitIn,channels);
103 while(channels.size()>2)
107 cv::merge(channels,scanHit);
111 scanHit = scanHitIn.clone();
113 if(scanNoHitIn.channels()>2)
115 std::vector<cv::Mat> channels;
116 cv::split(scanNoHitIn,channels);
117 while(channels.size()>2)
121 cv::merge(channels,scanNoHit);
125 scanNoHit = scanNoHitIn;
128 std::map<int, Transform> poses;
131 std::map<int, std::pair<cv::Mat, cv::Mat> > scans;
132 scans.insert(std::make_pair(1, std::make_pair(scanHit, scanNoHit)));
134 std::map<int, cv::Point3f> viewpoints;
135 viewpoints.insert(std::make_pair(1, viewpoint));
138 cv::Mat map8S =
create2DMap(poses, scans, viewpoints, cellSize, unknownSpaceFilled, xMin, yMin, 0.0
f, scanMaxRange);
141 std::list<int> emptyIndices;
142 for(
unsigned int i=0;
i< map8S.total(); ++
i)
144 if(map8S.data[
i] == 0)
146 emptyIndices.push_back(
i);
152 if(emptyIndices.size())
154 empty = cv::Mat(1, (
int)emptyIndices.size(), CV_32FC2);
156 for(std::list<int>::iterator
iter=emptyIndices.begin();
iter!=emptyIndices.end(); ++
iter)
158 int y = *
iter / map8S.cols;
159 int x = *
iter -
y*map8S.cols;
160 cv::Vec2f * ptr =
empty.ptr<cv::Vec2f>();
161 ptr[
i][0] = (
float(
x))*cellSize + xMin;
162 ptr[
i][1] = (
float(
y))*cellSize + yMin;
168 if(scanMaxRange > cellSize)
192 const std::map<int, Transform> & posesIn,
193 const std::map<
int, std::pair<cv::Mat, cv::Mat> > & occupancy,
199 float footprintRadius)
202 UDEBUG(
"cellSize=%f m, minMapSize=%f m, erode=%d", cellSize, minMapSize, erode?1:0);
205 std::map<int, cv::Mat> emptyLocalMaps;
206 std::map<int, cv::Mat> occupiedLocalMaps;
208 std::list<std::pair<int, Transform> > poses;
210 for(std::map<int, Transform>::const_reverse_iterator
iter = posesIn.rbegin();
iter!=posesIn.rend(); ++
iter)
214 poses.push_front(*
iter);
218 poses.push_back(*
iter);
222 float minX=-minMapSize/2.0, minY=-minMapSize/2.0, maxX=minMapSize/2.0, maxY=minMapSize/2.0;
223 bool undefinedSize = minMapSize == 0.0f;
224 for(std::list<std::pair<int, Transform> >::const_iterator
iter = poses.begin();
iter!=poses.end(); ++
iter)
228 float x =
iter->second.x();
229 float y =
iter->second.y();
234 undefinedSize =
false;
251 const std::pair<cv::Mat, cv::Mat> & pair = occupancy.at(
iter->first);
256 if(pair.first.rows > 1 && pair.first.cols == 1)
258 UFATAL(
"Occupancy local maps should be 1 row and X cols! (rows=%d cols=%d)", pair.first.rows, pair.first.cols);
260 cv::Mat ground(1, pair.first.cols, CV_32FC2);
261 for(
int i=0;
i<ground.cols; ++
i)
263 const float * vi = pair.first.ptr<
float>(0,
i);
264 float * vo = ground.ptr<
float>(0,
i);
266 if(pair.first.channels() != 2 && pair.first.channels() != 5)
278 else if(maxX < vo[0])
283 else if(maxY < vo[1])
286 emptyLocalMaps.insert(std::make_pair(
iter->first, ground));
292 if(pair.second.rows > 1 && pair.second.cols == 1)
294 UFATAL(
"Occupancy local maps should be 1 row and X cols! (rows=%d cols=%d)", pair.second.rows, pair.second.cols);
296 cv::Mat obstacles(1, pair.second.cols, CV_32FC2);
297 for(
int i=0;
i<obstacles.cols; ++
i)
299 const float * vi = pair.second.ptr<
float>(0,
i);
300 float * vo = obstacles.ptr<
float>(0,
i);
302 if(pair.second.channels() != 2 && pair.second.channels() != 5)
314 else if(maxX < vo[0])
319 else if(maxY < vo[1])
322 occupiedLocalMaps.insert(std::make_pair(
iter->first, obstacles));
329 if(minX != maxX && minY != maxY)
332 float margin = cellSize*10.0f;
333 xMin = minX-margin-cellSize/2.0f;
334 yMin = minY-margin-cellSize/2.0f;
335 float xMax = maxX+margin;
336 float yMax = maxY+margin;
337 if(
fabs((yMax - yMin) / cellSize) > 30000 ||
338 fabs((xMax - xMin) / cellSize) > 30000)
340 UERROR(
"Large map size!! map min=(%f, %f) max=(%f,%f). "
341 "There's maybe an error with the poses provided! The map will not be created!",
342 xMin, yMin, xMax, yMax);
346 UDEBUG(
"map min=(%f, %f) max=(%f,%f)", xMin, yMin, xMax, yMax);
349 map = cv::Mat::ones((yMax - yMin) / cellSize, (xMax - xMin) / cellSize, CV_8S)*-1;
350 for(std::list<std::pair<int, Transform> >::const_iterator kter = poses.begin(); kter!=poses.end(); ++kter)
352 std::map<int, cv::Mat >::iterator
iter = emptyLocalMaps.find(kter->first);
353 std::map<int, cv::Mat >::iterator jter = occupiedLocalMaps.find(kter->first);
354 if(
iter!=emptyLocalMaps.end())
356 for(
int i=0;
i<
iter->second.cols; ++
i)
358 float * ptf =
iter->second.
ptr<
float>(0,
i);
359 cv::Point2i pt((ptf[0]-xMin)/cellSize, (ptf[1]-yMin)/cellSize);
360 UASSERT_MSG(pt.y>0 && pt.y<map.rows && pt.x>0 && pt.x<map.cols,
361 uFormat(
"id=%d, map min=(%f, %f) max=(%f,%f) map=%dx%d pt=(%d,%d)", kter->first, xMin, yMin, xMax, yMax, map.cols, map.rows, pt.x, pt.y).c_str());
362 char &
value = map.at<
char>(pt.y, pt.x);
370 if(footprintRadius >= cellSize*1.5
f)
373 cv::Point2i ptBegin((kter->second.x()-footprintRadius-xMin)/cellSize, (kter->second.y()-footprintRadius-yMin)/cellSize);
374 cv::Point2i ptEnd((kter->second.x()+footprintRadius-xMin)/cellSize, (kter->second.y()+footprintRadius-yMin)/cellSize);
377 if(ptEnd.x >= map.cols)
378 ptEnd.x = map.cols-1;
382 if(ptEnd.y >= map.rows)
383 ptEnd.y = map.rows-1;
384 for(
int i=ptBegin.x;
i<ptEnd.x; ++
i)
386 for(
int j=ptBegin.y;
j<ptEnd.y; ++
j)
388 map.at<
char>(
j,
i) = -2;
393 if(jter!=occupiedLocalMaps.end())
395 for(
int i=0;
i<jter->second.cols; ++
i)
397 float * ptf = jter->second.ptr<
float>(0,
i);
398 cv::Point2i pt((ptf[0]-xMin)/cellSize, (ptf[1]-yMin)/cellSize);
399 UASSERT_MSG(pt.y>0 && pt.y<map.rows && pt.x>0 && pt.x<map.cols,
400 uFormat(
"id=%d: map min=(%f, %f) max=(%f,%f) map=%dx%d pt=(%d,%d)", kter->first, xMin, yMin, xMax, yMax, map.cols, map.rows, pt.x, pt.y).c_str());
401 char &
value = map.at<
char>(pt.y, pt.x);
413 cv::Mat updatedMap = map.clone();
414 std::list<std::pair<int, int> > obstacleIndices;
415 for(
int i=0;
i<map.rows; ++
i)
417 for(
int j=0;
j<map.cols; ++
j)
419 if(map.at<
char>(
i,
j) == -2)
421 updatedMap.at<
char>(
i,
j) = 0;
424 if(
i >=2 && i<map.rows-2 && j>=2 &&
j<map.cols-2)
426 if(map.at<
char>(
i,
j) == -1 &&
427 map.at<
char>(
i+1,
j) != -1 &&
428 map.at<
char>(
i-1,
j) != -1 &&
429 map.at<
char>(
i,
j+1) != -1 &&
430 map.at<
char>(
i,
j-1) != -1)
432 updatedMap.at<
char>(
i,
j) = 0;
434 else if(map.at<
char>(
i,
j) == 100)
438 if((map.at<
char>(
i-1,
j) == 0 || map.at<
char>(
i-1,
j) == -2) &&
439 map.at<
char>(
i-2,
j) == -1)
441 updatedMap.at<
char>(
i-1,
j) = -1;
443 else if((map.at<
char>(
i+1,
j) == 0 || map.at<
char>(
i+1,
j) == -2) &&
444 map.at<
char>(
i+2,
j) == -1)
446 updatedMap.at<
char>(
i+1,
j) = -1;
448 if((map.at<
char>(
i,
j-1) == 0 || map.at<
char>(
i,
j-1) == -2) &&
449 map.at<
char>(
i,
j-2) == -1)
451 updatedMap.at<
char>(
i,
j-1) = -1;
453 else if((map.at<
char>(
i,
j+1) == 0 || map.at<
char>(
i,
j+1) == -2) &&
454 map.at<
char>(
i,
j+2) == -1)
456 updatedMap.at<
char>(
i,
j+1) = -1;
461 obstacleIndices.push_back(std::make_pair(
i,
j));
464 else if(map.at<
char>(
i,
j) == 0)
467 if(map.at<
char>(
i-1,
j) == 100 &&
468 map.at<
char>(
i+1,
j) == 100)
470 updatedMap.at<
char>(
i,
j) = -1;
472 else if(map.at<
char>(
i,
j-1) == 100 &&
473 map.at<
char>(
i,
j+1) == 100)
475 updatedMap.at<
char>(
i,
j) = -1;
486 cv::Mat erodedMap = map.clone();
487 for(std::list<std::pair<int,int> >::
iterator iter = obstacleIndices.begin();
488 iter!= obstacleIndices.end();
492 int j =
iter->second;
493 int touchEmpty = (map.at<
char>(
i+1,
j) == 0?1:0) +
494 (map.at<
char>(
i-1,
j) == 0?1:0) +
495 (map.at<
char>(
i,
j+1) == 0?1:0) +
496 (map.at<
char>(
i,
j-1) == 0?1:0);
497 if(touchEmpty>=3 && map.at<
char>(
i+1,
j) != -1 &&
498 map.at<
char>(
i-1,
j) != -1 &&
499 map.at<
char>(
i,
j+1) != -1 &&
500 map.at<
char>(
i,
j-1) != -1)
502 erodedMap.at<
char>(
i,
j) = 0;
529 const std::map<
int, pcl::PointCloud<pcl::PointXYZ>::Ptr > & scans,
531 bool unknownSpaceFilled,
537 std::map<int, cv::Point3f > viewpoints;
538 std::map<int, std::pair<cv::Mat, cv::Mat> > scansCv;
539 for(std::map<
int, pcl::PointCloud<pcl::PointXYZ>::Ptr >::const_iterator
iter = scans.begin();
iter!=scans.end(); ++
iter)
555 const std::map<
int, pcl::PointCloud<pcl::PointXYZ>::Ptr > & scans,
556 const std::map<int, cv::Point3f > & viewpoints,
558 bool unknownSpaceFilled,
564 std::map<int, std::pair<cv::Mat, cv::Mat> > scansCv;
565 for(std::map<
int, pcl::PointCloud<pcl::PointXYZ>::Ptr >::const_iterator
iter = scans.begin();
iter!=scans.end(); ++
iter)
581 const std::map<
int, std::pair<cv::Mat, cv::Mat> > & scans,
582 const std::map<int, cv::Point3f > & viewpoints,
584 bool unknownSpaceFilled,
590 UDEBUG(
"poses=%d, scans = %d scanMaxRange=%f", poses.size(), scans.size(), scanMaxRange);
593 std::map<int, std::pair<cv::Mat, cv::Mat> > localScans;
595 pcl::PointCloud<pcl::PointXYZ> minMax;
596 if(minMapSize > 0.0
f)
598 minMax.push_back(pcl::PointXYZ(-minMapSize/2.0, -minMapSize/2.0, 0));
599 minMax.push_back(pcl::PointXYZ(minMapSize/2.0, minMapSize/2.0, 0));
601 for(std::map<int, Transform>::const_iterator
iter = poses.begin();
iter!=poses.end(); ++
iter)
603 std::map<int, std::pair<cv::Mat, cv::Mat> >::const_iterator jter=scans.find(
iter->first);
604 UASSERT_MSG(jter->second.first.empty() || jter->second.first.type() == CV_32FC2,
"Input scans should be 2D to avoid any confusion.");
605 UASSERT_MSG(jter->second.second.empty() || jter->second.second.type() == CV_32FC2,
"Input scans should be 2D to avoid any confusion.");
606 if(jter!=scans.end() && (jter->second.first.cols || jter->second.second.cols))
615 minMax.push_back(
min);
616 minMax.push_back(
max);
621 minMax.push_back(
min);
622 minMax.push_back(
max);
624 minMax.push_back(pcl::PointXYZ(
iter->second.x(),
iter->second.y(),
iter->second.z()));
626 std::map<int, cv::Point3f>::const_iterator kter=viewpoints.find(
iter->first);
627 if(kter!=viewpoints.end())
629 minMax.push_back(pcl::PointXYZ(
iter->second.x()+kter->second.x,
iter->second.y()+kter->second.y,
iter->second.z()+kter->second.z));
632 localScans.insert(std::make_pair(
iter->first, std::make_pair(hit, noHit)));
644 float margin = cellSize*10.0f;
645 xMin = (unknownSpaceFilled && scanMaxRange > 0 && -scanMaxRange <
min.x?-scanMaxRange:
min.x) - margin;
646 yMin = (unknownSpaceFilled && scanMaxRange > 0 && -scanMaxRange <
min.y?-scanMaxRange:
min.y) - margin;
647 float xMax = (unknownSpaceFilled && scanMaxRange > 0 && scanMaxRange >
max.x?scanMaxRange:
max.x) + margin;
648 float yMax = (unknownSpaceFilled && scanMaxRange > 0 && scanMaxRange >
max.y?scanMaxRange:
max.y) + margin;
650 UDEBUG(
"map min=(%fm, %fm) max=(%fm,%fm) (margin=%fm, cellSize=%fm, scan range=%f, min=[%fm,%fm] max=[%fm,%fm])",
651 xMin, yMin, xMax, yMax, margin, cellSize, scanMaxRange,
min.x,
min.y,
max.x,
max.y);
655 map = cv::Mat::ones((yMax - yMin) / cellSize, (xMax - xMin) / cellSize, CV_8S)*-1;
656 UDEBUG(
"map size = %dx%d", map.cols, map.rows);
658 float scanMaxRangeSqr = scanMaxRange * scanMaxRange;
659 for(std::map<
int, std::pair<cv::Mat, cv::Mat> >::
iterator iter = localScans.begin();
iter!=localScans.end(); ++
iter)
662 cv::Point3f viewpoint(0,0,0);
663 std::map<int, cv::Point3f>::const_iterator kter=viewpoints.find(
iter->first);
664 if(kter!=viewpoints.end())
666 viewpoint = kter->second;
668 cv::Point2i start(((pose.
x()+viewpoint.x)-xMin)/cellSize, ((pose.
y()+viewpoint.y)-yMin)/cellSize);
671 for(
int i=0;
i<
iter->second.first.cols; ++
i)
673 const float * ptr =
iter->second.first.
ptr<
float>(0,
i);
674 bool ignore = scanMaxRange>cellSize &&
uNormSquared(ptr[0]-(pose.
x()+viewpoint.x)+cellSize, ptr[1]-(pose.
y()+viewpoint.y)+cellSize) > scanMaxRangeSqr;
677 cv::Point2i
end((ptr[0]-xMin)/cellSize, (ptr[1]-yMin)/cellSize);
680 map.at<
char>(
end.y,
end.x) = 100;
686 for(
int i=0;
i<
iter->second.first.cols; ++
i)
688 const float * ptr =
iter->second.first.
ptr<
float>(0,
i);
690 cv::Vec2f pt(ptr[0], ptr[1]);
691 if(scanMaxRange>cellSize)
693 cv::Vec2f
v(pt[0]-(pose.
x()+viewpoint.x), pt[1]-(pose.
y()+viewpoint.y));
694 float n = cv::norm(
v);
695 if(
n > scanMaxRange+cellSize)
697 v = (
v/
n) * scanMaxRange;
698 pt[0] = pose.
x()+viewpoint.x +
v[0];
699 pt[1] = pose.
y()+viewpoint.y +
v[1];
703 cv::Point2i
end((pt[0]-xMin)/cellSize, (pt[1]-yMin)/cellSize);
706 if(localScans.size() > 1 || map.at<
char>(
end.y,
end.x) != 0)
713 for(
int i=0;
i<
iter->second.second.cols; ++
i)
715 const float * ptr =
iter->second.second.
ptr<
float>(0,
i);
717 cv::Vec2f pt(ptr[0], ptr[1]);
718 if(scanMaxRange>cellSize)
720 cv::Vec2f
v(pt[0]-(pose.
x()+viewpoint.x), pt[1]-(pose.
y()+viewpoint.y));
721 float n = cv::norm(
v);
722 if(
n > scanMaxRange+cellSize)
724 v = (
v/
n) * scanMaxRange;
725 pt[0] = pose.
x()+viewpoint.x +
v[0];
726 pt[1] = pose.
y()+viewpoint.y +
v[1];
730 cv::Point2i
end((pt[0]-xMin)/cellSize, (pt[1]-yMin)/cellSize);
733 if(localScans.size() > 1 || map.at<
char>(
end.y,
end.x) != 0)
736 if(map.at<
char>(
end.y,
end.x) == -1)
738 map.at<
char>(
end.y,
end.x) = 0;
744 UDEBUG(
"Ray trace known space=%fs",
timer.ticks());
747 if(unknownSpaceFilled && scanMaxRange > 0)
749 float angleIncrement = CV_PI/90.0f;
750 for(std::map<
int, std::pair<cv::Mat, cv::Mat> >::
iterator iter = localScans.begin();
iter!=localScans.end(); ++
iter)
752 if(
iter->second.first.cols > 2)
754 if(scanMaxRange > cellSize)
757 cv::Point3f viewpoint(0,0,0);
758 std::map<int, cv::Point3f>::const_iterator kter=viewpoints.find(
iter->first);
759 if(kter!=viewpoints.end())
761 viewpoint = kter->second;
763 cv::Point2i start(((pose.
x()+viewpoint.x)-xMin)/cellSize, ((pose.
y()+viewpoint.y)-yMin)/cellSize);
767 cv::Mat
rotation = (cv::Mat_<float>(2,2) <<
cos(angleIncrement), -
sin(angleIncrement),
768 sin(angleIncrement),
cos(angleIncrement));
769 cv::Mat
origin(2,1,CV_32F), obsFirst(2,1,CV_32F), obsLast(2,1,CV_32F);
770 origin.at<
float>(0) = pose.
x()+viewpoint.x;
771 origin.at<
float>(1) = pose.
y()+viewpoint.y;
772 obsFirst.at<
float>(0) =
iter->second.first.
ptr<
float>(0,0)[0];
773 obsFirst.at<
float>(1) =
iter->second.first.
ptr<
float>(0,0)[1];
774 obsLast.at<
float>(0) =
iter->second.first.
ptr<
float>(0,
iter->second.first.cols-2)[0];
775 obsLast.at<
float>(1) =
iter->second.first.
ptr<
float>(0,
iter->second.first.cols-2)[1];
776 cv::Mat firstVector(3,1,CV_32F), lastVector(3,1,CV_32F);
777 firstVector.at<
float>(0) = obsFirst.at<
float>(0) -
origin.at<
float>(0);
778 firstVector.at<
float>(1) = obsFirst.at<
float>(1) -
origin.at<
float>(1);
779 firstVector.at<
float>(2) = 0.0
f;
780 firstVector = firstVector/cv::norm(firstVector);
781 lastVector.at<
float>(0) = obsLast.at<
float>(0) -
origin.at<
float>(0);
782 lastVector.at<
float>(1) = obsLast.at<
float>(1) -
origin.at<
float>(1);
783 lastVector.at<
float>(2) = 0.0
f;
784 lastVector = lastVector / cv::norm(lastVector);
785 float maxAngle =
acos(firstVector.dot(lastVector));
786 if(firstVector.cross(lastVector).at<
float>(2) < 0)
788 maxAngle = 2*
M_PI-maxAngle;
794 float angle = angleIncrement;
795 cv::Mat tmp = (obsFirst -
origin);
796 cv::Mat endRotated =
rotation*((tmp/cv::norm(tmp))*scanMaxRange) +
origin;
797 while(
angle < maxAngle-angleIncrement)
799 cv::Point2i
end((endRotated.at<
float>(0)-xMin)/cellSize, (endRotated.at<
float>(1)-yMin)/cellSize);
802 end.x =
end.x >= map.cols?map.cols-1:
end.x;
804 end.y =
end.y >= map.rows?map.rows-1:
end.y;
809 angle+=angleIncrement;
822 void rayTrace(
const cv::Point2i & start,
const cv::Point2i & end, cv::Mat & grid,
bool stopOnObstacle)
824 UASSERT_MSG(start.x >= 0 && start.x < grid.cols,
uFormat(
"start.x=%d grid.cols=%d", start.x, grid.cols).c_str());
825 UASSERT_MSG(start.y >= 0 && start.y < grid.rows,
uFormat(
"start.y=%d grid.rows=%d", start.y, grid.rows).c_str());
829 cv::Point2i ptA, ptB;
833 float slope =
float(ptB.y - ptA.y)/
float(ptB.x - ptA.x);
835 bool swapped =
false;
836 if(slope<-1.0f || slope>1.0
f)
852 float b = ptA.y - slope*ptA.x;
853 for(
int x=ptA.x; ptA.x<ptB.x?x<ptB.x:x>ptB.x; ptA.x<ptB.x?++
x:--
x)
855 int upperbound =
float(
x)*slope +
b;
856 int lowerbound = upperbound;
859 lowerbound = (ptA.x<ptB.x?
x+1:
x-1)*slope +
b;
862 if(lowerbound > upperbound)
864 int tmp = upperbound;
865 upperbound = lowerbound;
871 UASSERT_MSG(lowerbound >= 0 && lowerbound < grid.rows,
uFormat(
"lowerbound=%f grid.rows=%d x=%d slope=%f b=%f x=%f", lowerbound, grid.rows,
x, slope,
b,
x).c_str());
872 UASSERT_MSG(upperbound >= 0 && upperbound < grid.rows,
uFormat(
"upperbound=%f grid.rows=%d x+1=%d slope=%f b=%f x=%f", upperbound, grid.rows,
x+1, slope,
b,
x).c_str());
876 UASSERT_MSG(lowerbound >= 0 && lowerbound < grid.cols,
uFormat(
"lowerbound=%f grid.cols=%d x=%d slope=%f b=%f x=%f", lowerbound, grid.cols,
x, slope,
b,
x).c_str());
877 UASSERT_MSG(upperbound >= 0 && upperbound < grid.cols,
uFormat(
"upperbound=%f grid.cols=%d x+1=%d slope=%f b=%f x=%f", upperbound, grid.cols,
x+1, slope,
b,
x).c_str());
880 for(
int y = lowerbound;
y<=(
int)upperbound; ++
y)
885 v = &grid.at<
char>(
x,
y);
889 v = &grid.at<
char>(
y,
x);
891 if(*
v == 100 && stopOnObstacle)
906 UASSERT(map8S.channels() == 1 && map8S.type() == CV_8S);
907 cv::Mat map8U = cv::Mat(map8S.rows, map8S.cols, CV_8U);
908 for (
int i = 0;
i < map8S.rows; ++
i)
910 for (
int j = 0;
j < map8S.cols; ++
j)
912 char v = pgmFormat?map8S.at<
char>((map8S.rows-1)-
i,
j):map8S.at<
char>(
i,
j);
916 gray = pgmFormat?254:178;
924 gray = pgmFormat?254:200;
926 else if(pgmFormat ||
v == -1)
928 gray = pgmFormat?205:89;
932 gray = double(100-
v)*2/100.0*double(89);
936 gray = double(50-
v)*2/100.0*double(178-89)+89;
938 map8U.at<
unsigned char>(
i,
j) = gray;
947 UASSERT_MSG(map8U.channels() == 1 && map8U.type() == CV_8U,
uFormat(
"map8U.channels()=%d map8U.type()=%d", map8U.channels(), map8U.type()).c_str());
948 cv::Mat map8S = cv::Mat(map8U.rows, map8U.cols, CV_8S);
949 for (
int i = 0;
i < map8U.rows; ++
i)
951 for (
int j = 0;
j < map8U.cols; ++
j)
953 unsigned char v = pgmFormat?map8U.at<
char>((map8U.rows-1)-
i,
j):map8U.at<
char>(
i,
j);
990 map8S.at<
char>(
i,
j) = occupancy;
998 UASSERT(map.type() == CV_8SC1);
999 cv::Mat erodedMap = map.clone();
1000 for(
int i=0;
i<map.rows; ++
i)
1002 for(
int j=0;
j<map.cols; ++
j)
1004 if(map.at<
char>(
i,
j) == 100)
1007 int touchEmpty = (map.at<
char>(
i+1,
j) == 0?1:0) +
1008 (map.at<
char>(
i-1,
j) == 0?1:0) +
1009 (map.at<
char>(
i,
j+1) == 0?1:0) +
1010 (map.at<
char>(
i,
j-1) == 0?1:0);
1012 if(touchEmpty>=3 && map.at<
char>(
i+1,
j) != -1 &&
1013 map.at<
char>(
i-1,
j) != -1 &&
1014 map.at<
char>(
i,
j+1) != -1 &&
1015 map.at<
char>(
i,
j-1) != -1)
1017 erodedMap.at<
char>(
i,
j) = 0;