private void ImageHandler(IntPtr handle) { if (OnImage != null) { VLImageWrapper image = new VLImageWrapper(handle, false); OnImage(image); image.Dispose(); } }
/// <summary> /// Automatically starts LearnWorkSpaceInitData() /// after the VLWorkerBehaviour got an image the first time /// </summary> /// <param name="success"></param> private void AutoStartLearningAfterImage(VLImageWrapper vlImage) { VLWorkerBehaviour.OnImage -= AutoStartLearningAfterImage; if (this.autoStartLearning) { LearnWorkSpaceInitData(); } }
private void OnImage(VLImageWrapper image) { // Use camera image as texture int imageWidth = image.GetWidth(); int imageHeight = image.GetHeight(); if (imageWidth > 0 && imageHeight > 0) { int imageByteSize = imageWidth * imageHeight * image.GetBytesPerPixel(); if (this.backgroundMeshData0.textureData.Length != imageByteSize) { this.backgroundMeshData0.textureData = new byte[imageByteSize]; } // Copy the image into a byte array if (image.CopyToBuffer(this.backgroundMeshData0.textureData)) { // Generate a texture from the byte array if (!this.backgroundMeshData0.texture || this.backgroundMeshData0.texture.width != imageWidth || this.backgroundMeshData0.texture.height != imageHeight) { this.backgroundMeshData0.texture = CreateTexture( imageWidth, imageHeight, image.GetFormat()); this.backgroundMeshData0.material.mainTexture = this.backgroundMeshData0.texture; this.UpdateBackgroundSize(); } if (this.backgroundMeshData0.texture) { this.backgroundMeshData0.texture.LoadRawTextureData( this.backgroundMeshData0.textureData); this.backgroundMeshData0.texture.Apply(); } } } else { Debug.LogWarning("[vlUnitySDK] Image size is 0"); } }
private static void DispatchNamedImageEvent(IntPtr handle, IntPtr clientData) { try { VLImageWrapper image = new VLImageWrapper(handle, false); GCHandle gcHandle = GCHandle.FromIntPtr(clientData); VLDebugImageBehaviour debugImageBehaviour = (VLDebugImageBehaviour)gcHandle.Target; debugImageBehaviour.OnImage(image); image.Dispose(); } catch (Exception e) // Catch all exceptions, because this is a callback // invoked from native code { Debug.LogError("[vlUnitySDK] " + e.GetType().Name + ": " + e.Message); } }
private void OnImage(VLImageWrapper image) { // Use camera image as texture int imageWidth = image.GetWidth(); int imageHeight = image.GetHeight(); if (imageWidth > 0 && imageHeight > 0) { int imageByteSize = imageWidth * imageHeight * image.GetBytesPerPixel(); if (this.textureData == null || this.textureData.Length != imageByteSize) { this.textureData = new byte[imageByteSize]; } // Copy the image into a byte array if (image.CopyToBuffer(this.textureData)) { // Generate a texture from the byte array VLUnitySdk.ImageFormat imageFormat = image.GetFormat(); TextureFormat textureFormat = ImageFormatToTextureFormat(imageFormat); if (!this.texture || this.texture.width != imageWidth || this.texture.height != imageHeight || this.texture.format != textureFormat) { this.texture = new Texture2D( imageWidth, imageHeight, textureFormat, false); this.rawImage.texture = this.texture; this.UpdateImageSize(); } if (this.texture) { this.texture.LoadRawTextureData(this.textureData); this.texture.Apply(); } } } }