public void Scale()
    {
        Texture2D source = Resources.Load <Sprite> ("image").texture;
        Texture2D tmp    = new Texture2D(1, 1);

        tmp.LoadImage(source.EncodeToJPG());
        int width  = int.Parse(ScaleWidthInput.text);
        int height = int.Parse(ScaleHeightInput.text);

        tmp = CropScale.ScaleTexture(tmp, width, height);
        ResultImage.sprite = Sprite.Create(tmp, new Rect(0f, 0f, tmp.width, tmp.height), new Vector2(0.5f, 0.5f));
    }
Exemple #2
0
    //transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) for IMAGENET
    Tensor ImageToTensor(Texture2D t)
    {
        var channelCount = 3;

        Texture2D crop = CropScale.CropTexture(t, new Vector2(175, 175), CropOptions.CENTER, 0, 0);

        //Custom Resize function
        Texture2D resized_img = Resize(crop, 256, 256);


        seeingImg.texture = resized_img;

        //Custom CenterCrop function
        //Texture2D center_crop_img = ResampleAndCrop(t, 256, 256);


        var img_tensor = new Tensor(resized_img, channelCount);

        //var n = CropPytorch(img_tensor, 256, 256);

        //Custom Standarization mean=[0.3418, 0.3126, 0.3224], std=[0.1627, 0.1632, 0.1731
        var std_tensor = StandardizeTensor(img_tensor, new double[] { 0.3418, 0.3126, 0.3224 }, new double[] { 0.1627, 0.1632, 0.1731 });

        byte[] bytes = resized_img.EncodeToJPG();

        if (Application.platform != RuntimePlatform.Android)
        {
            string filename = Application.dataPath + System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".jpg";
            //File.WriteAllBytes(filename, bytes);
        }
        else
        {
            if (!PlayerPrefs.HasKey("PhotoSaved"))
            {
                PlayerPrefs.SetInt("PhotoSaved", 1);
            }
            else
            {
                PlayerPrefs.SetInt("PhotoSaved", PlayerPrefs.GetInt("PhotoSaved") + 1);
            }

            string filename = Application.persistentDataPath + PlayerPrefs.GetInt("PhotoSaved").ToString() + ".jpg";
            File.WriteAllBytes(filename, bytes);
        }


        img_tensor.Dispose();

        return(std_tensor);
    }
    public void Crop()
    {
        Texture2D source = Resources.Load <Sprite> ("image").texture;
        Texture2D tmp    = new Texture2D(1, 1);

        tmp.LoadImage(source.EncodeToJPG());
        CropOptions options = (CropOptions)_selectedCropOption;
        int         width   = int.Parse(CropWidthInput.text);
        int         height  = int.Parse(CropHeightInput.text);
        int         x       = int.Parse(CropOffsetXInput.text);
        int         y       = int.Parse(CropOffsetYInput.text);

        tmp = CropScale.CropTexture(tmp, new Vector2(width, height), options, x, y);
        ResultImage.sprite = Sprite.Create(tmp, new Rect(0f, 0f, tmp.width, tmp.height), new Vector2(0.5f, 0.5f));
    }
Exemple #4
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (MinCropSize != 0)
            {
                hash ^= MinCropSize.GetHashCode();
            }
            if (CropMethod != 0)
            {
                hash ^= CropMethod.GetHashCode();
            }
            if (MeanB != 0F)
            {
                hash ^= MeanB.GetHashCode();
            }
            if (MeanG != 0F)
            {
                hash ^= MeanG.GetHashCode();
            }
            if (MeanR != 0F)
            {
                hash ^= MeanR.GetHashCode();
            }
            if (IsBgr != false)
            {
                hash ^= IsBgr.GetHashCode();
            }
            if (CropScale != 0F)
            {
                hash ^= CropScale.GetHashCode();
            }
            if (InputBlobName.Length != 0)
            {
                hash ^= InputBlobName.GetHashCode();
            }
            if (ImParamBlobName.Length != 0)
            {
                hash ^= ImParamBlobName.GetHashCode();
            }
            if (OutputBlobName.Length != 0)
            {
                hash ^= OutputBlobName.GetHashCode();
            }
            if (ModelName.Length != 0)
            {
                hash ^= ModelName.GetHashCode();
            }
            if (ModelType.Length != 0)
            {
                hash ^= ModelType.GetHashCode();
            }
            if (ProtoFile.Length != 0)
            {
                hash ^= ProtoFile.GetHashCode();
            }
            if (WeightFile.Length != 0)
            {
                hash ^= WeightFile.GetHashCode();
            }
            if (MaxBatchSize != 0)
            {
                hash ^= MaxBatchSize.GetHashCode();
            }
            return(hash);
        }