Esempio n. 1
0
        /**
         * Callback method that is called after the photo has been taken.
         *
         * @param result            the result of the capturing
         * @param photoCaptureFrame the captured frame
         */
        private void OnCapturedPhotoToMemory(MRC.PhotoCapture.PhotoCaptureResult result, MRC.PhotoCaptureFrame photoCaptureFrame)
        {
            if (result.success)
            {
                Matrix4x4 cameraToWorld;
                Matrix4x4 projection;
                if (photoCaptureFrame.TryGetCameraToWorldMatrix(out cameraToWorld) && photoCaptureFrame.TryGetProjectionMatrix(out projection))
                {
                    this.objectRecognition.SetMatrices(cameraToWorld, projection);
                }

                // TODO: flip Mat with cv::flip(oldmat, newmat, flipcode);
                // TODO: is opencv able to work with alpha value?

                // Copy the raw IMFMediaBuffer data into our empty byte list.
                List <byte> imageBufferList = new List <byte>();
                photoCaptureFrame.CopyRawImageDataIntoBuffer(imageBufferList);

                // The HoloLens uses the BGRA32 format. So our stride will be 4 since
                // we have a byte for each rgba channel. The raw image data will also
                // be flipped so we access our pixel data in the reverse order.
                int    oldStride = 4; // BGRA32
                int    newStride = 3; // BGR24
                int    j         = 0;
                byte[] imageData = new byte[this.CameraResolution.width * this.CameraResolution.height * newStride];
                for (int i = 0; i < imageBufferList.Count; i += oldStride)
                {
                    imageData[j + 0] = imageBufferList[i + 0]; // b
                    imageData[j + 1] = imageBufferList[i + 1]; // g
                    imageData[j + 2] = imageBufferList[i + 2]; // r
                    j += newStride;
                }

                // Dispose of the current photoCaptureFrame to avoid AccessViolation Exceptions (Unity Bug)
                photoCaptureFrame.Dispose();

                // OpenCV image type: CV_8UC3 = 16 (8-bit unsigned char with 3 channels)
                this.objectRecognition.AddImage(this.CameraResolution.width, this.CameraResolution.height, CV_8UC3, imageData);
            }
            else
            {
                this.logger.Log("Failed to save photo to memory.");
                this.isProcessing = false;
            }
        }
Esempio n. 2
0
 public IntPtr GetUnsafePointerToBuffer()
 {
     return(PhotoCaptureFrame.GetUnsafePointerToBuffer(this.m_NativePtr));
 }