Items with no label
3335 Discussions

full sample code for 3DScan in C#

SJung11
New Contributor I
2,139 Views

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 Solution
7 Replies
kkeye
Novice
522 Views

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();

 

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();

 

}

 

}
SJung11
New Contributor I
522 Views

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

0 Kudos
jb455
Valued Contributor II
522 Views

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.

0 Kudos
idata
Employee
523 Views

Hi Suho,

 

 

Thanks for reaching out.

 

 

I think that there is a lot of information that can be helpful for you, but practically it is like Jb455 said.

 

 

These are some helpful links:

 

 

https://software.intel.com/sites/default/files/Getting_Started_0.pdf

 

https://software.intel.com/sites/default/files/managed/41/4e/sdkdevguide.pdf

 

https://software.intel.com/en-us/articles/get-started-developing-intel-realsense-sdk-for-windows-10-desktop-apps

 

https://software.intel.com/en-us/articles/using-the-intel-realsense-sdk-to-create-hello-world-project

 

 

Have a nice weekend.

 

 

Regards,

 

-Leonardo
idata
Employee
522 Views

Hi Suho,

 

 

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

 

 

Please let us know.

 

 

Have a nice weekend.

 

 

Regards,

 

-Leonardo
SJung11
New Contributor I
522 Views

yes, Sorry for late ...

Thanks !!!

0 Kudos
idata
Employee
522 Views

Hi Suho,

 

 

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

 

 

Regards,

 

-Leonardo
0 Kudos
Reply