/** * Set the data for this info board. * * @param recognizedArtwork the recognized artwork information * @param placement initial info board placement * @param artwork data artwork for this info board * @param middlePoint middle point of the recognized artwork */ public void SetData(RecognizedArtwork recognizedArtwork, InfoBoardPlacement placement, Artwork artwork, Vector3 middlePoint) { this.anchorManager = WorldAnchorManager.Instance; this.logger = DebugLogger.Instance; this.infoCanvas = InfoCanvas.Instance; this.arrows = UIArrows.Instance; this.recognizedArtwork = recognizedArtwork; this.currentPlacement = placement; this.artwork = artwork; this.middlePoint = middlePoint; StartCoroutine(Initialize()); }
/** * Create a recognition object. * * @param artwork the actual artwork * @param worldSpaceCamera world space point of the camera * @param worldSpaceMiddle world space point of the middle of the recognized artwork * @param worldSpaceTopLeft world space point of the top left corner of the recognized artwork * @param worldSpaceTopRight world space point of the top right corner of the recognized artwork * @param worldSpaceBottomLeft world space point of the bottom left corner of the recognized artwork * @param worldSpaceBottomRight world space point of the bottom right corner of the recognized artwork */ public Recognition(Artwork artwork, Vector3 worldSpaceCamera, Vector3 worldSpaceMiddle, Vector3 worldSpaceTopLeft, Vector3 worldSpaceTopRight, Vector3 worldSpaceBottomLeft, Vector3 worldSpaceBottomRight) { this.Artwork = artwork; this.ValidationFinished = false; this.WorldSpaceCamera = worldSpaceCamera; this.WorldSpaceMiddle = worldSpaceMiddle; this.WorldSpaceTopLeft = worldSpaceTopLeft; this.WorldSpaceTopRight = worldSpaceTopRight; this.WorldSpaceBottomLeft = worldSpaceBottomLeft; this.WorldSpaceBottomRight = worldSpaceBottomRight; }
/** * Set newly recognized data for this artwork. * * @param info recognition infomation */ public void SetNewData(Recognition info) { this.artwork = info.Artwork; this.name = ARTWORK_ANCHOR_PREFIX + this.artwork.artworkID; this.worldSpaceCamera = info.WorldSpaceCamera; this.worldSpaceMiddle = info.WorldSpaceMiddle; this.worldSpaceTopLeft = info.WorldSpaceTopLeft; this.worldSpaceTopRight = info.WorldSpaceTopRight; this.worldSpaceBottomLeft = info.WorldSpaceBottomLeft; this.worldSpaceBottomRight = info.WorldSpaceBottomRight; this.newData = true; }
/** * Add a feature matching model. * * @param artworkID artwork for which the corresponding model should be created */ private void AddFeatureMatchingModel(int artworkID) { #if ENABLE_WINMD_SUPPORT // Create feature matching model if (this.artworks.ContainsKey(artworkID)) { Artwork artwork = this.artworks[artworkID]; CW.FeatureMatchingModel fModel = new CW.FeatureMatchingModel(artwork.localImagePath, artworkID); // Add feature matching model this.matchRecognition.addModel(fModel); this.logger.Log("Artwork " + artworkID + " added to Companion."); } #endif }
/** * Update the artwork data. * * @param artworks list of artworks */ private void UpdateArtworks(List <Artwork> artworks) { // Update artworks foreach (Artwork remoteArt in artworks) { int id = remoteArt.artworkID; string imageName = ARTWORK_IMAGE_PREFIX + id + IMAGE_FORMAT; string imagePath = this.ArtworkPath + PATH_SEPARATOR + imageName; // Check if this artwork already exists if (this.Artworks.ContainsKey(id)) { Artwork localArt = this.Artworks[id]; if (remoteArt.timestamp > localArt.timestamp) { // Update artist this.logger.Log("Update artwork: " + id); remoteArt.localImagePath = imagePath; this.Artworks[id] = remoteArt; this.loadDataCounter++; // Save image WWW request = new WWW(remoteArt.image); StartCoroutine(this.WaitForWWW(WebRequestFormat.Media, request, imagePath, imageName)); } else { this.logger.Log(ARTWORK_IMAGE_PREFIX + id + " is up to date."); } } else { // Add new artwork this.logger.Log("Add new artwork: " + id); remoteArt.localImagePath = imagePath; this.Artworks.Add(id, remoteArt); this.loadDataCounter++; // Save image WWW request = new WWW(remoteArt.image); StartCoroutine(this.WaitForWWW(WebRequestFormat.Media, request, imagePath, imageName)); } } }
/** * Result callback method for the Companion processing. * * @param results list of results that represent the recognized artworks * @param image the processed image with visually markers for the recognized artworks */ public void ResultCallback(IList <CW.Result> results, byte[] image) { // Ignore the result if the camera matrices of the processed photo were not obtained successfully if (!this.newCameraMatrices || (results.Count == 0)) { this.logger.Log("No results."); this.ProcessingStopped(); return; } // Reset camera matrices for this photo this.newCameraMatrices = false; bool newResults = false; Vector3 worldSpaceCamera; Vector3 worldSpaceMiddle; Vector3 worldSpaceTopLeft; Vector3 worldSpaceTopRight; Vector3 worldSpaceBottomLeft; Vector3 worldSpaceBottomRight; CW.Point upperLeftCorner; upperLeftCorner.x = 0; upperLeftCorner.y = 0; CW.Point upperRightCorner; upperRightCorner.x = 0; upperRightCorner.y = 0; CW.Point bottomRightCorner; bottomRightCorner.x = 0; bottomRightCorner.y = 0; CW.Point bottomLeftCorner; bottomLeftCorner.x = 0; bottomLeftCorner.y = 0; // ToDo: MultiplyPoint3x4 !! worldSpaceCamera = this.cameraToWorld.MultiplyPoint(new Vector3(0, 0, 0 /*, 1*/)); // camera location in world space // float casting float image_width = this.cameraResolution.width; float image_height = this.cameraResolution.height; foreach (CW.Result result in results) { int artworkID = result.getID(); // Ignore results for artworks, the ID of which is not within the eligible range if ((result.getType() != CW.ResultType.RECOGNITION) || !this.IsIdEligible(artworkID)) { this.logger.Log("Artwork " + artworkID + " has an ineligible ID."); continue; } // Ignore results for artworks that were already recognized if (this.recognizedArtworks[artworkID]) { this.logger.Log("Artwork " + artworkID + " already recognized."); continue; } this.logger.Log("Corners found for artwork " + artworkID + "."); upperLeftCorner = result.getFrame().getUpperLeftCorner(); upperRightCorner = result.getFrame().getUpperRightCorner(); bottomRightCorner = result.getFrame().getLowerRightCorner(); bottomLeftCorner = result.getFrame().getLowerLeftCorner(); float middleX = upperLeftCorner.x + ((upperRightCorner.x - upperLeftCorner.x) / 2.0f); float middleY = upperLeftCorner.y + ((bottomLeftCorner.y - upperLeftCorner.y) / 2.0f); Vector2 ImagePosZeroToOne = new Vector2(middleX / image_width, 1.0f - (middleY / image_height)); Vector2 ImagePosProjected = ((ImagePosZeroToOne * 2.0f) - new Vector2(1.0f, 1.0f)); // -1 to 1 space Vector3 CameraSpacePos = UnProjectVector(this.projection, new Vector3(ImagePosProjected.x, ImagePosProjected.y, 1.0f)); worldSpaceMiddle = this.cameraToWorld.MultiplyPoint(CameraSpacePos); // ray point in world space ImagePosZeroToOne = new Vector2(upperLeftCorner.x / image_width, 1.0f - (upperLeftCorner.y / image_height)); ImagePosProjected = ((ImagePosZeroToOne * 2.0f) - new Vector2(1.0f, 1.0f)); // -1 to 1 space CameraSpacePos = UnProjectVector(this.projection, new Vector3(ImagePosProjected.x, ImagePosProjected.y, 1.0f)); worldSpaceTopLeft = this.cameraToWorld.MultiplyPoint(CameraSpacePos); // ray point in world space ImagePosZeroToOne = new Vector2(upperRightCorner.x / image_width, 1.0f - (upperRightCorner.y / image_height)); ImagePosProjected = ((ImagePosZeroToOne * 2.0f) - new Vector2(1.0f, 1.0f)); // -1 to 1 space CameraSpacePos = UnProjectVector(this.projection, new Vector3(ImagePosProjected.x, ImagePosProjected.y, 1.0f)); worldSpaceTopRight = this.cameraToWorld.MultiplyPoint(CameraSpacePos); // ray point in world space ImagePosZeroToOne = new Vector2(bottomRightCorner.x / image_width, 1.0f - (bottomRightCorner.y / image_height)); ImagePosProjected = ((ImagePosZeroToOne * 2.0f) - new Vector2(1.0f, 1.0f)); // -1 to 1 space CameraSpacePos = UnProjectVector(this.projection, new Vector3(ImagePosProjected.x, ImagePosProjected.y, 1.0f)); worldSpaceBottomRight = this.cameraToWorld.MultiplyPoint(CameraSpacePos); // ray point in world space ImagePosZeroToOne = new Vector2(bottomLeftCorner.x / image_width, 1.0f - (bottomLeftCorner.y / image_height)); ImagePosProjected = ((ImagePosZeroToOne * 2.0f) - new Vector2(1.0f, 1.0f)); // -1 to 1 space CameraSpacePos = UnProjectVector(this.projection, new Vector3(ImagePosProjected.x, ImagePosProjected.y, 1.0f)); worldSpaceBottomLeft = this.cameraToWorld.MultiplyPoint(CameraSpacePos); // ray point in world space #if COMP_DEBUG_IMAGE // Calculate image corners in world space coordinates ImagePosZeroToOne = new Vector2(0.5f, 0.5f); ImagePosProjected = ((ImagePosZeroToOne * 2.0f) - new Vector2(1.0f, 1.0f)); // -1 to 1 space CameraSpacePos = UnProjectVector(this.projection, new Vector3(ImagePosProjected.x, ImagePosProjected.y, 1.0f)); Vector3 imageMiddle = this.cameraToWorld.MultiplyPoint(CameraSpacePos); // ray point in world space ImagePosZeroToOne = new Vector2(0.0f, 1.0f); ImagePosProjected = ((ImagePosZeroToOne * 2.0f) - new Vector2(1.0f, 1.0f)); // -1 to 1 space CameraSpacePos = UnProjectVector(this.projection, new Vector3(ImagePosProjected.x, ImagePosProjected.y, 1.0f)); Vector3 imageTopLeft = this.cameraToWorld.MultiplyPoint(CameraSpacePos); // ray point in world space ImagePosZeroToOne = new Vector2(1.0f, 1.0f); ImagePosProjected = ((ImagePosZeroToOne * 2.0f) - new Vector2(1.0f, 1.0f)); // -1 to 1 space CameraSpacePos = UnProjectVector(this.projection, new Vector3(ImagePosProjected.x, ImagePosProjected.y, 1.0f)); Vector3 imageTopRight = this.cameraToWorld.MultiplyPoint(CameraSpacePos); // ray point in world space ImagePosZeroToOne = new Vector2(0.0f, 0.0f); ImagePosProjected = ((ImagePosZeroToOne * 2.0f) - new Vector2(1.0f, 1.0f)); // -1 to 1 space CameraSpacePos = UnProjectVector(this.projection, new Vector3(ImagePosProjected.x, ImagePosProjected.y, 1.0f)); Vector3 imageBottomLeft = this.cameraToWorld.MultiplyPoint(CameraSpacePos); // ray point in world space // Save result image this.resultImage = new ResultImage(image, worldSpaceCamera, imageMiddle, imageTopLeft, imageTopRight, imageBottomLeft); #endif // Save information about the recognized artwork Artwork artwork = this.artworks[artworkID]; Recognition recognition = new Recognition(artwork, worldSpaceCamera, worldSpaceMiddle, worldSpaceTopLeft, worldSpaceTopRight, worldSpaceBottomLeft, worldSpaceBottomRight); this.recognitions.Add(artworkID, recognition); newResults = true; } // Check if the found results were ignored because they were already recognized before if (!newResults) { this.logger.Log("Artworks already recognized."); this.ProcessingStopped(); } else { // Beginn processing of new data this.newData = true; } }