public ImageImpl() { mWidth = 0; mHeight = 0; mStride = 0; mBufferWidth = 0; mBufferHeight = 0; mPixelFormat = PIXEL_FORMAT.UNKNOWN_FORMAT; mData = null; mUnmanagedData = IntPtr.Zero; mDataSet = false; }
void Start() { #if UNITY_EDITOR mPixelFormat = PIXEL_FORMAT.GRAYSCALE; // Need Grayscale for Editor #else mPixelFormat = PIXEL_FORMAT.RGB888; // Use RGB888 for mobile #endif // Register Vuforia life-cycle callbacks: VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted); VuforiaARController.Instance.RegisterTrackablesUpdatedCallback(OnTrackablesUpdated); VuforiaARController.Instance.RegisterOnPauseCallback(OnPause); }
void Start() { rend = GetComponent <Renderer>(); #if UNITY_EDITOR mPixelFormat = PIXEL_FORMAT.RGBA8888; #else mPixelFormat = PIXEL_FORMAT.RGB888; // Use RGB888 for mobile #endif // Register Vuforia life-cycle callbacks: VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted); VuforiaARController.Instance.RegisterTrackablesUpdatedCallback(OnTrackablesUpdated); VuforiaARController.Instance.RegisterOnPauseCallback(OnPause); }
void Start() { #if UNITY_EDITOR mPixelFormat = PIXEL_FORMAT.GRAYSCALE; // Need Grayscale for Editor #else mPixelFormat = PIXEL_FORMAT.RGB888; // Use RGB888 for mobile #endif // Register Vuforia life-cycle callbacks: VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted); VuforiaARController.Instance.RegisterTrackablesUpdatedCallback(OnTrackablesUpdated); VuforiaARController.Instance.RegisterOnPauseCallback(OnPause); #endregion // MONOBEHAVIOUR_METHODS // 创建 Texture。 // mTexture = new Texture2D(640, 480, TextureFormat.RGBA32, false); }
// Start is called before the first frame update void Start() { #if UNITY_EDITOR mPixelFormat = PIXEL_FORMAT.RGBA8888; // Need Grayscale for Editor #else mPixelFormat = PIXEL_FORMAT.RGB888; // Use RGB888 for mobile #endif // Register Vuforia life-cycle callbacks: VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted); VuforiaARController.Instance.RegisterOnPauseCallback(OnPause); InitTexture(); display.GetComponent <Renderer>().material.mainTexture = tex; }
private void Start() { // Get Light intensity initialIllumination = ambientLight.intensity; countedIllumination = initialIllumination; #if UNITY_EDITOR pixelFormat = PIXEL_FORMAT.GRAYSCALE; #else pixelFormat = PIXEL_FORMAT.RGB888; #endif // Register Vuforia callbacks VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted); VuforiaARController.Instance.RegisterTrackablesUpdatedCallback(OnTrackablesUpdated); VuforiaARController.Instance.RegisterOnPauseCallback(OnPause); }
private TextureFormat ConvertPixelFormat(PIXEL_FORMAT input) { switch (mPixelFormat) { case PIXEL_FORMAT.RGBA8888: return(TextureFormat.RGBA32); case PIXEL_FORMAT.RGB888: return(TextureFormat.RGB24); case PIXEL_FORMAT.RGB565: return(TextureFormat.RGB565); default: return(TextureFormat.Alpha8); } }
private void Start() { if (camText == null) { camText = new WebCamTexture(); } img.GetComponent <Renderer>().material.mainTexture = camText; #if UNITY_EDITOR mPixelFormat = PIXEL_FORMAT.GRAYSCALE; // Need Grayscale for Editor #else mPixelFormat = PIXEL_FORMAT.RGB888; // Use RGB888 for mobile #endif //camText.Play(); }
Mat getImgmat(Vuforia.Image img, PIXEL_FORMAT mPixelFormat) { Mat imgMat = null; if (mPixelFormat == PIXEL_FORMAT.RGBA8888) { Text.text = "before creating of the matrix(cas if) !!"; imgMat = new Mat(img.Height, img.Width, MatType.CV_8UC4); UnityEngine.Debug.Log("\nopencv matrix created (cas if) !! "); Text.text = "opencv matrix created (cas if) !!"; } else if (mPixelFormat == PIXEL_FORMAT.RGB888) { Text.text = "before creating of the matrix (cas else) !!"; imgMat = new Mat(img.Height, img.Width, MatType.CV_8UC3); UnityEngine.Debug.Log("\nopencv matrix created (cas else) !!"); Text.text = "opencv matrix created (cas else) !!"; } return(imgMat); }
/// <summary> /// Map Vuforia's PIXEL_FORMAT enumeration to ZXing's BitmapFormat enumeration wherever applicable. /// </summary> /// <param name="vuforiaFormat">The pixel format set in the inspector.</param> /// <returns>The corresponding BitmapFormat value.</returns> private static BitmapFormat VuforiaToZXingBitmapFormat(PIXEL_FORMAT vuforiaFormat) { switch (vuforiaFormat) { case PIXEL_FORMAT.GRAYSCALE: return(BitmapFormat.Gray8); case PIXEL_FORMAT.RGB888: return(BitmapFormat.RGB24); case PIXEL_FORMAT.RGBA8888: return(BitmapFormat.RGBA32); case PIXEL_FORMAT.RGB565: return(BitmapFormat.RGB565); default: Debug.LogError($"Vuforia {vuforiaFormat} does not have a corresponding ZXing BitmapFormat type. Please use another format type."); return(BitmapFormat.Unknown); } }
private TextureFormat ConvertPixelFormat(PIXEL_FORMAT input) { switch (mPixelFormat) { case PIXEL_FORMAT.RGBA8888: return TextureFormat.RGBA32; case PIXEL_FORMAT.RGB888: return TextureFormat.RGB24; case PIXEL_FORMAT.RGB565: return TextureFormat.RGB565; default: return TextureFormat.Alpha8; } }
public Texture3D Image2Texture3D( uint _Width, uint _Height, uint _Depth, PIXEL_FORMAT _Format, PixelsBuffer[] _SlicesContent ) { return new Texture3D( m_Device, _Width, _Height, _Depth, 1, _Format, false, false, _SlicesContent ); }
public Texture2D Image2Texture( uint _Width, uint _Height, PIXEL_FORMAT _Format, PixelsBuffer[] _MipsContent ) { return new Texture2D( m_Device, _Width, _Height, 1, (uint) _MipsContent.Length, _Format, false, false, _MipsContent ); }
public Texture2D Image2Texture( uint _Width, uint _Height, PIXEL_FORMAT _Format, PixelsBuffer _Content ) { return Image2Texture( _Width, _Height, _Format, new PixelsBuffer[] { _Content } ); }
public ImageFile Combine(ImageFile[] _layers) { if (_layers == null || _layers.Length == 1) { throw new Exception("Invalid list of layers or only 1 layer!"); } uint size = _layers[0].Width; if (_layers[0].Height != size) { throw new Exception("Layers must be square-sized!"); } int sizePOT = (int)(Math.Log(size) / Math.Log(2)); uint mask = size - 1; if ((1 << sizePOT) != size) { throw new Exception("Layer size must be a power of two!"); // For no other reason we want the mask to be full of 1's, otherwise you can replace the & mask by a modulo... :/ } uint layersCount = (uint)_layers.Length; for (uint layerIndex = 1; layerIndex < layersCount; layerIndex++) { if (_layers[layerIndex].Width != size || _layers[layerIndex].Height != size) { throw new Exception("Layer sizes mismatch!"); } } // Read layers into a simple format float[][,] layers = new float[layersCount][, ]; for (uint layerIndex = 0; layerIndex < layersCount; layerIndex++) { layers[layerIndex] = new float[size, size]; _layers[layerIndex].ReadPixels((uint X, uint Y, ref float4 _color) => { layers[layerIndex][X, Y] = _color.x; }); } float4[,] alignedLayers = new float4[size, size]; for (uint Y = 0; Y < size; Y++) { for (uint X = 0; X < size; X++) { alignedLayers[X, Y].x = layers[0][X, Y]; } } const double sigma_s = 1.0; double exponentialFactor = -1.0 / sigma_s; // Attempt to align each layer for (uint layerIndex = 1; layerIndex < layersCount; layerIndex++) { float[,] layer = layers[layerIndex]; uint bestOffsetX = 0, bestOffsetY = 0; double minScore = double.MaxValue; for (uint offsetY = 0; offsetY < size; offsetY++) { for (uint offsetX = 0; offsetX < size; offsetX++) { // Accumulate scores for each pixel double score = 0.0; switch (layerIndex) { case 1: { for (uint Y = 0; Y < size; Y++) { for (uint X = 0; X < size; X++) { float V0 = alignedLayers[X, Y].x; // Already aligned float V1 = layer[(X + offsetX) & mask, (Y + offsetY) & mask]; float delta = Math.Abs(V0 - V1); score += Math.Exp(exponentialFactor * delta); } } break; } case 2: { for (uint Y = 0; Y < size; Y++) { for (uint X = 0; X < size; X++) { float V0 = alignedLayers[X, Y].x; // Already aligned float V1 = alignedLayers[X, Y].y; // Already aligned float V2 = layer[(X + offsetX) & mask, (Y + offsetY) & mask]; float delta0 = Math.Abs(V2 - V0); float delta1 = Math.Abs(V2 - V1); score += Math.Exp(exponentialFactor * (Math.Pow(delta0, 1.5) + Math.Pow(delta1, 1.5))); } } break; } case 3: { for (uint Y = 0; Y < size; Y++) { for (uint X = 0; X < size; X++) { float V0 = alignedLayers[X, Y].x; // Already aligned float V1 = alignedLayers[X, Y].y; // Already aligned float V2 = alignedLayers[X, Y].z; // Already aligned float V3 = layer[(X + offsetX) & mask, (Y + offsetY) & mask]; float delta0 = V3 - V0; float delta1 = V3 - V1; float delta2 = V3 - V2; score += Math.Exp(exponentialFactor * (delta0 * delta0 + delta1 * delta1 + delta2 * delta2)); } } break; } } score /= size * size; // Not necessary but easier to debug... // Keep best score and position where it was found if (score < minScore) { // Better! minScore = score; bestOffsetX = offsetX; bestOffsetY = offsetY; } } } // Write the layer with the best selected offset switch (layerIndex) { case 1: for (uint Y = 0; Y < size; Y++) { for (uint X = 0; X < size; X++) { alignedLayers[X, Y].y = layer[(X + bestOffsetX) & mask, (Y + bestOffsetY) & mask]; } } break; case 2: for (uint Y = 0; Y < size; Y++) { for (uint X = 0; X < size; X++) { alignedLayers[X, Y].z = layer[(X + bestOffsetX) & mask, (Y + bestOffsetY) & mask]; } } break; case 3: for (uint Y = 0; Y < size; Y++) { for (uint X = 0; X < size; X++) { alignedLayers[X, Y].w = layer[(X + bestOffsetX) & mask, (Y + bestOffsetY) & mask]; } } break; } } // Create resulting image PIXEL_FORMAT format = PIXEL_FORMAT.UNKNOWN; switch (layersCount) { case 2: format = PIXEL_FORMAT.RGB8; break; // FreeImage doesn't support R8G8! It believes we're specifying R5G6B5! :( case 3: format = PIXEL_FORMAT.RGB8; break; case 4: format = PIXEL_FORMAT.RGBA8; break; } ImageFile result = new ImageFile(size, size, format, new ColorProfile(ColorProfile.STANDARD_PROFILE.sRGB)); result.WritePixels((uint X, uint Y, ref float4 _color) => { _color = alignedLayers[X, Y]; }); return(result); }