jrterven / Kin2

A Kinect 2 Toolbox for Matlab
38 stars 17 forks source link

Inf value in mapColorPoints2Camera when changing input pixels #4

Open aminEdraki opened 7 years ago

aminEdraki commented 7 years ago

Hello. As a part of a research project, I am trying to estimate the position of a marker with specific color with kinect. In the first part, markers position and color are determined by clicking on the marker and after that, in each frame I search the color image to find the markers position in the color frame (in pixels) and update the position. After that I use the mapColorPoints2Camera to determine the world coordinates of the marker. But the code continuously generates Inf value for all three coordinates. I have tried to check a fix point (for example 100, 100) and used the mapColorPoints2Camera function and it worked well. But as I changed the value in a loop (for example to check the coordinates on a line) the code generates inf value again.

I'm using MatlabR2016b, VS 2015 and MS Windows 10. Here is my code:

addpath('Mex'); clear all close all

k2 = Kin2('color','depth');

% images sizes d_width = 512; d_height = 424; outOfRange = 4000; c_width = 1920; c_height = 1080;

% Color image is to big, let's scale it down COL_SCALE = 0.5;

% Create matrices for the images depth = zeros(d_height,d_width,'uint16'); color = zeros(c_heightCOL_SCALE,c_widthCOL_SCALE,3,'uint8');

% Loop until pressing 'q' on any figure k=[]; count = 0;

while true % Get frames from Kinect and save them on underlying buffer validData = k2.updateData;

% Before processing the data, we need to make sure that a valid
% frame was acquired.
if validData
    % Copy data to Matlab matrices
    depth = k2.getDepth;
    color = k2.getColor;

    % update depth figure
    depth8u = uint8(depth*(255/outOfRange));
    depth8uc3 = repmat(depth8u,[1 1 3]);
    color = imresize(color,COL_SCALE);
    count = count + 1;        
    k2.mapColorPoints2Camera([count count])

end

if ~isempty(k)    
    if strcmp(k,'q'); break; end;
end
pause(0.01)

end

jrterven commented 7 years ago

Hi,

The camera space resolution is the same as the depth and infrared camera (512 x 424). When converting a color coordinate (1920 x 1080) to camera space there are many color coordinates without depth information and are returned as inf. So it is normal to obtain many inf values (even more at the boundaries and at reflective areas). You can check of the value is not inf and proceed. A probably better approach can be performed some kind of interpolation using nearest neighbors when obtaining inf.

Hope this helps.

Juan

On Dec 18, 2016, at 1:17 PM, aminEdraki notifications@github.com<mailto:notifications@github.com> wrote:

Hello. As a part of a research project, I am trying to estimate the position of a marker with specific color with kinect. In the first part, markers position and color are determined by clicking on the marker and after that, in each frame I search the color image to find the markers position in the color frame (in pixels) and update the position. After that I use the mapColorPoints2Camera to determine the world coordinates of the marker. But the code continuously generates Inf value for all three coordinates. I have tried to check a fix point (for example 100, 100) and used the mapColorPoints2Camera function and it worked well. But as I changed the value in a loop (for example to check the coordinates on a line) the code generates inf value again.

I'm using MatlabR2016b, VS 2015 and MS Windows 10. Here is my code:

`addpath('Mex'); clear all close all

k2 = Kin2('color','depth');

% images sizes d_width = 512; d_height = 424; outOfRange = 4000; c_width = 1920; c_height = 1080;

% Color image is to big, let's scale it down COL_SCALE = 0.5;

% Create matrices for the images depth = zeros(d_height,d_width,'uint16'); color = zeros(c_heightCOL_SCALE,c_widthCOL_SCALE,3,'uint8');

% Loop until pressing 'q' on any figure k=[]; count = 0;

while true % Get frames from Kinect and save them on underlying buffer validData = k2.updateData;

% Before processing the data, we need to make sure that a valid % frame was acquired. if validData % Copy data to Matlab matrices depth = k2.getDepth; color = k2.getColor;

% update depth figure
depth8u = uint8(depth*(255/outOfRange));
depth8uc3 = repmat(depth8u,[1 1 3]);
color = imresize(color,COL_SCALE);
count = count + 1;
k2.mapColorPoints2Camera([count count])

end

if ~isempty(k) if strcmp(k,'q'); break; end; end pause(0.01)

end`

- You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/jrterven/Kin2/issues/4, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADAPKBHdHB4WxniL3JULIx--E3HjYyMEks5rJYa2gaJpZM4LQNRv.

aminEdraki commented 7 years ago

Thanks Juan. That helped a lot!

aminEdraki commented 7 years ago

Hi again. I have another problem in my code. My pre-processing part takes some time and so the maximum frame rate possible (in real time) is about 10 fps. Is there any way to save the depth and color data and do the mappings and further processing after that on the files? I want to record the data and then do the processing. I know how to record depth and color data as a video file, but don't know how to process it after that (I mean calling the function mapColorPoints2Camera)