public void UpdateFrame(ARSessionUpdateEventArgs e) { var frame = e.IFrame; var image = frame.image(); if (image != null) { var img = image; UpdateRender(img); var screenRotation = Utility.GetScreenRotation(); var viewport_aspect_ratio = targetCamera.aspect; var projection = Utility.Matrix44FToMatrix4x4(e.CameraParam.projection(targetCamera.nearClipPlane, targetCamera.farClipPlane, viewport_aspect_ratio, screenRotation, true, false)); var imageProjection = Utility.Matrix44FToMatrix4x4(e.CameraParam.imageProjection(viewport_aspect_ratio, screenRotation, true, false)); targetCamera.projectionMatrix = projection * e.ImageRotationMatrixGlobal.inverse; mat.SetMatrix("_TextureRotation", imageProjection); img.Dispose(); } else { Debug.Log("[EasyAR] image is null"); } }
public void UpdateFrame(ARSessionUpdateEventArgs e) { var frame = e.IFrame; var image = frame.image(); if (image != null) { var img = image; UpdateRender(img); var screenRotation = Utility.GetScreenRotation(); var viewport_aspect_ratio = targetCamera.aspect; var projection = Utility.Matrix44FToMatrix4x4(e.CameraParam.projection(targetCamera.nearClipPlane, targetCamera.farClipPlane, viewport_aspect_ratio, screenRotation, true, false)); var imageProjection = Utility.Matrix44FToMatrix4x4(e.CameraParam.imageProjection(viewport_aspect_ratio, screenRotation, true, false)); targetCamera.projectionMatrix = projection * e.ImageRotationMatrixGlobal.inverse; mat.SetMatrix("_TextureRotation", imageProjection); // HERE WE GET ALL BYTES FROM EASYAR AND TRANSFER TO ZXING TO DECODE // byte[] allbyte = new byte[img.buffer().size()]; img.buffer().copyToByteArray(0, allbyte, 0, img.buffer().size()); if (dataSignal) { data.image = allbyte; data.imageHeight = img.height(); data.imageWidth = img.width(); data.imageSize = img.buffer().size(); dataSignal = false; } /////////////////////////////////////////////////////////////////////// img.Dispose(); } else { Debug.Log("image is null"); } }
void Init() { initialized = true; iFrameThrottler = InputFrameThrottler.create(); oFrameBuffer = OutputFrameBuffer.create(); i2fAdapter = InputFrameToFeedbackFrameAdapter.create(); inputFrameFork = InputFrameFork.create(ForkOutputNum); i2OAdapter = InputFrameToOutputFrameAdapter.create(); oFrameJoin = OutputFrameJoin.create(JoinNum); if (FrameSourceType == FrameSource.easyar) { if (CameraDevice.isAvailable()) { Debug.Log("[EasyAR] use ezar camera device"); easyarCamera = CameraDeviceSelector.createCameraDevice(EasyarCameraPrefer); var openResult = false; if (UseSecondCamera) { openResult = easyarCamera.openWithIndex(1); } else { openResult = easyarCamera.openWithType(CameraDeviceType.Default); } easyarCamera.setFocusMode(CameraFocusMode); if (!openResult) { Debug.Log("[EasyAR] open camera failed"); initialized = false; return; } easyarCamera.setSize(new Vec2I((int)CameraSize.x, (int)CameraSize.y)); easyarCamera.inputFrameSource().connect(iFrameThrottler.input()); easyarCamera.start(); } else { initialized = false; Debug.Log("[EasyAR] ezar camera device can not work"); return; } } iFrameThrottler.output().connect(inputFrameFork.input()); inputFrameFork.output(0).connect(i2OAdapter.input()); i2OAdapter.output().connect(oFrameJoin.input(0)); outputFrameFork = OutputFrameFork.create(1); int index = 0; if (ImgTracker != null) { index++; outputFrameFork = OutputFrameFork.create(2); inputFrameFork.output(index).connect(i2fAdapter.input()); i2fAdapter.output().connect(ImgTracker.Input()); ImgTracker.Output().connect(oFrameJoin.input(index)); outputFrameFork.output(1).connect(i2fAdapter.sideInput()); } if (SfTracker != null) { index++; inputFrameFork.output(index).connect(SfTracker.Input()); SfTracker.Output().connect(oFrameJoin.input(index)); } if (CloudImageRecognizer != null) { index++; inputFrameFork.output(index).connect(CloudImageRecognizer.Input()); } oFrameJoin.output().connect(outputFrameFork.input()); outputFrameFork.output(0).connect(oFrameBuffer.input()); oFrameBuffer.signalOutput().connect(iFrameThrottler.signalInput()); args = new ARSessionUpdateEventArgs(); }
public void UpdateFrame(ARSessionUpdateEventArgs args) { List <ImageTargetController> currentTrackingControllers = new List <ImageTargetController>(); var results = args.OFrame.results(); foreach (var _result in results) { ImageTrackerResult result = null; if (_result.OnSome) { result = _result.Value as ImageTrackerResult; } if (result != null) { var targetInstances = result.targetInstances(); int centerTargetId = -1; if (TargetCamera == null) { Utility.SetMatrixOnTransform(Camera.main.transform, centerTransform); } else { Utility.SetMatrixOnTransform(TargetCamera.transform, centerTransform); } if (CenterImageTarget != null && CenterImageTarget.Target() != null && CenterTarget == CenterMode.SpecificTarget) { centerTargetId = CenterImageTarget.Target().runtimeID(); } foreach (var targetInstance in targetInstances) { var target = targetInstance.target(); if (!target.OnSome) { continue; } var status = targetInstance.status(); foreach (var targetController in targetControllers) { var _target = targetController.Target(); if (target.Value.runtimeID() == _target.runtimeID()) { if (status == TargetStatus.Tracked) { if (!targetController.Tracked) { targetController.OnFound(); targetController.Tracked = true; } var pose = Utility.Matrix44FToMatrix4x4(targetInstance.pose()); pose = args.ImageRotationMatrixGlobal * pose; if (CenterTarget == CenterMode.FirstTarget && centerTargetId == -1) { centerTargetId = target.Value.runtimeID(); CenterImageTarget = targetController; } if (centerTargetId != target.Value.runtimeID()) { pose = centerTransform * pose; targetController.OnTracking(pose); } else { targetController.OnTracking(Matrix4x4.identity); centerTransform = pose.inverse; } currentTrackingControllers.Add(targetController); } } } target.Value.Dispose(); targetInstance.Dispose(); } result.Dispose(); } } foreach (var targetController in targetControllers) { bool contain = false; foreach (var item in currentTrackingControllers) { if (item == targetController) { contain = true; } } if (!contain && targetController.Tracked) { targetController.OnLost(); targetController.Tracked = false; } } }
public void UpdateFrame(ARSessionUpdateEventArgs args) { var frame = args.OFrame; var results = args.OFrame.results(); foreach (var _result in results) { SurfaceTrackerResult result = null; if (_result.OnSome) { result = _result.Value as SurfaceTrackerResult; } if (result != null && Target != null) { if (result.status() != SurfaceTrackingStatus.NotTracking) { if (!Target.Tracked) { Target.OnFound(); Target.Tracked = true; } var easyarTransform = result.transform(); var unityTransform = Utility.Matrix44FToMatrix4x4(easyarTransform); unityTransform = unityTransform * args.ImageRotationMatrixGlobal.inverse; Target.OnTracking(unityTransform); } else { Target.OnLost(); Target.Tracked = false; } result.Dispose(); } } if (!PickSwitch) { return; } var cameraParams = args.CameraParam; if (cameraParams != null && Target != null && UnityEngine.Input.touchCount > 0) { var touch = UnityEngine.Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { TouchInfo info = new TouchInfo(); info.position = touch.position; touchInfoList.Add(info); } else if (touch.phase == TouchPhase.Ended) { var distance = touchInfoList[0].position - touch.position; touchInfoList.Clear(); if (distance.magnitude > 0.1) { return; } var position = touch.position; var position_normalize = new Vector2(position.x / Screen.width, 1 - position.y / Screen.height); var aspectRatio = Target.TargetCamera.aspect; var screenRotation = Utility.GetScreenRotation(); var imageCoordinates = cameraParams.imageCoordinatesFromScreenCoordinates( aspectRatio, screenRotation, true, false, new Vec2F(position_normalize.x, position_normalize.y)); tracker.alignTargetToCameraImagePoint(imageCoordinates); } } }