/// <summary> /// Enumerates the resolutions. /// </summary> /// <exception cref="System.Exception">PXCMCapture.Device null</exception> public void EnumerateResolutions() { ColorResolutions = new Dictionary <string, IEnumerable <Tuple <PXCMImage.ImageInfo, PXCMRangeF32> > >(); var desc = new PXCMSession.ImplDesc { group = PXCMSession.ImplGroup.IMPL_GROUP_SENSOR, subgroup = PXCMSession.ImplSubgroup.IMPL_SUBGROUP_VIDEO_CAPTURE }; for (int i = 0; ; i++) { PXCMSession.ImplDesc desc1; if (Session.QueryImpl(desc, i, out desc1) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } PXCMCapture capture; if (Session.CreateImpl(desc1, out capture) < pxcmStatus.PXCM_STATUS_NO_ERROR) { continue; } for (int j = 0; ; j++) { PXCMCapture.DeviceInfo info; if (capture.QueryDeviceInfo(j, out info) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } PXCMCapture.Device device = capture.CreateDevice(j); if (device == null) { throw new Exception("PXCMCapture.Device null"); } var deviceResolutions = new List <Tuple <PXCMImage.ImageInfo, PXCMRangeF32> >(); for (int k = 0; k < device.QueryStreamProfileSetNum(PXCMCapture.StreamType.STREAM_TYPE_COLOR); k++) { PXCMCapture.Device.StreamProfileSet profileSet; device.QueryStreamProfileSet(PXCMCapture.StreamType.STREAM_TYPE_COLOR, k, out profileSet); var currentRes = new Tuple <PXCMImage.ImageInfo, PXCMRangeF32>(profileSet.color.imageInfo, profileSet.color.frameRate); if (SupportedColorResolutions.Contains(new Tuple <int, int>(currentRes.Item1.width, currentRes.Item1.height))) { deviceResolutions.Add(currentRes); } } ColorResolutions.Add(info.name, deviceResolutions); device.Dispose(); } capture.Dispose(); } }
private void ScanForProfiles(int deviceIndex) { PXCMSession.ImplDesc desc = new PXCMSession.ImplDesc(); desc.group = PXCMSession.ImplGroup.IMPL_GROUP_SENSOR; desc.subgroup = PXCMSession.ImplSubgroup.IMPL_SUBGROUP_VIDEO_CAPTURE; desc.iuid = devicesUIDs[deviceIndex]; int current_device_iuid = desc.iuid; desc.cuids[0] = PXCMCapture.CUID; profiles.Clear(); List <string> colorStrings = new List <string>(); List <string> depthStrings = new List <string>(); PXCMCapture capture; PXCMCapture.DeviceInfo dinfo2 = deviceInfo[deviceIndex]; 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(); for (int s = 0; s < PXCMCapture.STREAM_LIMIT; s++) { PXCMCapture.StreamType st = PXCMCapture.StreamTypeFromIndex(s); if (((int)dinfo2.streams & (int)st) != 0) { int num = device.QueryStreamProfileSetNum(st); for (int p = 0; p < num; p++) { if (device.QueryStreamProfileSet(st, p, out profile) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } PXCMCapture.Device.StreamProfile sprofile = profile[st]; string profileText = ProfileToString(sprofile); try { profiles.Add(profileText, sprofile); } catch { } switch (st) { case PXCMCapture.StreamType.STREAM_TYPE_COLOR: colorStrings.Add(profileText); break; case PXCMCapture.StreamType.STREAM_TYPE_DEPTH: depthStrings.Add(profileText); break; } } } } device.Dispose(); } capture.Dispose(); } colorProfiles = new ListParamDesc <string>(colorStrings) { Description = "Color Profiles", ReadableWhen = ParamDesc.ConnectionStates.Connected, }; depthProfiles = new ListParamDesc <string>(depthStrings) { Description = "Depth Profiles", ReadableWhen = ParamDesc.ConnectionStates.Connected, }; }
public void StreamColorDepth(String scanType) /* Stream Color and Depth Synchronously or Asynchronously */ { bool sts = true; PXCM3DScan.Configuration scan_config = new PXCM3DScan.Configuration(); String statusString; /* Create an instance of the PXCSenseManager interface */ PXCMSenseManager pp = PXCMSenseManager.CreateInstance(); if (pp == null) { form.UpdateStatus("Failed to create sense manager"); return; } if (pp.captureManager == null) { form.UpdateStatus("Capture manager does not exist"); return; } if (!form.IsModeLive()) { pp.captureManager.SetFileName(form.GetFileName(), form.IsModeRecord()); } /* Set Input Source */ PXCMCapture.DeviceInfo dinfo2 = form.GetCheckedDevice(); if (form.IsModeLive() || form.IsModeRecord()) { pp.captureManager.FilterByDeviceInfo(dinfo2); } if (form.IsModeRecord()) { // Delay recording frames until the scan starts pp.captureManager.SetPause(true); } else if (!form.IsModeLive()) { // Disable real-time mode if we are playing back a file // to ensure that frames are not skipped. pp.captureManager.SetRealtime(false); } /* Set Color & Depth Resolution */ PXCMCapture.Device.StreamProfile cinfo = form.GetColorConfiguration(); if (cinfo.imageInfo.format != 0) { Single cfps = cinfo.frameRate.max; pp.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, cinfo.imageInfo.width, cinfo.imageInfo.height, cfps); } PXCMCapture.Device.StreamProfile dinfo = form.GetDepthConfiguration(); if (dinfo.imageInfo.format != 0) { Single dfps = dinfo.frameRate.max; pp.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, dinfo.imageInfo.width, dinfo.imageInfo.height, dfps); } /* Initialization */ FPSTimer timer = new FPSTimer(form); if (form.IsModeLive()) { form.UpdateStatus("Initializing..."); } /* Enable the 3D Scan video module */ pxcmStatus result = pp.Enable3DScan(); if (result != pxcmStatus.PXCM_STATUS_NO_ERROR) { pp.Close(); pp.Dispose(); form.UpdateStatus("Enable3DScan() returned " + result); return; } /* Initialize the camera system */ result = pp.Init(); form.UpdateStatus(""); device = pp.captureManager.device; if (result >= pxcmStatus.PXCM_STATUS_NO_ERROR && device != null) { bool bAutoExpAndWBChanged = false; bool bAutoExposureEnabled = true; bool bAutoWhiteBalanceEnabled = true; /* Setup the scanning configuration */ if (scanType == "Object") { scan_config.mode = PXCM3DScan.ScanningMode.OBJECT_ON_PLANAR_SURFACE_DETECTION; } else if (scanType == "Face") { scan_config.mode = PXCM3DScan.ScanningMode.FACE; } else if (scanType == "Body") { scan_config.mode = PXCM3DScan.ScanningMode.BODY; } else if (scanType == "Head") { scan_config.mode = PXCM3DScan.ScanningMode.HEAD; } else if (scanType == "Full") { scan_config.mode = PXCM3DScan.ScanningMode.VARIABLE; } /* Select the Targeting Options */ scan_config.options = PXCM3DScan.ReconstructionOption.NONE; if (form.isSolidificationSelected()) { scan_config.options |= (PXCM3DScan.ReconstructionOption.SOLIDIFICATION); } if (form.isTextureSelected()) { scan_config.options |= (PXCM3DScan.ReconstructionOption.TEXTURE); } if (form.isLandmarksSelected()) { scan_config.options |= (PXCM3DScan.ReconstructionOption.LANDMARKS); } //scan_config.useMarker = form.isUseMarkerChecked(); scan_config.flopPreviewImage = form.isFlopPreviewImageSelected(); /* Try to initialize the scanning system */ PXCM3DScan scan = pp.Query3DScan(); sts = false; if (scan == null) { form.UpdateStatus("3DScan module not found."); } else { result = scan.SetConfiguration(scan_config); if (result < pxcmStatus.PXCM_STATUS_NO_ERROR) { scan.Dispose(); // Show the configuration related error code switch (result) { case pxcmStatus.PXCM_STATUS_FEATURE_UNSUPPORTED: form.UpdateStatus("Configuration not supported."); break; case pxcmStatus.PXCM_STATUS_ITEM_UNAVAILABLE: form.UpdateStatus("Face module not found."); break; default: form.UpdateStatus("SetConfiguration returned an error."); break; } } else { sts = true; } } // Conditionally finish the initialization and enter the main loop if (sts == true) { // Subscribe to recieve range and tracking alerts scan.Subscribe(OnAlert); Projection projection = new Projection( pp.session, device, dinfo.imageInfo); Boolean bScanning = false; Boolean bPlaybackStarted = false; form.Invoke(new Action(() => form.SetButtonState(sample3dscan.cs.MainForm.ButtonState.Ce_SSd))); while (form.reconstruct_requested || !form.GetStopState()) { if (form.GetScanRequested()) /* one time latch */ { form.Invoke(new Action(() => form.SetScanRequested(false))); // Delay recording frames until the start of the scan is requested if (form.IsModeRecord()) { pp.captureManager.SetPause(false); } // If the max tri/vert controls are enabled, // use the set values. Otherwise, disabled decimation // by setting the values to zero. /* * scan_config.maxTriangles = form.getMaxTrianglesEnabledChecked() * ? form.getMaxTriangles() : 0; * scan_config.maxVertices = form.getMaxVerticesEnabledChecked() * ? form.getMaxVertices() : 0; */ // Request that the scan starts as soon as possible scan_config.startScan = true; scan.SetConfiguration(scan_config); /* Update the status bar to help users understand what the detector is looking for */ if (form.IsModeLive()) { if (scan_config.mode == PXCM3DScan.ScanningMode.OBJECT_ON_PLANAR_SURFACE_DETECTION) { form.UpdateStatus("Object not detected. Place object on flat surface in center of view."); } } } else if (form.reconstruct_requested) { sts = SaveMesh(scan); } /* Get preview image from the 3D Scan video module */ if (!form.GetStopState()) { /* Wait until a frame is ready: Synchronized or Asynchronous */ if (pp.AcquireFrame() < pxcmStatus.PXCM_STATUS_NO_ERROR) { projection.Dispose(); if (!form.IsModeLive()) { form.Invoke(new Action(() => form.EndScan())); sts = SaveMesh(scan); } break; } /* Get preview image from the 3D Scan video module */ PXCMImage preview_image = scan.AcquirePreviewImage(); pp.ReleaseFrame(); /* Display Image and Status */ if (preview_image != null) { form.SetBitmap(preview_image); if (scan.IsScanning()) { statusString = "Scanning"; timer.Tick(statusString + " "); if (bScanning == false) // Lazy initializer { bScanning = true; // One way latch // Once the scanning process starts, we want to enable the Reconstruct button form.Invoke(new Action(() => form.SetButtonState(sample3dscan.cs.MainForm.ButtonState.Ce_ESe))); // Object, head and body scanning with a rear facing camera involves walking // around the target, which effectivly exposes the camera to the full // environment, similar to a panorama. To avoid undesirable color // inconsistencies (realted to the response of the auto-exposure/wb changes), // it usually works best to disable them. // Note that these property changes are restored (below). if (device.deviceInfo.orientation == PXCMCapture.DeviceOrientation.DEVICE_ORIENTATION_REAR_FACING && scan_config.mode != PXCM3DScan.ScanningMode.FACE && form.IsModeLive()) { bAutoExpAndWBChanged = true; bAutoExposureEnabled = device.QueryColorAutoExposure(); device.SetColorAutoExposure(false); bAutoWhiteBalanceEnabled = device.QueryColorAutoWhiteBalance(); device.SetColorAutoWhiteBalance(false); } } } else { if (!form.IsModeLive() && !form.IsModeRecord()) // In playback mode, automatically request the scan { if (bPlaybackStarted == false) // Lazy initializer { bPlaybackStarted = true; // One way latch form.scan_requested = true; form.Invoke(new Action(() => form.StartScanning(false))); form.Invoke(new Action(() => form.SetButtonState(sample3dscan.cs.MainForm.ButtonState.Ce_ESe))); } } else { if (!form.GetStopState()) { if (isScanReady(form.landmarksChecked())) { form.Invoke(new Action(() => form.EnableReconstruction(true))); } else { form.Invoke(new Action(() => form.EnableReconstruction(false))); } } } } preview_image.Dispose(); } } } projection.Dispose(); scan.Dispose(); } // Restore the default camera properties if (bAutoExpAndWBChanged) { device.SetColorAutoExposure(bAutoExposureEnabled); device.SetColorAutoWhiteBalance(bAutoWhiteBalanceEnabled); } device.Dispose(); device = null; } else { try { form.UpdateStatus(result + ""); } catch { } sts = false; } if (sts) { try { form.UpdateStatus(""); } catch { } } pp.Close(); pp.Dispose(); try { form.Invoke(new Action(() => form.ResetStop())); } catch { } }
private void PopulateDepthMenus(ToolStripMenuItem device_item) { 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; DepthMenu.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; } 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();; PXCMCapture.Device.StreamProfile color_profile = GetColorConfiguration(); if (((int)dinfo2.streams & (int)PXCMCapture.StreamType.STREAM_TYPE_DEPTH) != 0) { for (int p = 0; ; p++) { if (device.QueryStreamProfileSet(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, p, out profile) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } PXCMCapture.Device.StreamProfile sprofile = profile[PXCMCapture.StreamType.STREAM_TYPE_DEPTH]; bool bFound = false; int i = 0; PXCMVideoModule.DataDesc inputs; while ((m.QueryCaptureProfile(i++, out inputs) >= pxcmStatus.PXCM_STATUS_NO_ERROR)) { if ((sprofile.imageInfo.height == inputs.streams.depth.sizeMax.height) && (sprofile.imageInfo.width == inputs.streams.depth.sizeMax.width) && (sprofile.frameRate.max == inputs.streams.depth.frameRate.max) && (color_profile.frameRate.max == inputs.streams.depth.frameRate.max)) { bFound = true; } } if (bFound) { if (sprofile.options != (PXCMCapture.Device.StreamOption) 0x20000) // do not show Depth Confidence { ToolStripMenuItem sm1 = new ToolStripMenuItem(ProfileToString(sprofile), null, new EventHandler(Depth_Item_Click)); profiles[sm1] = sprofile; DepthMenu.DropDownItems.Add(sm1); } } } } device.Dispose(); } capture.Dispose(); } m.Dispose(); pp.Dispose(); if (DepthMenu.DropDownItems.Count > 0) { (DepthMenu.DropDownItems[DepthMenu.DropDownItems.Count - 1] as ToolStripMenuItem).Checked = true; } }
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; } }
private void CheckSelection() { if (!ModePlayback.Checked) { PXCMCapture.Device.StreamProfileSet allProfile = new PXCMCapture.Device.StreamProfileSet(); for (int s = 0; s < PXCMCapture.STREAM_LIMIT; s++) { PXCMCapture.StreamType st = PXCMCapture.StreamTypeFromIndex(s); allProfile[st] = GetStreamConfiguration(st); } PXCMSession.ImplDesc desc = new PXCMSession.ImplDesc(); desc.group = PXCMSession.ImplGroup.IMPL_GROUP_SENSOR; desc.subgroup = PXCMSession.ImplSubgroup.IMPL_SUBGROUP_VIDEO_CAPTURE; desc.iuid = current_device_iuid; desc.cuids[0] = PXCMCapture.CUID; PXCMCapture capture; PXCMCapture.DeviceInfo dinfo2 = GetCheckedDevice(); 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(); PXCMCapture.Device.StreamProfileSet test = new PXCMCapture.Device.StreamProfileSet(); /* Loop over all stream types and profiles and enable only compatible in menu */ for (int s = 0; s < PXCMCapture.STREAM_LIMIT; s++) { PXCMCapture.StreamType st = PXCMCapture.StreamTypeFromIndex(s); if (((int)dinfo2.streams & (int)st) != 0) { for (int s1 = 0; s1 < PXCMCapture.STREAM_LIMIT; s1++) { test[PXCMCapture.StreamTypeFromIndex(s1)] = allProfile[PXCMCapture.StreamTypeFromIndex(s1)]; } int num = device.QueryStreamProfileSetNum(st); for (int p = 0; p < num; p++) { if (device.QueryStreamProfileSet(st, p, out profile) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } PXCMCapture.Device.StreamProfile sprofile = profile[st]; ToolStripMenuItem sm1 = GetMenuItem(st, sprofile); if (sm1 != null) { test[st] = sprofile; sm1.Enabled = device.IsStreamProfileSetValid(test); } } } } Start.Enabled = device.IsStreamProfileSetValid(allProfile); device.Dispose(); } capture.Dispose(); } } int sumEnabled = 0; for (int s = 0; s < PXCMCapture.STREAM_LIMIT; s++) { if (streamButtons[s] != null && streamNone[s] != null) { streamButtons[s].Enabled = !streamNone[s].Checked; sumEnabled += streamButtons[s].Enabled?1:0; } } PIP.Enabled = (sumEnabled >= 2); Mirror.Enabled = !ModePlayback.Checked; PXCMCapture.StreamType selectedStream = GetSelectedStream(); if (selectedStream != PXCMCapture.StreamType.STREAM_TYPE_ANY && !streamButtons[PXCMCapture.StreamTypeToIndex(selectedStream)].Enabled) { PXCMCapture.StreamType st = GetUnselectedStream(); streamButtons[PXCMCapture.StreamTypeToIndex(st)].Checked = true; streaming.ColorPanel = st; } //if (PIP.Enabled && streaming.DepthPanel == PXCMCapture.StreamType.STREAM_TYPE_ANY) //{ // streaming.DepthPanel = GetUnselectedStream(); //} }
private void PopulateColorDepthMenus(ToolStripMenuItem device_item) { 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]; current_device_iuid = desc.iuid; desc.cuids[0] = PXCMCapture.CUID; profiles.Clear(); foreach (ToolStripMenuItem menu in streamMenus) { if (menu != null) { menu.DropDownItems.Clear(); } } PXCMCapture capture; PXCMCapture.DeviceInfo dinfo2 = GetCheckedDevice(); 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(); for (int s = 0; s < PXCMCapture.STREAM_LIMIT; s++) { PXCMCapture.StreamType st = PXCMCapture.StreamTypeFromIndex(s); if (((int)dinfo2.streams & (int)st) != 0 && streamMenus[s] != null) { streamMenus[s].Visible = true; streamButtons[s].Visible = true; streamPanels[s].Visible = true; int num = device.QueryStreamProfileSetNum(st); for (int p = 0; p < num; p++) { if (device.QueryStreamProfileSet(st, p, out profile) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } PXCMCapture.Device.StreamProfile sprofile = profile[st]; ToolStripMenuItem sm1 = new ToolStripMenuItem(ProfileToString(sprofile), null, new EventHandler(Stream_Item_Click)); profiles[sm1] = sprofile; streamMenus[s].DropDownItems.Add(sm1); if (sm1.Text.Contains(default_config[s])) { default_menu[s] = p; Debug.WriteLine(s + " : " + p + " : " + ProfileToString(sprofile)); } } } else if (((int)dinfo2.streams & (int)st) == 0 && streamMenus[s] != null) { streamMenus[s].Visible = false; streamButtons[s].Visible = false; streamPanels[s].Visible = false; } } device.Dispose(); } capture.Dispose(); } for (int i = 0; i < PXCMCapture.STREAM_LIMIT; i++) { ToolStripMenuItem menu = streamMenus[i]; if (menu != null) { streamNone[i] = new ToolStripMenuItem("None", null, new EventHandler(Stream_Item_Click)); profiles[streamNone[i]] = new PXCMCapture.Device.StreamProfile(); menu.DropDownItems.Add(streamNone[i]); if (default_menu[i] != 0) { (menu.DropDownItems[default_menu[i]] as ToolStripMenuItem).Checked = true; } else { streamNone[i].Checked = true; } } } CheckSelection(); }
/// <summary> /// 取得所有裝置支援的顏色與解析度 /// </summary> private PXCMCapture.Device.StreamProfileSet[][] GetDeviceStreamProfiles() { var result = new List <PXCMCapture.Device.StreamProfileSet[]>(); var desc = new PXCMSession.ImplDesc { group = PXCMSession.ImplGroup.IMPL_GROUP_SENSOR, subgroup = PXCMSession.ImplSubgroup.IMPL_SUBGROUP_VIDEO_CAPTURE }; for (int i = 0; ; i++) { PXCMSession.ImplDesc desc1; if (RealSenseObjects.Session.QueryImpl(desc, i, out desc1) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } PXCMCapture capture; if (RealSenseObjects.Session.CreateImpl(desc1, out capture) < pxcmStatus.PXCM_STATUS_NO_ERROR) { continue; } for (int j = 0; ; j++) { PXCMCapture.DeviceInfo info; if (capture.QueryDeviceInfo(j, out info) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } PXCMCapture.Device device = capture.CreateDevice(j); if (device == null) { throw new Exception("PXCMCapture.Device null"); } var deviceResolutions = new List <PXCMCapture.Device.StreamProfileSet>(); for (int k = 0; k < device.QueryStreamProfileSetNum(PXCMCapture.StreamType.STREAM_TYPE_COLOR); k++) { PXCMCapture.Device.StreamProfileSet profileSet; device.QueryStreamProfileSet(PXCMCapture.StreamType.STREAM_TYPE_COLOR, k, out profileSet); PXCMCapture.DeviceInfo dinfo; device.QueryDeviceInfo(out dinfo); if (IsProfileSupported(profileSet, dinfo)) { continue; } deviceResolutions.Add(profileSet); } try { result.Add(deviceResolutions.ToArray()); } catch (Exception e) { } device.Dispose(); } capture.Dispose(); } return(result.ToArray()); }