Beispiel #1
0
void testIntersection()
{

    RGB24Buffer image(1000,1000, RGBColor::White());

    corecvs::Polygon p;
    for (int i = 0; i < 5; i++)
    {
        p.push_back(Vector2dd::FromPolar(-2 * M_PI / 5 * i, 260) + Vector2dd(image.w / 2.0, image.h / 2.0));
    }


    AbstractPainter<RGB24Buffer> painter(&image);

    painter.drawPolygon(p, RGBColor::Black());
    for (unsigned i = 0; i < p.size(); i++)
    {
        Vector2dd p1 = p[i];
        Vector2dd p2 = p[(i + 1) % p.size()];

        Vector2dd center = (p1 + p2) / 2.0;
        Vector2dd decal = (p2 - p1).rightNormal().normalised();
        decal = center + decal * 8;
        image.drawLine(center.x(), center.y(), decal.x(), decal.y(), RGBColor::gray(128));
    }


    for (int i = 1; i < 10; i++)
    {
        Ray2d ray( Vector2dd::FromPolar( M_PI / 20.0 * i + 0.02, 100), Vector2dd(140,180));

        Vector2dd p1 = ray.getPoint(0.0);
        Vector2dd p2 = ray.getPoint(8.0);
        image.drawLine(fround(p1.x()), fround(p1.y()), fround(p2.x()), fround(p2.y()), RGBColor::Yellow());
        for (int j = 0; j < 8; j++)
        {
            Vector2dd p = ray.getPoint(j);
            image.drawCrosshare1(p.x(), p.y(), RGBColor::Cyan());
        }

        double t1, t2;
        ray.clip<Polygon>(p, t1, t2);

        p1 = ray.getPoint(t1);
        p2 = ray.getPoint(t2);

        cout << "t1 = " << t1 << endl;
        cout << "t2 = " << t2 << endl;
        cout << "p1 = " << p1 << endl;
        cout << "p2 = " << p2 << endl;

        image.drawLine(fround(p1.x()), fround(p1.y()), fround(p2.x()), fround(p2.y()),
                       t1 > t2 ? RGBColor::Red() : RGBColor::Green());

    }


    BMPLoader().save("out1.bmp", &image);

}
void RGB24Buffer::drawCorrespondanceList(CorrespondanceList *src, double colorScaler, int32_t y, int32_t x)
{
    if (src == NULL) {
        return;
    }

    CorrespondanceList::iterator it;
    for (it = src->begin(); it != src->end(); ++it)
    {
        Correspondance &tmpCorr = (*it);
        Vector2dd from = tmpCorr.start;
        Vector2dd to = tmpCorr.end;
        Vector2dd vec = to - from;
        //RGBColor color = RGBColor(128 + (vec.x() * 5),128 + (vec.y() * 5), 0);
        RGBColor color = RGBColor::rainbow1(!vec / colorScaler);
        drawLineSimple(from.x() + x, from.y() + y, to.x() + x, to.y() + y, color);
        this->drawCrosshare3(to.x() + x, to.y() + y, color);
    }
}
    virtual void operator()(const double in[], double out[])
    {
        double dh = (double)mH / (mSteps - 1);
        double dw = (double)mW / (mSteps - 1);
        RadialCorrection guess = updateWithModel(mGuess, in);

        for (int i = 0; i < mSteps; i++)
        {
            for (int j = 0; j < mSteps; j++)
            {
                Vector2dd point(dw * j, dh * i);
                Vector2dd deformed = mInput.map(point); /* this could be cached */
                Vector2dd backproject = guess.map(deformed);
                Vector2dd diff = backproject - point;

                out[2 * (i * mSteps + j)    ] = diff.x();
                out[2 * (i * mSteps + j) + 1] = diff.y();
            }
        }
    }
StereographicProjection::StereographicProjection(const Vector2dd &principal, double focal, const Vector2dd &size) :
    ProjectionBaseParameters(principal.x(), principal.y(), focal, size.x(), size.y(), size.x(), size.y()),
    CameraProjection(ProjectionType::STEREOGRAPHIC)
{}
Beispiel #5
0
CameraProjection *ILFormat::loadIntrisics(std::istream &filename)
{
    /**
      Some examples

        // "omnidirectional\n"
        // "1578 1.35292 1.12018 5 0.520776 -0.561115 -0.560149 1.01397 -0.870155";


        // projective
        // fx fy cx cy w h


    **/

    std::string cameraType;
    filename >> cameraType;

    if (cameraType == IL_OMNIDIRECTIONAL)
    {
        double s;
        Vector2dd c;
        int imax;
        double n0;

        filename >> s;
        filename >> c.x() >> c.y();
        filename >> imax;

        filename >> n0;
        vector<double> n;
        for (int i = 0; i < imax-1; i++)
        {
            double v = 0;
            filename >> v;
            n.push_back(v);
        }

#if 0
        cout << "Type: " << cameraType << endl;
        cout << "s: " << s << endl;
        cout << "c: " << c << endl;
        cout << "imax: " << imax << endl;
        cout << "n0: " << n0 << endl;

        for (int i = 0; i < imax-1; i++)
        {
            cout << "n" << i+2 << " " << n[i] << endl;
        }
#endif

        OmnidirectionalProjection *projection = new OmnidirectionalProjection;
        projection->setFocal(s * n0);
        projection->setPrincipalX(s * c.x());
        projection->setPrincipalY(s * c.y());
        projection->setSizeX(projection->principalX() * 2);
        projection->setSizeY(projection->principalY() * 2);

        projection->setDistortedSizeX(projection->principalX() * 2);
        projection->setDistortedSizeY(projection->principalY() * 2);

        projection->mN.clear();

        for (size_t i = 0; i < n.size(); i++)
        {
           projection->mN.push_back(n[i] * pow(n0, i + 1));
        }
        return projection;
    }