Beispiel #1
0
Datei: Panner.C Projekt: 0mk/non
/** set X, Y, W, and H to the bounding box of point /p/ in screen coords */
void
Panner::point_bbox ( const Point *p, int *X, int *Y, int *W, int *H ) const
{
    int tx, ty, tw, th;

    bbox( tx, ty, tw, th );

    float px, py;
    float s = 1.0f;
       
    if ( projection() == POLAR )
    {
        project_polar( p, &px, &py, &s );
    }
    else
    {
        project_ortho( p, &px, &py, &s );
    }

    const float htw = float(tw)*0.5f;
    const float hth = float(th)*0.5f;


    *W = *H = tw * s;
     
    if ( *W < 8 )
        *W = 8;
    if ( *H < 8 )
        *H = 8;

    *X = tx + (htw * px + htw) - *W/2;
    *Y = ty + (hth * py + hth) - *H/2;

}
	// x = current params, fvec = the errors/differences of the proj with current params and the GT (image_points)
	int operator()(const Eigen::VectorXd& x, Eigen::VectorXd& fvec) const
	{
		const float aspect = static_cast<float>(width) / height;
		for (int i = 0; i < values(); i++)
		{
			// opencv to glm:
			glm::vec3 point_3d(model_points[i][0], model_points[i][1], model_points[i][2]);
			// projection given current params x:
			glm::vec3 proj_with_current_param_esti = project_ortho(point_3d, x[0], x[1], x[2], x[3], x[4], x[5], width, height);
			cv::Vec2f proj_point_2d(proj_with_current_param_esti.x, proj_with_current_param_esti.y);
			// diff of current proj to ground truth, our error
			auto diff = cv::norm(proj_point_2d, image_points[i]);
			// fvec should contain the differences
			// don't square it.
			fvec[i] = diff;
		}
		return 0;
	};