public void StartProcessing() { Debug.Log("ImagePosterLocator:StartProcessing: " + gameObject.name); UpdatePosterDebug(); posterLocationHandler = null; PVCamManager.Instance.RegisterForFrames(this.OnCaptureCompleted); }
private bool OnCaptureCompleted(PhotoCaptureFrame frame) { if (this.isProcessingImage) { return(true); } this.isProcessingImage = true; Matrix4x4 cameraToWorldMatrix; frame.TryGetCameraToWorldMatrix(out cameraToWorldMatrix); cameraToWorldMatrix = cameraToWorldMatrix * Matrix4x4.Scale(new Vector3(1, 1, -1)); // Update the preview image with the last image processed UpdatePreviewTexture(cameraImageBuffer); var res = PVCamManager.Instance.PhotoCapCamResolution; var w = res.width; var h = res.height; if (posterLocationHandler == null) { posterLocationHandler = new PosterLocationHandler(w, h); } Matrix4x4 cameraClipToWorld; Vector3 cameraPos; var camProj = TuneProjectionMatrix(frame); GetCameraClipTransformAndWorldPosition(cameraToWorldMatrix, camProj, out cameraClipToWorld, out cameraPos); posterLocationHandler.UpdateCamera(cameraToWorldMatrix, camProj, cameraPos); DoOnSeperateThread(() => { // Allocate the buffers to hold the image data if ((cameraImageListBuffer == null) || (cameraImageListBuffer.Count != frame.dataLength)) { cameraImageListBuffer = new List <byte>(frame.dataLength); } if ((cameraImageBuffer == null) || (cameraImageBuffer.Length != frame.dataLength)) { cameraImageBuffer = new byte[frame.dataLength]; cameraImageGCHandle = GCHandle.Alloc(cameraImageBuffer, GCHandleType.Pinned); cameraImagePtrToData = cameraImageGCHandle.AddrOfPinnedObject(); } frame.CopyRawImageDataIntoBuffer(cameraImageListBuffer); // Copy the image data from the list into the byte array cameraImageListBuffer.CopyTo(cameraImageBuffer); PVCamManager.Instance.SignalFinishedWithFrame(); // Find the poster: this.FindPoster(w, h); this.isProcessingImage = false; }); return(false); }