Esempio n. 1
0
void fitLines(const cv::Mat &edges, LFLineFitter &lineFitter)
{
  Ptr<Image<uchar> > fdcmEdges;
  cv2fdcm(edges, fdcmEdges);
  lineFitter.Init();
  lineFitter.FitLine(fdcmEdges);
}
void EIEdgeImage::Read(LFLineFitter &lf)
{
	SafeRelease();
	width_ = lf.rWidth();
	height_ = lf.rHeight();
	nLines_ = lf.rNLineSegments();
	LFLineSegment* lineSegmentMap = lf.rOutputEdgeMap();

	lines_ = new LFLineSegment[nLines_];
	for (int i=0 ; i<nLines_ ; i++)
		lines_[i] = lineSegmentMap[i];

	SetLines2Grid();
	SetDirections();

}
Esempio n. 3
0
void main(int argc, char *argv[])
{
	//IplImage *inputImage=NULL;
	Image<uchar> *inputImage=NULL;
	LFLineFitter lf;

	if(argc != 4)
	{
		std::cerr<<"[Syntax] fitline   input_edgeMap.pgm   output_line.txt   output_edgeMap.pgm"<<std::endl;
		exit(0);
	}

	string imageName(argv[1]);
	string outFilename(argv[2]);
	string outputImageName(argv[3]);
	
	//string imageName("data/hat_edges.pgm");
	//string outFilename("data/hat_edges.txt");
	//string outputImageName("data/hat_edges_display.pgm");

	
	//inputImage = cvLoadImage(imageName.c_str(),0);
	inputImage = ImageIO::LoadPGM(imageName.c_str());
	if(inputImage==NULL)
	{
		std::cerr<<"[ERROR] Fail in reading image "<<imageName<<std::endl;
		exit(0);
	}
	
	lf.Init();
	
	lf.Configure("para_template_line_fitter.txt");
	
	lf.FitLine(inputImage);

	lf.DisplayEdgeMap(inputImage,outputImageName.c_str());	

	lf.SaveEdgeMap(outFilename.c_str());

	//cvReleaseImage(&inputImage);
	delete inputImage;
};
Esempio n. 4
0
void computeNormals(const cv::Mat &edges, cv::Mat &normals, cv::Mat &orientationIndices)
{
  //TODO: move up
  const int directionsCount = 60;
  LFLineFitter lineFitter;
  fitLines(edges, lineFitter);

  Mat linearMap(edges.size(), CV_8UC1, Scalar(0));
  Mat linearMapNormals(edges.size(), CV_32FC2, Scalar::all(std::numeric_limits<float>::quiet_NaN()));
  Mat linearMapOrientationIndices(edges.size(), CV_32SC1, Scalar(-1));
  for (int i = 0; i < lineFitter.rNLineSegments(); ++i)
  {
    cv::Point start(lineFitter.outEdgeMap_[i].sx_, lineFitter.outEdgeMap_[i].sy_);
    cv::Point end(lineFitter.outEdgeMap_[i].ex_, lineFitter.outEdgeMap_[i].ey_);

    LineIterator edgelsIterator(linearMap, start, end);
    for(int j = 0; j < edgelsIterator.count; ++j, ++edgelsIterator)
    {
      **edgelsIterator = 255;
      Vec2f normal(lineFitter.outEdgeMap_[i].normal_.x, lineFitter.outEdgeMap_[i].normal_.y);
      linearMapNormals.at<Vec2f>(edgelsIterator.pos()) = normal;
      linearMapOrientationIndices.at<int>(edgelsIterator.pos()) = theta2Index(lineFitter.outEdgeMap_[i].Theta(), directionsCount);
    }
  }
//  imshow("edges", edges);
//  imshow("linearMap", linearMap);
//  waitKey();

  Mat dt, labels;
  distanceTransform(~linearMap, dt, labels, CV_DIST_L2, CV_DIST_MASK_PRECISE, DIST_LABEL_PIXEL);

  CV_Assert(linearMap.type() == CV_8UC1);
  CV_Assert(labels.type() == CV_32SC1);
  std::map<int, cv::Point> label2position;
  for (int i = 0; i < linearMap.rows; ++i)
  {
    for (int j = 0; j < linearMap.cols; ++j)
    {
      if (linearMap.at<uchar>(i, j) != 0)
      {
        //TODO: singal error if the label already exists
        label2position[labels.at<int>(i, j)] = cv::Point(j, i);
      }
    }
  }

  orientationIndices.create(edges.size(), CV_32SC1);
  orientationIndices = -1;

  normals.create(edges.size(), CV_32FC2);
  normals = Scalar::all(std::numeric_limits<float>::quiet_NaN());
  for (int i = 0; i < edges.rows; ++i)
  {
    for (int j = 0; j < edges.cols; ++j)
    {
//      if (edges.at<uchar>(i, j) != 0)
      cv::Point nearestEdgelPosition = label2position[labels.at<int>(i, j)];
      normals.at<Vec2f>(i, j) = linearMapNormals.at<Vec2f>(nearestEdgelPosition);
      orientationIndices.at<int>(i, j) = linearMapOrientationIndices.at<int>(nearestEdgelPosition);
      CV_Assert(orientationIndices.at<int>(i, j) >= 0 && orientationIndices.at<int>(i, j) < directionsCount);
    }
  }

/*
  Mat vis(orientations.size(), CV_8UC1, Scalar(0));
  for (int i = 0; i < orientations.rows; ++i)
  {
    for (int j = 0; j < orientations.cols; ++j)
    {
      Vec2f elem = orientations.at<Vec2f>(i, j);
      vis.at<uchar>(i, j) = (cvIsNaN(elem[0]) || cvIsNaN(elem[1])) ? 0 : 255;
    }
  }
  imshow("final or", vis);
  waitKey();
*/
}