7 Replies Latest reply on Jan 2, 2017 6:19 AM by Intel Corporation

    full sample code for 3DScan in C#

    suho

      hello, I work with realsense

      I want to 3D Scan with SR300 and R200

      I read 'Coding 3D Scanning' in the 'RealSense SDK 2016 R2 Documentation'

      but i don't know what do i have to write in 'ㆍㆍㆍ'

      so i want to get a full sample code for 3D Scan and save mesh file in C# (WPF / FORM)

      help me, send a full sample code !! please

        • 1. Re: full sample code for 3DScan in C#
          KY_JIAO

          this is my code work with unity, I hope useful for you. if you use wpf or form you convert _previewData to bitmap

           

          void Start()
              {
                  Mgt_AppSession.SM = SenseManager.CreateInstance();
                  if (Mgt_AppSession.SM == null)
                  {
                      Mgt_Message.Msg_Error("Sense Manager 创建失败");
                      return;
                  }

                  if (Mgt_AppSession.SM.CaptureManager == null)
                  {
                      Mgt_Message.Msg_Error("Capture Manager 不存在");
                      return;
                  }
                  Mgt_AppSession.SM.CaptureManager.FilterByStreamProfiles(StreamType.STREAM_TYPE_DEPTH, DepthWidth, DepthHeight, FrameRate);
                 
                  Mgt_AppSession.ScanModule = Scan3D.Activate(Mgt_AppSession.SM);

                  if (Mgt_AppSession.ScanModule == null)
                  {
                      Mgt_AppSession.SM.Close();
                      Mgt_AppSession.SM.Dispose();
                      Mgt_Message.Msg_Error("Scan3D 模块激活失败");
                      return;
                  }

                  var initStatus = Mgt_AppSession.SM.Init();
                  if (initStatus < Status.STATUS_NO_ERROR)
                  {
                      Mgt_AppSession.SM.Close();
                      Mgt_AppSession.SM.Dispose();
                      Mgt_Message.Msg("Sense Manager 初始化失败", initStatus);
                      return;
                  }

                  Mgt_AppSession.ScanConfig = new Configuration();
                  Mgt_AppSession.ScanConfig.mode = ScanningMode.VARIABLE;
                  Mgt_AppSession.ScanConfig.maxVertices = 0;
                  Mgt_AppSession.ScanConfig.maxTriangles = 0;
                  var scanConfigStatus = Mgt_AppSession.ScanModule.SetConfiguration(Mgt_AppSession.ScanConfig);
                  if (scanConfigStatus < Status.STATUS_NO_ERROR)
                  {
                      Mgt_AppSession.ScanModule.Dispose();
                      Mgt_AppSession.SM.Close();
                      Mgt_AppSession.SM.Dispose();
                      Mgt_Message.Msg("Scan3D 选项配置失败", scanConfigStatus);
                  }

                  _imgControl = GameObject.Find("RawImage").GetComponent<RawImage>();
                  Mgt_AppSession.MeshFilePath = string.Format("{0}", System.Environment.CurrentDirectory);
                  Mgt_AppSession.IsStreaming = true;
              }

              void Update()
              {
                  if (!Mgt_AppSession.IsStreaming)
                      return;

                  if (Mgt_AppSession.SM.AcquireFrame(true).IsSuccessful())
                  {
                      ImageData _previewData;
                      var previewImage = Mgt_AppSession.ScanModule.PreviewImage;
                      var previewImageStatus = previewImage.AcquireAccess(ImageAccess.ACCESS_READ, PixelFormat.PIXEL_FORMAT_RGB32, out _previewData);
                      if (previewImageStatus == Status.STATUS_NO_ERROR)
                      {
                          var image = _previewData.ToTexture2D(0, previewImage.Info.width, previewImage.Info.height);
                          _imgControl.texture = image;
                          image.Apply();
                          previewImage.ReleaseAccess(_previewData);
                      }
                      else
                      {
                          Mgt_AppSession.IsStreaming = false;
                          Mgt_Message.Msg("图像获取失败", previewImageStatus);
                      }

                      previewImage.Dispose();
                      Mgt_AppSession.SM.ReleaseFrame();
                  }
              }

          1 of 1 people found this helpful
          • 2. Re: full sample code for 3DScan in C#
            suho

            I appreciate your kindness

            but i don't know how do i conver _previewData to bitmap ??

            If you are ok, can you tell me the way?

            Thanks, JY_JIAO

            • 3. Re: full sample code for 3DScan in C#
              jb455

              If you have the SDK installed, open up "RealSense SDK Sample Browser", go to the Common Samples tab, click C# on the left then find 3D Scan and click Sources next to it. You'll have the full source code then.

              • 4. Re: full sample code for 3DScan in C#
                Intel Corporation
                This message was posted on behalf of Intel Corporation
                1 of 1 people found this helpful
                • 5. Re: full sample code for 3DScan in C#
                  Intel Corporation
                  This message was posted on behalf of Intel Corporation

                  Hi Suho,

                  Were the links helpful? Do you still have issues with the code?

                  Please let us know.

                  Have a nice weekend.

                  Regards,
                  -Leonardo

                  1 of 1 people found this helpful
                  • 6. Re: full sample code for 3DScan in C#
                    suho

                    yes, Sorry for late ...

                    Thanks !!!    

                    • 7. Re: full sample code for 3DScan in C#
                      Intel Corporation
                      This message was posted on behalf of Intel Corporation

                      Hi Suho,

                      Awesome! Feel free to contact us if you have issues.

                      Regards,
                      -Leonardo