We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Thank you so much for sticking with me on this one guys. I have tidied up the code below.
Line 82 shows the commented out potentially obsolete method of converting PXCImage data to PImage (unless anyone can see me doing something incorrect? The SDK has a different method at this link)
Lines 58 to 78 show the next approach I think may work if the PImage approach does not. This is converting the PXCImage to a float array. Original SDK doc is this...
The fact I can see my Image Data streaming to my "dData" Print Out surely confirms there is a way to get this data as an image on the canvas.
Again, thank you for your your thoughts. I am going through a whole bunch of trial and error trying to sort this out, especially trying to sort the Java syntax from the SDK and integrate it into the Processing sketch :)
import intel.rssdk.*;
import java.lang.System.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.*;
PXCMSenseManager sm = null;
pxcmStatus sts = pxcmStatus.PXCM_STATUS_NO_ERROR;
PImage imgDepth;
void setup() {
size(640, 480, P2D);
//Create PXCMsession for Realsense Camera
PXCMSession session = PXCMSession.CreateInstance();
if (session == null) {
System.out.print("Failed to create a session instance\n");
System.exit(3);
}
// Create SenseManager for Realsense Camera
sm = session.CreateSenseManager();
if (sm == null) {
print("Failed to create a SenseManager instance\n");
return;
}
// Specify the camera stream. Depth 320*240 30fps
sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH,320,240,30);
PXCMCaptureManager captureMgr = sm.QueryCaptureManager();
captureMgr.FilterByDeviceInfo("RealSense", null, 0);
sts = sm.Init();
if (sts.compareTo(pxcmStatus.PXCM_STATUS_NO_ERROR)>=0) {
} else {
print("Failed to initial a RSSDK pipeline instance.\n");
return;
}
imgDepth = createImage(640, 480, RGB);
}
void draw() {
sm.AcquireFrame(true);
PXCMCapture.Sample sample=sm.QuerySample();
//create PXCM Image Data, as dData
PXCMImage.ImageData dData = new PXCMImage.ImageData(); {
sample.depth.AcquireAccess(PXCMImage.Access.ACCESS_READ,PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32, dData);
println(dData);
//Namespace Hierarchy
//PXCMImage.ImageData.ToFloatArray
//Syntax#Java
//float[] ToFloatArray(int plane, int size);
//float[] ToFloatArray(int plane, float[] dest);
//Parameters
//plane - The data plane index
//size - The data array size
//dest - The application-allocated destination array.
//Description - The ToFloatArray function retrieves a copy of the image plane as a float array.
//Return Status - The float array instance, or null if there is any error.
//imgDepth = dData.ToPImage(0, imgDepth); - This code from existing example seems obsolote. need to get dData to PImage, by float array?
sample.depth.ReleaseAccess(dData);
image(imgDepth, 0,0);
}
}
// Close the Sensemanager is no more data
void dispose() {
if (sm==null) return;
sm.close();
sm=null;
}
Sorry, no other ideas -- I'm not familiar with rssdk and don't have a Realsense on hand. Perhaps check past discussions of Processing+rssdk or of that error message if you have not already:
Thank you for the response Jeremy. I have tried that approach also without any luck.
There actually is another reference in the RSSDK called PXCMImage.ImageData.ToPImage
which has
PImage ToPImage(int index, PImage dest); as its syntaxes.
Though I cant seem to get this to link to a PImage class in Processing.
Any other thoughts? Thanks :)
@matt92au -- regarding your error:
"The function ToPImage(int,PImage) does not exist"
..are you sure the method shouldn't be "toPImage()" -- not "ToPImage()"? It is very unusual for a method to begin uppercase in Java.
You should be able to search the library intel.rssdk.*
and find that method if it exists. It is also possible that you are passing the wrong arguments or in the wrong order -- you are passing an int and a PImage, but should be passing a PImage and an int (or something else).
Your debugging that prints "intel.rssdk.PXCMImage@7E89278e" is telling you that you are printing a depth object ("PXCMImage") and the memory address of that object ("7E89278e").
Hey everyone. I am certainly a bit over my head on this one, but chipping away bit by bit. I hope someone might have some excellent insight to put my head in the right direction :)
I am trying to obtain depth data from an Intel Realsense r200 camera. Below is my code (with some errors to show where I am falling down..)
import intel.rssdk.*;
//import java.lang.System.*;
//import java.util.*;
//import javax.swing.*;
//import java.awt.event.*;
//import java.awt.image.*;
//import java.awt.*;
PXCMSenseManager sm = null;
int nframes = 0;
PImage imgDepth = null;
void setup() {
size(640, 480);
// Create a SenseManager instance
PXCMSenseManager sm=PXCMSenseManager.CreateInstance();
// Select the color and depth streams
sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR,640,480,30);
sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH,320,240,30);
// Initialize and Stream Samples
sm.Init();
for (;;) {
// This function blocks until both samples are ready
if (sm.AcquireFrame(true).isError()) break;
// retrieve the samples
PXCMCapture.Sample sample=sm.QuerySample();
// work on the samples: sample.color & sample.depth
// ...
if (sample.depth != null) {
PXCMImage.ImageData dData = new PXCMImage.ImageData();
sample.depth.AcquireAccess(PXCMImage.Access.ACCESS_READ,PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32, dData);
//imgDepth = dData.ToPImage(0, imgDepth);
imgDepth = dData.ToPImage(0, imgDepth);
sample.depth.ReleaseAccess(dData);
image(imgDepth, 0,0);
}
println(sample.depth);
//hoping to convert the PXCMImage data to something drawable in canvas. String fail
//String depth=sample.depth;
//loadImage("depth");
// go fetching the next samples
sm.ReleaseFrame();}
}
void draw() {
//need to get data from sample.depth here.
//image("sample.depth", 0, 0);
}
// Close down
void dispose(){
sm.close();
}
I am able to initialize the camera, and use println to view the data coming from the camera (sample.depth)
The readouts from the console comes in the form of..
intel.rssdk.PXCMImage@7E89278e intel.rssdk.PXCMImage@70a5104a intel.rssdk.PXCMImage@7548d086
etc etc etc.
The error I am getting at this stage is "The function ToPImage(int,PImage) does not exist". (line 43 I hope..)
This is code I pulled from one of the examples (which I am unable to successfully get running, I have had no luck getting any depth images into Processing at all). It seems to be a fundamental aspect of converting the cameras image format to PImage. Intels reference can be found here..
I believe the examples may have been designed for Processing 2.x so this could be an issue. Any insights would be amazing. Thanks!
Hi, is someone experimenting now with the new camera Intel RealSense? I'm using it now, and the codes works well but when I generate the application it doesn't work :( Below an example, can someone help me to generate working application? Thanks M.
/**
** This sample demonstrates how RealSense SDK Java interface work with Processing
** The sample traces hand positions with a Hand module. Red circle at the PXCMPointF32
**/
import intel.rssdk.*;
import java.lang.System.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.*;
int nframes = 0;
PImage imgDepth = null;
pxcmStatus sts = pxcmStatus.PXCM_STATUS_NO_ERROR;
PXCMSenseManager senseMgr = null;
PXCMHandData handData = null;
// *******************************************************************************
void setup() {
size(640, 480, P2D);
// registerDispose(this);
//Create session
PXCMSession session = PXCMSession.CreateInstance();
if (session == null) {
System.out.print("Failed to create a session instance\n");
System.exit(3);
}
// Create SenseManager
senseMgr = session.CreateSenseManager();
if (senseMgr == null) {
// print("Failed to create a SenseManager instance\n");
return;
}
PXCMCaptureManager captureMgr = senseMgr.QueryCaptureManager();
captureMgr.FilterByDeviceInfo("RealSense", null, 0);
pxcmStatus sts = senseMgr.EnableHand(null);
if (sts.compareTo(pxcmStatus.PXCM_STATUS_NO_ERROR)<0) {
print("Failed to enable HandAnalysis\n");
return;
}
sts = senseMgr.Init();
if (sts.compareTo(pxcmStatus.PXCM_STATUS_NO_ERROR)>=0) {
PXCMHandModule handModule = senseMgr.QueryHand();
PXCMHandConfiguration handConfig = handModule.CreateActiveConfiguration();
handConfig.EnableAllGestures();
handConfig.EnableAllAlerts();
handConfig.ApplyChanges();
handConfig.Update();
handData = handModule.CreateOutput();
} else {
// print("Failed to initial a RSSDK pipeline instance.\n");
return;
}
}
//***************************************************************************************************
void draw() {
// print ("Frame # " + nframes + "\n");
sts = senseMgr.AcquireFrame(true);
if (sts.compareTo(pxcmStatus.PXCM_STATUS_NO_ERROR)<0) return;
nframes++;
if (nframes==65535) nframes = 0;
PXCMCapture.Sample sample = senseMgr.QueryHandSample();
// Query and Display Joint of Hand or Palm
handData.Update();
PXCMHandData.IHand hand = new PXCMHandData.IHand();
sts = handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_NEAR_TO_FAR, 0, hand);
if (sts.compareTo(pxcmStatus.PXCM_STATUS_NO_ERROR) >= 0) {
PXCMPointF32 image = hand.QueryMassCenterImage();
// println("Palm Center at frame " + nframes + ": ");
// print(" Image Position: (" + image.x + "," +image.y + ")");
fill(255,0,0);
ellipse(image.x,image.y,10,10);
}
senseMgr.ReleaseFrame();
}
void dispose() {
if (senseMgr==null) return;
senseMgr.close();
senseMgr=null;
}