Beispiel #1
0
    List <KeyValuePair <Vector3, bool> > project_loop(string imageFrame)
    {
        List <Matrix <float> > cameraCalibrations   = CameraCalibrations.GetCamerasProjMatrix();
        List <KeyValuePair <Vector3, bool> > voxels = InitializeVoxelDictionary();

        for (int i = 0; i < voxels.Count; i++)
        {
            //if (voxels[i].Value)
            //{
            for (int j = 0; j < cameraCalibrations.Count; j++)
            {
                int       cam          = j + 1;
                string    imagePath    = "silhouettes/Silhouette" + cam + "_" + imageFrame;
                Texture2D currentImage = Resources.Load(imagePath) as Texture2D;

                float[,] xyzCoords = new float[, ] {
                    { voxels[i].Key.x }, { voxels[i].Key.y }, { voxels[i].Key.z }, { 1 }
                };

                Matrix <float> matrixCoords = Matrix <float> .Build.DenseOfArray(xyzCoords);

                matrixCoords.Transpose();

                Matrix <float> X = cameraCalibrations[j] * matrixCoords;

                float uCoord = currentImage.width - X[0, 0] / X[2, 0];
                float vCoord = currentImage.height - X[1, 0] / X[2, 0];

                if (currentImage.GetPixel(Mathf.RoundToInt(uCoord), Mathf.RoundToInt(vCoord)).Equals(Color.black))
                {
                    voxels[i] = new KeyValuePair <Vector3, bool>(voxels[i].Key, false);
                }
                else
                {
                    voxels[i] = new KeyValuePair <Vector3, bool>(voxels[i].Key, true);
                }
            }
            // }
        }

        return(voxels);
    }
Beispiel #2
0
    void PlotUVProjectionOnImage(string imagePath, int cameraProjectionMatrix)
    {
        Texture2D      currentImage = Resources.Load(imagePath) as Texture2D;
        Matrix <float> P            = CameraCalibrations.GetProjMatrix(cameraProjectionMatrix);
        List <float>   u            = new List <float>();
        List <float>   v            = new List <float>();

        List <Vector2> uvCoords = new List <Vector2>();

        for (float x = -5f; x <= 5f; x += 0.2f)
        {
            for (float y = -5f; y <= 5f; y += 0.2f)
            {
                for (float z = -5f; z <= 5f; z += 0.2f)
                {
                    float[,] xyzCoords = new float[, ] {
                        { x }, { y }, { z }, { 1 }
                    };

                    Matrix <float> matrixCoords = Matrix <float> .Build.DenseOfArray(xyzCoords);

                    matrixCoords.Transpose();

                    Matrix <float> X = P * matrixCoords;

                    Vector2 uv = new Vector2((X[0, 0] / X[2, 0]), (X[1, 0] / X[2, 0]));

                    if (!currentImage.GetPixel(Mathf.RoundToInt(uv.x), Mathf.RoundToInt(uv.y)).Equals(Color.black))
                    {
                        uvCoords.Add(uv);
                    }
                }
            }
        }

        PlotPoints(uvCoords, currentImage);
        //PlotPoints(uvCoords);

        CreateTargetImage("img1", currentImage, new Vector3(0, 0, 0), new Vector3(1, 1, 1));
    }