void OnCapturedPhotoToMemory(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame) { if (result.success) { Debug.Log("Photo Captured"); // Create our Texture2D for use and set the correct resolution // GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad); Renderer quadRenderer = quad.GetComponent <Renderer>() as Renderer; Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First(); Texture2D targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height); Debug.Log(cameraResolution.width + " " + cameraResolution.height); // Copy the raw image data into our target texture photoCaptureFrame.UploadImageDataToTexture(targetTexture); Texture2D newImage = CropImage(targetTexture, cameraResolution.width / 2, cameraResolution.height / 2); quadRenderer.material = new Material(Shader.Find("Unlit/Texture")); //quad.transform.parent = this.transform; // quad.transform.localPosition = new Vector3(0.0f, 0.0f, 3.0f); quadRenderer.material.SetTexture("_MainTex", newImage); text.SetActive(false); } // Clean up Debug.Log("Cleaning it up"); photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode); }
void onCapturedPhotoToMemory(UnityEngine.XR.WSA.WebCam.PhotoCapture.PhotoCaptureResult result, UnityEngine.XR.WSA.WebCam.PhotoCaptureFrame photoCaptureFrame) { if (!result.success) { Debug.LogError("Error CapturedPhotoToMemory"); return; } // 撮影画像の取得 List <byte> buffer = new List <byte>(); photoCaptureFrame.CopyRawImageDataIntoBuffer(buffer); photoCapture.StopPhotoModeAsync(onStoppedPhotoMode); // QR照準内のみを切り取る List <byte> trimmedBuffer = trimmingQrSight(buffer, 4); // QR照準内の画像を保存 Texture2D tex = createTexture(trimmedBuffer, cameraParameters.cameraResolutionWidth, cameraParameters.cameraResolutionHeight); saveToFile(tex); if (callback != null) { callback(new List <byte>(trimmedBuffer), cameraParameters.cameraResolutionWidth, cameraParameters.cameraResolutionHeight); } }
// Capture de l'image void OnCapturedPhotoToMemory(UnityEngine.XR.WSA.WebCam.PhotoCapture.PhotoCaptureResult result, UnityEngine.XR.WSA.WebCam.PhotoCaptureFrame photoCaptureFrame) { if (result.success) { Debug.Log("photo captured"); List <byte> imageBufferList = new List <byte>(); photoCaptureFrame.CopyRawImageDataIntoBuffer(imageBufferList); var cameraToWorldMatrix = new Matrix4x4(); photoCaptureFrame.TryGetCameraToWorldMatrix(out cameraToWorldMatrix); camera_pos_ = cameraToWorldMatrix.MultiplyPoint3x4(new Vector3(0, 0, -1)); camera_rot_ = Quaternion.LookRotation(-cameraToWorldMatrix.GetColumn(2), cameraToWorldMatrix.GetColumn(1)); Matrix4x4 projectionMatrix; photoCaptureFrame.TryGetProjectionMatrix(Camera.main.nearClipPlane, Camera.main.farClipPlane, out projectionMatrix); Matrix4x4 pixelToCameraMatrix = projectionMatrix.inverse; status.GetComponent <TextMesh>().text = "photo captured, processing..."; status.transform.position = camera_pos_; status.transform.rotation = camera_rot_; StartCoroutine(PostToServer(imageBufferList.ToArray(), cameraToWorldMatrix, pixelToCameraMatrix)); } photo_capture_.StopPhotoModeAsync(OnStoppedPhotoMode); }
public void StopCamera() { if (photoCaptureObj != null) { photoCaptureObj.StopPhotoModeAsync(OnStoppedPhotoMode); } //TextManager.Instance.setText(""); }
/// <summary> /// Clean up on destroty /// </summary> void OnDestroy() { m_photoCapture.StopPhotoModeAsync( delegate(UnityEngine.XR.WSA.WebCam.PhotoCapture.PhotoCaptureResult res) { m_photoCapture.Dispose(); m_photoCapture = null; Debug.Log("Photo Mode stopped"); } ); }
//カメラの設定 ここまで。 private void OnCapturedPhotoToMemory(UnityEngine.XR.WSA.WebCam.PhotoCapture.PhotoCaptureResult result, UnityEngine.XR.WSA.WebCam.PhotoCaptureFrame photoCaptureFrame) { if (result.success) { List <byte> imageBufferList = new List <byte>(); // Copy the raw IMFMediaBuffer data into our empty byte list. photoCaptureFrame.CopyRawImageDataIntoBuffer(imageBufferList); DisplayImage(imageBufferList.ToArray()); //画像表示処理呼び出し StartCoroutine(GetVisionDataFromImages(imageBufferList.ToArray())); //API呼び出し } photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode); }