Created
May 4, 2017 10:18
-
-
Save yty/d2274ec32311393396170231794b7e95 to your computer and use it in GitHub Desktop.
testExternalImage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class testExternalImage : MonoBehaviour { | |
private PXCMSenseManager psm; //SenseManager Instance | |
private pxcmStatus sts; //Check error status | |
private PXCMFaceModule facemodule; //FaceModule Instance | |
private PXCMVideoModule videomodule; | |
private PXCMSession session; | |
public Texture tex; //external JPG image | |
public PXCMImage image; | |
public PXCMCapture.Sample images; | |
public PXCMImage.ImageInfo info; | |
void Start () { | |
psm = PXCMSenseManager.CreateInstance(); | |
if (psm == null) | |
{ | |
Debug.LogError("SenseManager Initialization Failed"); | |
return; | |
} | |
session = psm.QuerySession(); | |
if (session == null) | |
{ | |
Debug.LogError("PXCSenseManager.QuerySession"); | |
} | |
sts = psm.EnableFace(); | |
if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR) | |
{ | |
Debug.LogError("PXCSenseManager.EnableFace: " + sts); | |
} | |
facemodule = psm.QueryFace(); | |
if (facemodule == null) | |
{ | |
Debug.LogError("PXCSenseManager.QueryFace"); | |
} | |
videomodule = facemodule.QueryInstance<PXCMVideoModule>(); | |
if (videomodule == null) | |
{ | |
Debug.LogError("PXCSenseManager.videomodule"); | |
} | |
PXCMFaceConfiguration config = facemodule.CreateActiveConfiguration(); | |
config.SetTrackingMode(PXCMFaceConfiguration.TrackingModeType.FACE_MODE_COLOR);// 2d tracking mode. | |
config.detection.isEnabled = true; | |
config.landmarks.isEnabled = true; | |
config.pose.isEnabled = true; | |
config.ApplyChanges(); | |
config.Dispose(); | |
for (int i = 0; ; i++) | |
{ | |
PXCMVideoModule.DataDesc inputs = new PXCMVideoModule.DataDesc(); | |
sts = videomodule.QueryCaptureProfile(i, out inputs); | |
if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) | |
{ | |
break; | |
} | |
if (inputs.deviceInfo.model == PXCMCapture.DeviceModel.DEVICE_MODEL_SR300) | |
{ | |
sts = videomodule.SetCaptureProfile(inputs); | |
if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) | |
{ | |
Debug.Log(" video module error"); | |
} | |
} | |
} | |
info.format = PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32; | |
info.width = tex.width; | |
info.height = tex.height; | |
PXCMImage.ImageData data = new PXCMImage.ImageData(); //==========================ERROR | |
data.format = PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32; | |
data.planes[0] = tex.GetNativeTexturePtr(); | |
data.pitches[0] = info.width * 4; | |
image = session.CreateImage(info, data); | |
images.color = session.CreateImage(info, data); | |
sts = psm.Init(); | |
if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR) | |
{ | |
Debug.LogError("PXCMSenseManager.Init Failed"); | |
} | |
} | |
// Update is called once per frame | |
void Update () { | |
// | |
if (images != null) | |
{ | |
Debug.Log("udpate"); | |
PXCMSyncPoint sp; | |
sts = videomodule.ProcessImageAsync(images, out sp); //============Error | |
if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) | |
{ | |
Debug.Log("error"); | |
} | |
sp.Synchronize(); | |
images.ReleaseImages(); | |
} | |
} | |
void OnDisable() | |
{ | |
facemodule.Dispose(); | |
if (psm == null) return; | |
psm.Dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I refer to the information
https://software.intel.com/en-us/forums/realsense/topic/606341#comment-1857656