0

私がやろうとしていることは非常に単純に聞こえますが、インターネットのどこにも DotNet でこれを行う方法を見つけたことがなく、これを行うサードパーティのコンポーネントも見つかりませんでした (完全に不要な機能に何千ドルも費やすことなく)。ここに行きます:

チェッカーボード パターンを作成する床タイル (実際の写真) の jpeg があります。dotnet では、写真を回転させてつなぎ合わせ、最終的な画像を jpeg として保存するのは簡単です。

次に、最終的な写真を撮り、「タイル」が一般的な「部屋のシーン」の床に置かれているように見せたいと思います。基本的には 3D パースペクティブを追加して、実際に部屋のシーンにあるかのように見せます。

カーペットで似たようなことをしている Web サイトを次に示しますが、WinForms アプリケーションでこれを行う必要があります

基本的に、jpeg の 3D パースペクティブを作成し、それを新しい jpeg として保存する必要があります (その後、一般的な部屋のシーンのオーバーレイを配置できます)。

この一見単純なタスクを実行できるサードパーティの DotNet 画像処理モジュールをどこで入手できるか、誰にもわかりませんか?

4

2 に答える 2

3

シンプルな床だけが必要な場合、コードは次のようになります。警告: 目的の結果を得るには、かなりの時間と改良が必要です。特に、数学がよくわからない場合は注意が必要です。しかし一方で、このタイプのコードで遊ぶのはいつでも楽しいものです... (:

以下のサンプル画像を見つけてください。

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace floorDrawer
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        ResizeRedraw = DoubleBuffered = true;

        Width = 800;
        Height = 600;

        Paint += new PaintEventHandler(Form1_Paint);

    }

    void Form1_Paint(object sender, PaintEventArgs e)
    {

        // a few parameters that control the projection transform
        // these are the parameters that you can modify to change 
        // the output

        double cz = 10; // distortion
        double m = 1000; // magnification, usually around 1000 (the pixel width of the monitor)

        double y0 = -100; // floor height

        string texturePath = @"c:\pj\Hydrangeas.jpg";//@"c:\pj\Chrysanthemum.jpg";


        // screen size
        int height = ClientSize.Height;
        int width = ClientSize.Width;

        // center of screen
        double cx = width / 2;
        double cy = height / 2;



        // render destination
        var dst = new Bitmap(width, height);

        // source texture

        var src = Bitmap.FromFile(texturePath) as Bitmap;

        // texture dimensions
        int tw = src.Width;
        int th = src.Height;

        for (int y = 0; y < height; y++)
            for (int x = 0; x < width; x++)
            {
                double v = m * y0 / (y - cy) - cz;
                double u = (x - cx) * (v + cz) / m;

                int uu = ((int)u % tw + tw) % tw;
                int vv = ((int)v % th + th) % th;
                // The following .SetPixel() and .GetPixel() are painfully slow
                // You can replace this whole loop with an equivalent implementation
                // using pointers inside unsafe{} code to make it much faster.
                // Note that by casting u and v into integers, we are performing
                // a nearest pixel interpolation...  It's sloppy but effective.

                dst.SetPixel(x, y, src.GetPixel(uu, vv));
            }

        // draw result on the form
        e.Graphics.DrawImage(dst, 0, 0);
    }

}
}

これは、Windows 7 のサンプル イメージの 1 つを使用したサンプル出力です。

別の Windows 7 サンプル画像を使用した別の例。

于 2011-09-07T19:07:07.387 に答える