public static void CopyToByteArray(this PXCMImage image, byte[] data, bool for_preview = false)
        {
            PXCMImage.ImageData   cdata;
            PXCMImage.PixelFormat pixelFormat = PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32;

            if (!for_preview && (image.streamType == PXCMCapture.StreamType.STREAM_TYPE_DEPTH))
            {
                pixelFormat = PXCMImage.PixelFormat.PIXEL_FORMAT_DEPTH;
            }
            else if (image.streamType == PXCMCapture.StreamType.STREAM_TYPE_LEFT || image.streamType == PXCMCapture.StreamType.STREAM_TYPE_RIGHT)
            {
                pixelFormat = PXCMImage.PixelFormat.PIXEL_FORMAT_DEPTH;
            }


            pxcmStatus status = image.AcquireAccess(PXCMImage.Access.ACCESS_READ, pixelFormat, out cdata);

            if (status != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                throw new InvalidOperationException("AcquireAccess failed");
            }
            //cdata.ToByteArray(0, data);
            //Pitches is the real stride width the sensor returns. it's 640 for the current resolution
            byte[] rawData = cdata.ToByteArray(0, cdata.pitches[0] * image.info.height);

            Buffer.BlockCopy(rawData, 0, data, 0, rawData.Length);

            image.ReleaseAccess(cdata);
        }
Example #2
0
        public void PopulateColorResolutionMenu(string deviceName)
        {
            bool foundDefaultResolution = false;
            var  sm = new ToolStripMenuItem("Color");

            foreach (var resolution in ColorResolutions[deviceName])
            {
                var resText = PixelFormat2String(resolution.Item1.format) + " " + resolution.Item1.width + "x"
                              + resolution.Item1.height + " " + resolution.Item2.max + " fps";
                var sm1 = new ToolStripMenuItem(resText, null);
                var selectedResolution = resolution;
                sm1.Click += (sender, eventArgs) =>
                {
                    m_selectedColorResolution = selectedResolution;
                    ColorResolution_Item_Click(sender);
                };

                sm.DropDownItems.Add(sm1);

                int width  = selectedResolution.Item1.width;
                int height = selectedResolution.Item1.height;
                PXCMImage.PixelFormat format = selectedResolution.Item1.format;
                float fps = selectedResolution.Item2.min;

                if (DefaultCameraConfig.IsDefaultDeviceConfig(deviceName, width, height, format, fps))
                {
                    foundDefaultResolution = true;
                    sm1.Checked            = true;
                    sm1.PerformClick();
                }
            }

            if (!foundDefaultResolution && sm.DropDownItems.Count > 0)
            {
                ((ToolStripMenuItem)sm.DropDownItems[0]).Checked = true;
                ((ToolStripMenuItem)sm.DropDownItems[0]).PerformClick();
            }

            try
            {
                MainMenu.Items.RemoveAt(1);
            }
            catch (NotSupportedException)
            {
                sm.Dispose();
                throw;
            }
            MainMenu.Items.Insert(1, sm);
        }
Example #3
0
        /*
         * Colorメニュー関連
         * いったんスルー
         */
        private static string PixelFormat2String(PXCMImage.PixelFormat format)
        {
            switch (format)
            {
            case PXCMImage.PixelFormat.PIXEL_FORMAT_YUY2:
                return("YUY2");

            case PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32:
                return("RGB32");

            case PXCMImage.PixelFormat.PIXEL_FORMAT_RGB24:
                return("RGB24");
            }
            return("NA");
        }
Example #4
0
        /// <summary>
        /// Gets the raw frame.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <returns>System.Byte[].</returns>
        public byte[] GetRawFrame(object image)
        {
            const PXCMImage.PixelFormat format = PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32;

            var frame = image as PXCMImage;

            if (frame == null)
            {
                throw new ResearchException("Frame type is unexpected.");
            }

            PXCMImage.ImageData data;
            frame.AcquireAccess(PXCMImage.Access.ACCESS_READ, format, out data);
            byte[] bytes = data.ToByteArray(0, StreamSetting.Width * StreamSetting.Height * 4);
            frame.ReleaseAccess(data);
            return(bytes);
        }
Example #5
0
            public static bool IsDefaultDeviceConfig(string deviceName, int width, int height, PXCMImage.PixelFormat format, float fps)
            {
                if (deviceName.Contains("R200"))
                {
                    return(width == DefaultDs4Width && height == DefaultDs4Height && format == DefaultDs4PixelFormat && fps == DefaultDs4Fps);
                }

                if (deviceName.Contains("F200") || deviceName.Contains("SR300"))
                {
                    return(width == DefaultIvcamWidth && height == DefaultIvcamHeight && format == DefaultIvcamPixelFormat && fps == DefaultIvcamFps);
                }

                return(false);
            }
Example #6
0
 public static string ToString(this PXCMImage.PixelFormat format)
 {
     return(PXCMImage.PixelFormatToString(format));
 }
Example #7
0
        private void PopulateColorMenus(ToolStripMenuItem device_item)
        {
            OperatingSystem os_version = Environment.OSVersion;

            PXCMSession.ImplDesc desc = new PXCMSession.ImplDesc();
            desc.group    = PXCMSession.ImplGroup.IMPL_GROUP_SENSOR;
            desc.subgroup = PXCMSession.ImplSubgroup.IMPL_SUBGROUP_VIDEO_CAPTURE;
            desc.iuid     = devices_iuid[device_item];
            desc.cuids[0] = PXCMCapture.CUID;

            profiles.Clear();
            ColorMenu.DropDownItems.Clear();
            PXCMCapture capture;

            PXCMCapture.DeviceInfo dinfo2 = GetCheckedDevice();

            PXCMSenseManager pp = session.CreateSenseManager();

            if (pp == null)
            {
                return;
            }
            if (pp.Enable3DScan() < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                return;
            }
            PXCM3DScan s = pp.Query3DScan();

            if (s == null)
            {
                return;
            }
            PXCMVideoModule m = s.QueryInstance <PXCMVideoModule>();

            if (m == null)
            {
                return;
            }

            int count = 0;

            if (session.CreateImpl <PXCMCapture>(desc, out capture) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                PXCMCapture.Device device = capture.CreateDevice(dinfo2.didx);
                if (device != null)
                {
                    PXCMCapture.Device.StreamProfileSet profile = new PXCMCapture.Device.StreamProfileSet();;
                    if (dinfo2.streams.HasFlag(PXCMCapture.StreamType.STREAM_TYPE_COLOR))
                    {
                        for (int p = 0; ; p++)
                        {
                            if (device.QueryStreamProfileSet(PXCMCapture.StreamType.STREAM_TYPE_COLOR, p, out profile) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                            {
                                break;
                            }
                            PXCMCapture.Device.StreamProfile sprofile = profile[PXCMCapture.StreamType.STREAM_TYPE_COLOR];

                            // Only populate profiles which are supported by the module
                            bool bFound = false;
                            int  i      = 0;
                            PXCMVideoModule.DataDesc inputs;
                            PXCMImage.PixelFormat    format = PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32;
                            if (dinfo2.orientation != PXCMCapture.DeviceOrientation.DEVICE_ORIENTATION_REAR_FACING)
                            {
                                format = PXCMImage.PixelFormat.PIXEL_FORMAT_RGB24;
                            }
                            while ((m.QueryCaptureProfile(i++, out inputs) >= pxcmStatus.PXCM_STATUS_NO_ERROR))
                            {
                                if ((sprofile.imageInfo.height == inputs.streams.color.sizeMax.height) &&
                                    (sprofile.imageInfo.width == inputs.streams.color.sizeMax.width) &&
                                    (sprofile.frameRate.max == inputs.streams.color.frameRate.max) &&
                                    (sprofile.imageInfo.format == format) &&
                                    (0 == (sprofile.options & PXCMCapture.Device.StreamOption.STREAM_OPTION_UNRECTIFIED)))
                                {
                                    bFound = true;
                                    if (dinfo2.orientation != PXCMCapture.DeviceOrientation.DEVICE_ORIENTATION_REAR_FACING)
                                    {   // Hide rear facing resolutions when the front facing camera is connected...
                                        if (sprofile.imageInfo.width == 640)
                                        {
                                            bFound = false;
                                        }
                                    }
                                    // On Windows 7, filter non-functional 30 fps modes
                                    if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1)
                                    {
                                        if (sprofile.frameRate.max == 30)
                                        {
                                            bFound = false;
                                        }
                                    }
                                }
                            }
                            if (bFound)
                            {
                                ToolStripMenuItem sm1 = new ToolStripMenuItem(ProfileToString(sprofile), null, new EventHandler(Color_Item_Click));
                                profiles[sm1] = sprofile;
                                ColorMenu.DropDownItems.Add(sm1);
                                count++;
                            }
                        }
                    }
                    device.Dispose();
                }
                capture.Dispose();
            }
            m.Dispose();
            pp.Dispose();
            if (count > 0)
            {
                (ColorMenu.DropDownItems[ColorMenu.DropDownItems.Count - 1] as ToolStripMenuItem).Checked = true;
            }
        }