vector<LPPACKAGE> cvPic::getPrintPack() { string srcImg = ImgName; // 源图片的位置 int num = 0; // 连通图个数 cv::Mat grayImg = cv::imread( srcImg ); // 将图片加载 cv::Mat labelImg; vector<int> stRun,enRun,rowRun,runLabels; vector<pair<int,int>> equivalences; vector<int> imgX,imgY,imgColor; int imgWidth,imgHeight; cv::cvtColor( grayImg, labelImg, CV_BGR2GRAY ); // 灰度化图像 cv::threshold( labelImg, labelImg, 150, 255, CV_THRESH_BINARY ); // 二值化图像 packagePictureInfo( labelImg, imgX, imgY, imgColor ); imgWidth = labelImg.cols; imgHeight = labelImg.rows; fillRunVectors( labelImg, num, stRun, enRun, rowRun ); // 完成团的标记与等价对列表的生成 firstPass( stRun, enRun, rowRun, num, runLabels, equivalences, 1 ); // 八邻接 replaceSameLabel( runLabels, equivalences ); printf( "连通图数目为:%d\n", num ); return getPackages(imgWidth,imgHeight,imgX,imgY,imgColor); }
void ObstacleDetection::ObstacleDetecting(const int obstacleMap[120][120], RobPose cRobotPos) { int cObstacleMap[120][120]; memcpy(cObstacleMap, obstacleMap, 120*120*sizeof(int)); stRun.clear(); enRun.clear(); rowRun.clear(); runLabels.clear(); equivalences.clear(); numberOfRuns = 0; offset = 1; obsNum = 0; obsPoses.clear(); std::stringstream out; out<<frames_num; std::string filename = "ObstacleMap" + out.str() + ".txt"; std::ofstream Obstaclemapfile(filename); if (Obstaclemapfile.is_open()) { for(int i = 0; i < 120; i++) { for(int j = 0; j < 120; j++) { Obstaclemapfile<<cObstacleMap[i][j]<<" "; } Obstaclemapfile<<std::endl; } } frames_num++; fillRunVectors(cObstacleMap, numberOfRuns, stRun, enRun, rowRun); if(numberOfRuns > 0) { firstPass(stRun, enRun, rowRun, numberOfRuns, runLabels, equivalences, offset); replaceSameLabel(runLabels, equivalences); FindObstacle(stRun, enRun, rowRun, numberOfRuns, runLabels, obsNum, obsPoses, cRobotPos); cout<<"Num of Obstalces: "<<obsNum<<endl; } }