Пример #1
0
std::vector< std::vector< Point > > Hough::getPoints(){ //to find the points on lines in the image
    std::vector< std::vector< Point > > edgePoints;
    //save the accumulator
    FILE *fp = fopen("accumulator.raw", "wb");
    if (fp) {
        
        fwrite(acc, (180) * (r_size*2), 1, fp);
        fclose(fp);
        std::cout<<"Accumulator saved"<<std::endl;
    }
    else{
        std::cout<<"Could not save file"<<std::endl;
    }
    
    polarPoints = threshAcc(200);//threshold and get polar coords
    
    for(int i = 0; i < polarPoints.size(); i++){
        
        Point p1, p2, p3, p4; //Where the lines cross points where x = 0, x = width, y = 0, y = height
        
        //x = r - y.sin(theta) / cos(theta)    y = r - x.cos(theta) / sin(theta)
        p1.x = 0;
        p1.y = (polarPoints[i].y - p1.x * cos(polarPoints[i].x*(PI/180))) /sin(polarPoints[i].x*(PI/180));
        
        p2.x = xSize - 1;
        p2.y = (polarPoints[i].y - p2.x * cos(polarPoints[i].x*(PI/180))) /sin(polarPoints[i].x*(PI/180));
        
        p3.y = 0;
        p3.x = (polarPoints[i].y - p3.y * sin(polarPoints[i].x*(PI/180))) /cos(polarPoints[i].x*(PI/180));
        
        p4.y = ySize - 1;
        p4.x = (polarPoints[i].y - p4.y * sin(polarPoints[i].x*(PI/180))) /cos(polarPoints[i].x*(PI/180));
        
        std::vector< Point > temp_vec;
        
        //if the points are in the image save the points
        if(PointInImage(p1, xSize, ySize)){
            temp_vec.push_back(p1);
        }
        if(PointInImage(p2, xSize, ySize)){
            temp_vec.push_back(p2);
        }
        if(PointInImage(p3, xSize, ySize)){
            temp_vec.push_back(p3);
        }
        if(PointInImage(p4, xSize, ySize)){
            temp_vec.push_back(p4);
        }
        
        if(temp_vec.size() != 0) {
            edgePoints.push_back(temp_vec);
        }
        
    }
    return edgePoints;
}
bool CameraIntrinsics::DirectionToImage(double u_normalized,
                                        double v_normalized,
                                        double *u_distorted,
                                        double *v_distorted) const {
  CHECK_NOTNULL(u_distorted);
  CHECK_NOTNULL(v_distorted);

  // Distort the normalized direction vector;
  double u = 0.0, v = 0.0;
  Distort(u_normalized, v_normalized, &u, &v);

  // Make a homogeneous vector from the output.
  Vector3d p;
  p << u, v, 1.0;

  // Multiply the distorted direction vector by camera intrinsic matrix to get
  // the image space point.
  const Vector3d p_out = CameraIntrinsics::K() * p;
  *u_distorted = p_out(0);
  *v_distorted = p_out(1);

  // Make sure that the resulting point is in the image.
  return PointInImage(*u_distorted, *v_distorted);
}