예제 #1
0
void CLabHorizScale::drawScale(CDC *pDC)
{
   int tickLength;
   
   CRgn rgn;
   CRect rect = bounds();
   rgn.CreateRectRgn(rect.left, rect.top, rect.right, rect.bottom);
   pDC->SelectClipRgn(&rgn);
      
   for(double x=getTickMin(); x<=maximum(); x=x+tickIncrement())
   {
      double temp = x/(majorTickFrequency()*tickIncrement());
      if(temp == ceil(temp))
         tickLength = 7;
      else
         tickLength = 3;


      pDC->MoveTo(translateCoordinate(x), rect.top);
      pDC->LineTo(translateCoordinate(x), rect.top + tickLength);

      temp = x/(tickMarkFrequency() * tickIncrement());
      if(temp == ceil(temp))
      {
         CString tickMarkStr;
         tickMarkStr.Format("%.*f", precision(), x);
         
         pDC->TextOut(translateCoordinate(x) - _parent->getCharWidth() * tickMarkStr.GetLength()/2, 
                      rect.top + 7 /* _parent->getCharHeight()*/, 
                      tickMarkStr);

      }
   }
}
void StereoReconstructor::RestructPointCloud(bool objSpace, bool undistort, std::string pcfilename) {
  //载入2个虚拟摄像机
  VirtualCamera vc1;
  VirtualCamera vc2;
  //载入内参
  vc1.loadCameraMatrix("reconstruct\\LeftMatrix.txt");
  vc1.loadDistortion("reconstruct\\LeftDistortion.txt");
  vc1.rotationMatrix = cv::Mat::eye(3, 3, CV_32FC1);
  vc1.translationVector = cv::Mat::zeros(3, 1, CV_32FC1);
  vc2.loadCameraMatrix("reconstruct\\RightMatrix.txt");
  vc2.loadDistortion("reconstruct\\RightDistortion.txt");
  vc2.loadRotationMatrix("reconstruct\\R.txt");
  vc2.loadTranslationVector("reconstruct\\T.txt");

  vc1.loadKeyPoints("left.txt");					//载入角点
  vc2.loadKeyPoints("right.txt");

  //重建3d点
  std::vector<RestructPoint> ret;
  ret = triangulation(vc1, vc2, undistort);	//true进行畸变矫正,false表示不进行

  //保存结果
  std::vector<StereoReconstructor::RestructPoint> ans;
  for (size_t i = 0; i != ret.size(); ++i)
    ans.push_back(StereoReconstructor::RestructPoint(ret[i].point, ret[i].distance));

  plyFileGenerate(ans,
                  pcfilename,					//ply文件
                  "_calPointsDis.txt",			//3d点+相交距离
                  "_calPoints.txt");				//3d点

  //转换到物体坐标系
  if (objSpace) {
    translateCoordinate(
      "Coordinate.txt",				//棋盘格坐标系
      "_calPoints.txt",				//要转换的3D点
      "Points_obj.txt");				//在棋盘格坐标系下的坐标calPoints_ObjSpace.txt

    //生成物体坐标系下的ply文件
    std::vector<cv::Point3f> pointcloud = Utilities::load3dPoints("Points_obj.txt");
    Utilities::savePly(pointcloud, "PointsObj.ply");
  }
}
void StereoReconstructor::RestructCalibrationPointsFromImage(std::string leftFilename, std::string rightFilename, int x, int y, int squareLength) {
  //计算角点
  bool f1, f2;
  CameraCalibration::findCorners(leftFilename, f1, x, y);
  CameraCalibration::findCorners(rightFilename, f2, x, y);
  
  if (!f1 || !f2) {
    std::cout << "角点没找到" << std::endl;
    return;
  }

  //载入2个虚拟摄像机
  VirtualCamera vc1;
  VirtualCamera vc2;
  //载入内参
  vc1.loadCameraMatrix("reconstruct\\LeftMatrix.txt");
  vc1.loadDistortion("reconstruct\\LeftDistortion.txt");
  vc1.rotationMatrix = cv::Mat::eye(3, 3, CV_32FC1);
  vc1.translationVector = cv::Mat::zeros(3, 1, CV_32FC1);
  vc2.loadCameraMatrix("reconstruct\\RightMatrix.txt");
  vc2.loadDistortion("reconstruct\\RightDistortion.txt");
  vc2.loadRotationMatrix("reconstruct\\R.txt");
  vc2.loadTranslationVector("reconstruct\\T.txt");

  //载入角点	
  vc1.loadKeyPoints(leftFilename + "_imgCorners.txt");
  vc2.loadKeyPoints(rightFilename + "_imgCorners.txt");

  //重建3d点
  std::vector<RestructPoint> ret;
  ret = triangulation(vc1, vc2, true);	//进行畸变矫正,false表示不进行

  //保存结果
  //生成点云文件
  plyFileGenerate(ret,
                  leftFilename + ".ply",		//ply文件
                  "_calPointsDis.txt",		//3d点+相交距离
                  "_calPoints.txt");			//3d点
  //评估长度误差
  resultEvaluate(ret,
                 "_calLineLength.txt",		//157条线段的误差calLineLength.txt
                 "_calLineLengthDist.txt",	//线段的长度的概率分布
                 x, y, squareLength);
  //计算棋盘格坐标系
  computeCoordinate(
    "_calPoints.txt",			//读取棋盘格坐标
    "_coordinate.txt",			//计算坐标系,保存到Coordinate.txt
    x, y);						//水平方向和垂直方向的角点个数
  //转换到棋盘格坐标系
  translateCoordinate(
    "_coordinate.txt",			//棋盘格坐标系
    "_calPoints.txt",			//要转换的3D点
    "_calPoints_ObjSpace.txt");	//在棋盘格坐标系下的坐标calPoints_ObjSpace.txt

  //生成物体坐标系下的ply文件
  std::vector<cv::Point3f> pointcloud = Utilities::load3dPoints("_calPoints_ObjSpace.txt");
  Utilities::savePly(pointcloud, "ObjSpace" + leftFilename + ".ply");

  //生成棋盘格物体空间坐标,并载入
  Utilities::generateObjCorners("_chessbordCorner.txt", x, y, squareLength);
  std::vector<cv::Point3f> ideaPts = Utilities::load3dPoints("_chessbordCorner.txt");
  std::vector<cv::Point3f> realPts = Utilities::load3dPoints("_calPoints_ObjSpace.txt");
  //计算到角点的绝对距离,并保存
  std::ofstream absDis("_absCornerDistance.txt");
  for (int i = 0; i < ideaPts.size(); i++) {
    cv::Point3f idea = ideaPts[i];
    cv::Point3f real = realPts[i];
    float dis = cv::norm((idea - real));
    absDis << dis << std::endl;
  }
  absDis.close();

}