Question

I am new to Matlab and Kinect programming. I have managed to struggle through to line 155 of 162 of my code but now I have come stuck and would appreciate any help.

I am trying to record both colour and depth streams so that I can image process them later without have to stream live every time I want to test it. I have managed the colour stream but the depth stream seems more difficult.

I am getting "Error using hgMovie. Movie cdata must be of type uint8 array"

I have tried using line depthMov=uint8(depthMov); as suggested by one forum but now I get "Conversion to uint8 from struct is not possible" any other suggestions? Below are snippets of the code I am trying to use.

    depthVid=videoinput('kinect',2,'Depth_640x480');
    set(depthVid, 'LoggingMode', 'Disk&Memory');
    depthLogfile = VideoWriter('depthlogfile.mj2'), 'Motion JPEG 200');
    depthVid.DiskLogger = depthLogfile;

    triggerconfig(depthVid, 'manual');
    set(depthVid, 'FramesPerTrigger',inf);

    start(depthVid);
    pause(20);
    trigger(depthVid);
    [depthFrameData, depthTimeData, depthMetaData] = getdata(depthVid);
    stop(depthVid)

    depthPlayback=Video('depthlogfile.mj2');

    dFrames=depthPlayback.NumberOfFrames;
    dheight=depthPlayback.Height;
    dWidth=depthPlayback.Width;

    depthMov(1:dFrames)=struct('cdata,zeros(dHeight,dWidth,3,'unit8'),'colormap',[]);

    for k = 1:dFrames
         depthMov(k).cdata=read(depthPlayback,k);
    end

    hf2 = figure;
    set (hf2,'position',[150 150 dWidth dHeight])

    %depthMov = uint(depthMov); % failed conversion

    movie(hf2,depthMov,1,depthPlayback.FrameRate); %Line I am getting the error

Thank you for any help or advice in advance.

Was it helpful?

Solution

the variable depthMov is a structural array, the video data for each frame is the field cdata.

for your application it look like you need to make sure the data in depthMov.cdata is uint8.

in your code you can do this as you assign each frame to depthMov.cdata in the for loop.

try this

 for k = 1:dFrames
     depthMov(k).cdata=uint8(read(depthPlayback,k));
 end

NB the line above this in your code has, what i presume, is a typo and should be

depthMov(1:dFrames)=struct('cdata',zeros(dHeight,dWidth,3,'unit8'),'colormap',[]);

see here for more on matlab fundamentals including different data types.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top