Beispiel #1
0
        public int AddAugmentedImageAtRuntime(IntPtr augmentedImageDatabaseHandle, string name,
                                              AugmentedImageSrc imageSrc, float width)
        {
            int outIndex = -1;

            if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage(
                    "add images to Augmented Image database");
                return(outIndex);
            }

            GCHandle grayscaleBytesHandle = _ConvertTextureToGrayscaleBytes(imageSrc);

            if (grayscaleBytesHandle.AddrOfPinnedObject() == IntPtr.Zero)
            {
                return(-1);
            }

            ApiArStatus status;

            if (width > 0)
            {
                status = ExternApi.ArAugmentedImageDatabase_addImageWithPhysicalSize(
                    m_NativeSession.SessionHandle, augmentedImageDatabaseHandle, name,
                    grayscaleBytesHandle.AddrOfPinnedObject(), imageSrc.Width,
                    imageSrc.Height, imageSrc.Width, width, ref outIndex);
            }
            else
            {
                status = ExternApi.ArAugmentedImageDatabase_addImage(
                    m_NativeSession.SessionHandle, augmentedImageDatabaseHandle, name,
                    grayscaleBytesHandle.AddrOfPinnedObject(), imageSrc.Width,
                    imageSrc.Height, imageSrc.Width, ref outIndex);
            }

            if (grayscaleBytesHandle.IsAllocated)
            {
                grayscaleBytesHandle.Free();
            }

            if (status != ApiArStatus.Success)
            {
                Debug.LogWarningFormat(
                    "Failed to add aumented image at runtime with status {0}", status);
                return(-1);
            }

            return(outIndex);
        }
Beispiel #2
0
        public override void RegisterMarker(RawImageMarker marker)
        {
            if (marker.TargetImage == null)
            {
                return;
            }

            string url = marker.TargetImage.Url;

            m_logger.Debug("Registering image target {0}", url);

            ImageLoader.LoadTexture(url, (tex) =>
            {
                var pxs = tex.GetPixels32();

                var gs = new byte[pxs.Length];

                m_logger.Debug("Got px len={0}", pxs.Length);

                for (int iy = 0, oy = pxs.Length - tex.width;
                     iy < pxs.Length;
                     iy += tex.width, oy -= tex.width)
                {
                    for (int x = 0; x < tex.width; x++)
                    {
                        int gidx = oy + x;
                        var c    = pxs[iy + x];

                        gs[gidx] = (byte)((c.r + c.g + c.b) / 3);
                    }
                }

                //System.IO.File.WriteAllBytes(@"C:\Users\ryan\Projects\Sandbox\img", gs);

                //#if !UNITY_EDITOR
                int idx;

                m_logger.Debug("ArAugmentedImageDatabase_addImage({0}, {1}, {2}, {3})", marker.Name, tex.width, tex.height, tex.width);

                int result = 0;

                if (marker.ImageSize != null && marker.ImageSize.Width.HasValue)
                {
                    result = ExternApi.ArAugmentedImageDatabase_addImageWithPhysicalSize(
                        m_sessionHandle, m_dbHandle, Encoding.UTF8.GetBytes(marker.Name), gs, tex.width, tex.height, tex.width, (float)marker.ImageSize.Width.Value, out idx);
                }
                else
                {
                    result = ExternApi.ArAugmentedImageDatabase_addImage(
                        m_sessionHandle, m_dbHandle, Encoding.UTF8.GetBytes(marker.Name), gs, tex.width, tex.height, tex.width, out idx);
                }

                m_logger.Debug("Got result {0} from ArAugmentedImageDatabase_addImage idx={1}", result, idx);

                m_markerIdentifiers[idx] = marker.GetIdentifier();

                UpdateConfig();

                int numImages;

                ExternApi.ArAugmentedImageDatabase_getNumImages(m_sessionHandle, m_dbHandle, out numImages);

                m_logger.Debug("DB now has {0} images", numImages);

                //#endif
            });

            base.RegisterMarker(marker);
        }