- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone,
I have a question as I use unity to do 3D scan.Unity Editor would crash with no error.
The version of Unity is Unity 5.2.3f1
The OS version is windows 10.
The version of RS SDK is 2016 R1.
Can anyone help me to solve this problem?
The source code to do the 3d scan. is in the below.
using UnityEngine; using System.Collections; public class ScanModule : MonoBehaviour{ static PXCMCapture.Device device; private PXCMSenseManager psm; private pxcmStatus sts; //Check error status private PXCM3DScan.Configuration scan_config = new PXCM3DScan.Configuration (); private PXCM3DScan scan; /*3D Scan Preview Image*/ private Texture2D scanTexture2D; public GameObject scanPlane; private bool scan_complete = false; public void Init(){ /* Create an instance of the PXCSenseManager interface */ psm = PXCMSenseManager.CreateInstance(); if (psm == null){ Debug.LogError("PXCMSenseManager Initialization Failed"); return; } /* Set Color & Depth Resolution */ psm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1920, 1080, 30); psm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480, 30); /* Enable the 3D Scan video module */ pxcmStatus result = psm.Enable3DScan(); if (result != pxcmStatus.PXCM_STATUS_NO_ERROR) { Debug.LogError("Enable 3d Scan Error : " + result); psm.Close(); psm.Dispose(); return; } /* Initialize the camera system */ sts = psm.Init(); device = psm.captureManager.device; if (result >= pxcmStatus.PXCM_STATUS_NO_ERROR && device != null) { device.SetColorAutoExposure(true); device.SetColorAutoWhiteBalance(true); /* Try to initialize the scanning system */ scan = psm.Query3DScan(); if ( scan == null ) Debug.LogError("3DScan module not found."); else{ //result = scan.SetConfiguration(scan_config); if (result < pxcmStatus.PXCM_STATUS_NO_ERROR) { Debug.LogError ("PXCMSenseManager.Init Pass:" + result); scan.Dispose(); return; } } /* Setup the scanning configuration */ scan_config.startScan = true; scan_config.mode = PXCM3DScan.ScanningMode.VARIABLE; scan_config.options = (PXCM3DScan.ReconstructionOption.NONE); scan_config.options = scan_config.options | (PXCM3DScan.ReconstructionOption.TEXTURE); result = scan.SetConfiguration(scan_config); if (result < pxcmStatus.PXCM_STATUS_NO_ERROR) { Debug.LogError ("PXCMSenseManager.Init Pass:" + result); scan.Dispose(); return; } } else { Debug.LogError ("PXCMSenseManager.Init Failed:" + sts); OnDisable (); return; } } void setConfigure(){ /* Setup the scanning configuration */ scan_config.startScan = true; scan_config.mode = PXCM3DScan.ScanningMode.VARIABLE; scan_config.options = (PXCM3DScan.ReconstructionOption.NONE); scan_config.options = scan_config.options | (PXCM3DScan.ReconstructionOption.TEXTURE); pxcmStatus result = scan.SetConfiguration(scan_config); if (result < pxcmStatus.PXCM_STATUS_NO_ERROR) { Debug.LogError ("PXCMSenseManager.Init Pass:" + result); scan.Dispose(); return; } } void ScanUpdate(){ /* Get preview image from the 3D Scan video module */ PXCMImage preview_image = scan.AcquirePreviewImage(); psm.ReleaseFrame(); /* Display Image and Status */ /*Retrieve and render the individual color and depth images */ if (preview_image != null) { if(!scan_complete) { if (scanTexture2D == null) { /* If not allocated, allocate a Texture2D */ scanTexture2D = new Texture2D (preview_image.info.width, preview_image.info.height, TextureFormat.ARGB32, false); /* Associate the Texture2D with a gameObject */ scanPlane.GetComponent<Renderer>().material.mainTexture = scanTexture2D; } /* Retrieve the image data in Texture2D */ PXCMImage.ImageData scanImageData; preview_image.AcquireAccess (PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32, out scanImageData); scanImageData.ToTexture2D (0, scanTexture2D); preview_image.ReleaseAccess (scanImageData); /* Apply the texture to the GameObject to display on */ scanTexture2D.Apply (); preview_image.Dispose (); } else scan.Reconstruct(PXCM3DScan.FileFormat.OBJ,SceneManager.m_root+"ScanMe\\ScanFace.obj"); } else Debug.LogError ("preview_image is null!"); } public void OnGUI(){ if (Input.GetKeyUp (KeyCode.A)) setConfigure (); if (Input.GetKeyUp (KeyCode.S)) { scan_complete = true; Debug.Log("scan_complete : " + scan_complete); } } public void OnDisable(){ if (scan != null) { scan.Dispose(); scan = null; } if(psm!=null) { psm.Close(); psm.Dispose(); psm = null; } } void Start (){ Init (); } void Update(){ ScanUpdate (); } }
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Adapt your resolution, something like COLOR: 960,540 60fps & DEPTH 640,480 60fps.
- senseManager is calling releaseFrame, but never acquireFrame?
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page