private void TakeCapture() { // Get image from camera var snap = TakeTextureSnap(); if (snap == null) { return; } var rotated = Rotate(snap); var croped = TextureTools.CropWithRect( snap, //rotated, new Rect(0, 0, capturedImageWidth, capturedImageWidth), //TextureTools.RectOptions.BottomLeft, TextureTools.RectOptions.Center, 0, 0); if (testImage != null && isDebug) { testImage.texture = rotated; } capturedImage = Scale(rotated, CNN_INPUT_SIZE); }
private Task <Texture2D> RotateAsync(Texture2D texture) { return(Task.Run(() => { return TextureTools.RotateTexture(texture, -90); })); }
public void Detect() { text.text = ""; var tex = Resources.Load <Texture2D>("Products_UnitTests/" + $"debug_{slider.value}"); tex = GenericUtils.Resize(tex, IMAGE_SIZE, IMAGE_SIZE); //var scaled = TextureTools.scaled(tex, IMAGE_SIZE, IMAGE_SIZE); var rot = TextureTools.RotateImageMatrix(tex.GetPixels32(), IMAGE_SIZE, IMAGE_SIZE, 180); img.texture = tex; string result = ""; using (var tensor = TransformInput(rot, IMAGE_SIZE, IMAGE_SIZE)) { var inputs = new Dictionary <string, Tensor>(); inputs.Add(INPUT_NAME, tensor); worker.Execute(inputs); var output = worker.PeekOutput(OUTPUT_NAME); var results = ParseOutputs(output); var classes = new List <KeyValuePair <string, float> >(); for (int i = 0; i < results.Count; i++) { Debug.Log(results[i].ToString()); classes.Add(new KeyValuePair <string, float>(results[i].Label, results[i].Confidence)); } classes = classes.OrderByDescending(x => x.Value).ToList(); foreach (var VARIABLE in classes) { text.text += VARIABLE.Key + ", " + VARIABLE.Value + "\n"; } //var boxes = FilterBoundingBoxes(results, 5, MINIMUM_CONFIDENCE); } }
public override Texture2D TakeScreenShot() { Texture2D snap = new Texture2D(activeCameraTexture.width, activeCameraTexture.height); snap.SetPixels(activeCameraTexture.GetPixels()); snap.Apply(); switch (Screen.orientation) { case ScreenOrientation.Portrait: snap = TextureTools.RotateTexture(snap, -90); //Debug.Log("Portrait"); break; case ScreenOrientation.PortraitUpsideDown: snap = TextureTools.RotateTexture(snap, 90); break; case ScreenOrientation.LandscapeRight: snap = TextureTools.RotateTexture(snap, 180); //Debug.Log("Landscape right"); break; case ScreenOrientation.LandscapeLeft: //snap = TextureTools.RotateTexture(snap, -180); //Debug.Log("Landscape left"); break; } return(snap); }
/* * Get snaped image from camera */ private Texture2D TakeTextureSnap() { Vuforia.Image captured = CameraDevice.Instance.GetCameraImage(mPixelFormat); if (captured == null || !captured.IsValid()) { return(null); } byte[] pixels = captured.Pixels; if (pixels == null || pixels.Length <= 0) { return(null); } // Make temperate Texture2D to copy camera pixel data Texture2D tmp = new Texture2D(captured.Width, captured.Height, TextureFormat.RGB24, false); captured.CopyToTexture(tmp); /* * TODO: Change captureImageWidth to be proportional to Screen.width */ return(TextureTools.CropWithRect( tmp, //new Rect(0, 0, Mathf.Min(tmp.width, Screen.width), Mathf.Min(tmp.height, Screen.height)), //new Rect(0, 0, 610, 1280), new Rect(0, 0, capturedImageWidth, capturedImageWidth), TextureTools.RectOptions.Center, 0, 0)); }
public IEnumerator ExportFrame() { while (true) { if (sendToAWS && !isRunning) { isRunning = true; yield return(frameEnd); tex.Resize(arCam.pixelWidth, arCam.pixelHeight); tex.ReadPixels(screenRect, 0, 0); tex.Apply(); TextureScale.Bilinear(tex, tex.width / 2, tex.height / 2); croppedTex = TextureTools.ResampleAndCrop(tex, tex.width, tex.height / 2 + 100); frameBytes = croppedTex.EncodeToJPG(); dataToStream.ApproximateCaptureTime = System.DateTime.UtcNow; dataToStream.FrameCount = Time.frameCount; dataToStream.ImageBytes = frameBytes; JSONdataToStream = dataToStream.serialize(); _C.PutRecord(JSONdataToStream, "FrameStream", (response) => { }); frameBytes = null; JSONdataToStream = null; isRunning = false; } yield return(exportInterval); } }
// Get material using search criterias public Material GetMaterial() { Material material = new Material(TextureTools.RandomColor()); materials.Add(material); return(material); }
T IModelPrediction.FetchOutput <T, U>(U inputTex) { //////// TODO : shape should be passed as argument to Transform Input var shape = new TFShape(1, inputWidth, inputHeight, 3); //////// var scaled = TextureTools.scaled(inputTex as Texture2D, 224, 224, FilterMode.Trilinear); var rotated = TextureTools.RotateImageMatrix(scaled.GetPixels32(), scaled.width, scaled.height, 180); var input = graph[inputName][0]; var inputTensor = TFSharpUtils.TransformInput(rotated, 224, 224, inputMean, inputStd); var runner = session.GetRunner(); runner.AddInput(input, inputTensor).Fetch(graph[outputName][0]); var output = runner.Run()[0]; var feautures = output.GetValue() as float[, , , ]; var jagged_features = ((float[][][][])output.GetValue(jagged: true)); var flat3D = jagged_features.SelectMany(a => a).ToArray(); var flat2D = flat3D.SelectMany(a => a).ToArray(); var flat1D = flat2D.SelectMany(a => a).ToArray(); List <float> featureVector = new List <float>(flat1D); inputTensor.Dispose(); output.Dispose(); return(featureVector as T); }
public void ProcessImage(Texture2D tex) { graph = new TFGraph(); graph.Import(model.bytes); session = new TFSession(graph); Debug.Log("Model loaded"); var scaled = TextureTools.scaled(tex, 224, 224, FilterMode.Bilinear); var img = scaled.GetPixels32(); var tensor = TransformInput(img, INPUT_SIZE, INPUT_SIZE); var runner = session.GetRunner(); runner.AddInput(graph[inputName][0], tensor).Fetch(graph[outputName][0]); var output = runner.Run(); //put results into one dimensional array float[] probs = ((float[][])output[0].GetValue(jagged: true))[0]; //get max value of probabilities and find its associated label index float maxValue = probs.Max(); int maxIndex = probs.ToList().IndexOf(maxValue); print(maxIndex); //print label with highest probability string label = labels[maxIndex]; Debug.Log(label); }
private Task <Color32[]> RotateAsync(Color32[] pixels, int width, int height) { return(Task.Run(() => { return TextureTools.RotateImageMatrix( pixels, width, height, -90); })); }
private Texture2D Scale(Texture2D texture, int imageSize) { var scaled = TextureTools.scaled(texture, imageSize, imageSize, FilterMode.Bilinear); //var scaled = TextureTools.test(texture, imageSize, imageSize); return(scaled); }
private Task <Color32[]> RotateAsync(Texture2D scaled) { return(Task.Run(() => { return TextureTools.RotateImageMatrix( scaled.GetPixels32(), scaled.width, scaled.height, -90); })); }
/// <summary> /// Crop the rendered image to have a squared image using the smallest image dimension /// </summary> private Texture2D TakeTextureSnap() { var smallestDimension = Math.Min(m_ImageWidth, m_ImageHeight); var snap = TextureTools.CropWithRect(m_TextureToRender, new Rect(0, 0, smallestDimension, smallestDimension), TextureTools.RectOptions.Center, 0, 0); return(snap); }
private Task <Texture2D> AsyncRotate(Texture2D texture) { return(Task.Run(() => { texture = TextureTools.ReflectTexture(texture); texture = TextureTools.RotateTexture(texture, -90); return texture; })); }
public Texture2D GetTexture(SpriteBatch spriteBatch) { if (texture == null) { texture = TextureTools.GenerateTexture(spriteBatch, Map.BLOCK_WIDTH, Map.BLOCK_HEIGHT, baseColor, 10); } return(texture); }
public mTextureApply(mTexture Texture, int ImageWidth, int ImageHeight) { Width = ImageWidth; Height = ImageHeight; float[,] Txtr = Texture.Texture.Generate(Width, Height); GeneratedBitmap = TextureTools.ToBitmap(Txtr); }
void CreateTexture(ref RenderTexture texture, int resolution, string name) { RenderTextureDescriptor desc = TextureTools.GetDescriptorNoise1D_R(resolution); TextureTools.VerifyTexture(ref texture, desc, name); texture.wrapMode = TextureWrapMode.Mirror; texture.filterMode = FilterMode.Bilinear; }
public IEnumerator FinalizeTextures(System.Diagnostics.Stopwatch stopWatch) { if (coordList.Count == 0) // There's nothing that uses this. { yield break; } int scaleFactor = 1; tileArray = new Texture2DArray(Mathf.ClosestPowerOfTwo(tileWidth * scaleFactor), Mathf.ClosestPowerOfTwo(tileHeight * scaleFactor), coordList.Count, TextureFormat.ARGB32, true); normalArray = new Texture2DArray(Mathf.ClosestPowerOfTwo(tileWidth * scaleFactor), Mathf.ClosestPowerOfTwo(tileHeight * scaleFactor), coordList.Count, TextureFormat.ARGB32, true, true); for (int i = 0; i < coordList.Count; i++) { var coord = coordList[i]; var tileSource = originalPage.GetPixels(coord.x * tileWidth, (pageHeight - coord.y - 1) * tileHeight, tileWidth, tileHeight); var tileSource32 = new Color32[tileSource.Length]; for (int j = 0; j < tileSource.Length; j++) { tileSource32[j] = tileSource[j]; } var tileDest32 = new Color32[tileWidth * scaleFactor * tileHeight * scaleFactor]; switch (scaleFactor) { case 4: HqxSharp.Scale4(tileSource32, tileDest32, tileWidth, tileHeight); break; case 3: HqxSharp.Scale3(tileSource32, tileDest32, tileWidth, tileHeight); break; case 2: HqxSharp.Scale2(tileSource32, tileDest32, tileWidth, tileHeight); break; default: tileDest32 = tileSource32; break; } Texture2D texture = new Texture2D(tileWidth * scaleFactor, tileHeight * scaleFactor, TextureFormat.ARGB32, false); texture.SetPixels32(tileDest32); TextureScale.Bilinear(texture, Mathf.ClosestPowerOfTwo(tileWidth * scaleFactor), Mathf.ClosestPowerOfTwo(tileHeight * scaleFactor)); tileArray.SetPixels(texture.GetPixels(), i); normalArray.SetPixels(TextureTools.Bevel(texture.GetPixels(), texture.width, texture.height), i); if (stopWatch.ElapsedMilliseconds > ContentLoader.LoadFrameTimeout) { yield return(null); stopWatch.Reset(); stopWatch.Start(); } } tileArray.Apply(); normalArray.Apply(); }
public Color32[] ProcessImage() { //crop var cropped = TextureTools.CropTexture(webcamTexture); //scale var scaled = TextureTools.scaled(cropped, 112, 112, FilterMode.Bilinear); //run detection return(scaled.GetPixels32()); }
private IEnumerator ProcessImage(int inputSize, System.Action <Color32[]> callback) { yield return(StartCoroutine(TextureTools.CropSquare(backCamera, TextureTools.RectOptions.Center, snap => { var scaled = Scale(snap, inputSize); var rotated = Rotate(scaled.GetPixels32(), scaled.width, scaled.height); callback(rotated); }))); }
private Texture2D Rotate(Texture2D texture) { var ret = TextureTools.ReflectTexture(texture); #if !UNITY_EDITOR ret = TextureTools.RotateTexture(ret, -90); #endif return(ret); }
private Texture2D TakeTextureSnap() { var smallest = backCamera.width < backCamera.height ? backCamera.width : backCamera.height; var snap = TextureTools.CropWithRect(backCamera, new Rect(0, 0, smallest, smallest), TextureTools.RectOptions.Center, 0, 0); return(snap); }
public static Texture2D CropTexture(Texture2D tex) { var smallest = tex.width < tex.height ? tex.width : tex.height; var snap = TextureTools.CropWithRect(tex, new Rect(0, 0, smallest, smallest), TextureTools.RectOptions.Center, 0, 0); return(snap); }
void CreateTexture(ref RenderTexture texture, int resolution, string name) { RenderTextureDescriptor desc = TextureTools.GetDescriptorNoise3D_RGBA(resolution); TextureTools.VerifyTexture(ref texture, desc, name); texture.wrapMode = TextureWrapMode.Repeat; texture.filterMode = FilterMode.Trilinear; Load(name, texture); }
void CreateTexture(ref RenderTexture texture, int resolution) { RenderTextureDescriptor desc = TextureTools.GetDescriptorNoise3D_RGBA(resolution); desc.graphicsFormat = UnityEngine.Experimental.Rendering.GraphicsFormat.R8G8B8A8_UInt; if (TextureTools.VerifyTexture(ref texture, desc)) { updateNoise = true; } texture.wrapMode = TextureWrapMode.Repeat; }
public Color32[] GetImage() { Texture2D camTex = new Texture2D(image.Width, image.Height); //copy to texture image.CopyToTexture(camTex); //crop var cropped = TextureTools.CropTexture(camTex); //scale var scaled = TextureTools.scaled(cropped, 224, 224, FilterMode.Bilinear); //return scaled color32[] return(scaled.GetPixels32()); }
public static Bitmap combineImages(Bitmap img1, Bitmap img2, Bitmap valuesCombination) { Bitmap below = ImageUtil.convert(img1, PixelFormat.Format24bppRgb); Bitmap over = ImageUtil.convert(img2, PixelFormat.Format24bppRgb); Bitmap values = ImageUtil.convert(valuesCombination, PixelFormat.Format24bppRgb); values = Grayscale.CommonAlgorithms.RMY.Apply(values); TexturedMerge filter = new TexturedMerge(TextureTools.FromBitmap(values)); filter.OverlayImage = over; below = filter.Apply(below); return(below); }
public IEnumerator TakePhoto() { yield return(new WaitForEndOfFrame()); Texture2D photo = new Texture2D(_webCamTexture.width, _webCamTexture.height); photo.SetPixels(_webCamTexture.GetPixels()); photo.Apply(); TextureTools.scale(photo, 128, 128); var tensor = ImageUtil.TransformInput(photo.GetPixels32()); //Encode to a PNG byte[] bytes = photo.EncodeToJPG(); string result = imageTensor.Parse(tensor, bytes); output.text = result; }
void Update() { Debug.Log(worleyTex.enableRandomWrite); worleyTex.enableRandomWrite = true; var sw = System.Diagnostics.Stopwatch.StartNew(); // Validate resolution = Mathf.Max(1, resolution); numPoints = Mathf.Max(1, numPoints); RenderTextureDescriptor desc = TextureTools.GetDescriptorBase(resolution, resolution); TextureTools.VerifyTexture(ref tex2D, desc); if (needsUpdate) { needsUpdate = false; // Run Vector2[] points = new Vector2[numPoints]; worleyCompute2D.SetInt("numLayers", numLayers); worleyCompute2D.SetFloat("persistence", persistence); worleyCompute2D.SetFloat("lacunarity", lacunarity); worleyCompute2D.SetInt("numPoints", numPoints); worleyCompute2D.SetInt("resolution", resolution); worleyCompute2D.SetFloat("multiplier", multiplier); worleyCompute2D.SetFloat("multiplier2", multiplier2); worleyCompute2D.SetFloat("offset", offset); worleyCompute2D.SetInt("seed", seed); worleyCompute2D.SetTexture(0, "values", tex2D); int numThreadGroups = Mathf.CeilToInt(resolution / (float)threadGroupSize); worleyCompute2D.Dispatch(0, numThreadGroups, numThreadGroups, 1); GetComponent <MeshRenderer> ().sharedMaterial.SetTexture("_MainTex", tex2D); if (logTimer) { print("Completed: " + sw.ElapsedMilliseconds + " ms."); } } }
public void ProcessImage() { Image image = camFeed.GetImage(); Texture2D camTex = new Texture2D(image.Width, image.Height); //copy to texture image.CopyToTexture(camTex); //crop var cropped = TextureTools.CropTexture(camTex); //scale var scaled = TextureTools.scaled(cropped, 224, 224, FilterMode.Bilinear); //return scaled color32[] pixels = scaled.GetPixels32(); //create tensor tensor = TransformInput(pixels, INPUT_SIZE, INPUT_SIZE); //run model on other thread modelThread = new Thread(RunModel); modelThread.Start(); }