xxorde / librekinect

Depth data from a kinect sensor! Small and fast kernel driver. Also for embedded devices like the raspberry pi!
407 stars 68 forks source link

Getting depth image values #1

Open arunchettoor opened 10 years ago

arunchettoor commented 10 years ago

@xxorde Thank you so much . I am not having any monitor for the output. I am using ssh to communicate with the board. I got that this can be done like calling cvCaptureFromCAM functions of OpenCV,isnt it? I will try and let you know about my proceedings. But I have a doubt that in kinect libfreenect they have many formats in depth image like mm , 10 bit, 11 bit etc, so is it possible to change these parameters in this module.

arunchettoor commented 10 years ago

I done with the following code -

#include <cv.h>
#include <highgui.h>

int main( int argc, char* argv[] ) 
{
    int i=1;
    CvCapture* capture = NULL;
    capture = cvCreateCameraCapture( 0 );
    IplImage *frame = cvQueryFrame(capture);

    while(1) 
    {
        // if we are on the 20th frame, quit.
        if (i==20)
        {
            cvReleaseCapture ( &capture );
            break;
        }

        // if the user types whatever key 27 corresponds to, quit.
        char c = cvWaitKey(33);
        if( c == 27 )
        {
            cvReleaseCapture ( &capture );
            break;
        }
        // do you want to get the next frame?  here.
        frame = cvQueryFrame( capture );
        i++;
    }
    return 0;
}

But when i compile it it is getting output as -

VIDIOC_QUERYCTRL: Inappropriate ioctl for device
VIDIOC_QUERYCTRL: Inappropriate ioctl for device
VIDIOC_QUERYCTRL: Inappropriate ioctl for device
VIDIOC_QUERYCTRL: Inappropriate ioctl for device
VIDIOC_QUERYCTRL: Inappropriate ioctl for device
VIDIOC_QUERYCTRL: Inappropriate ioctl for device

The code is running only upto "capture = cvCreateCameraCapture( 0 );" Can anyone try out the code to get the pixel.

xxorde commented 10 years ago

Am 18.04.2014 01:30, schrieb Arun Krishnan Chettoor:

@xxorde Thank you so much . I am not having any monitor for the output. I am using ssh to communicate with the board. I do not see your problem over ssh, what is it? If you want to process the data you do not need a monitor, if you want them somewhere else you can stream them. If you just want to look at the depth data you can use "ssh -X pi@pi". I got that this can be done like calling cvCaptureFromCAM functions of OpenCV,isnt it? It depends on your software, with this driver the kinetic can be used like a standard video device.

I gave you some hints here: https://github.com/OpenKinect/libfreenect/issues/338#issuecomment-40772870

I will try and let you know about my proceedings. Please let me know. If you have issues with OpenCV search for your error message or ask at https://stackoverflow.com But I have a doubt that in kinect libfreenect they have many formats in depth image like mm, 10 bit, 11 bit etc, so is it possible to change these parameters in this module. At the moment it only supports 10 bit but if you need to change it, you can. In two steps.

Step 1 kinect.c:256

255 /* Depth Stream Format 0x03: 11 bit stream | 0x02: 10 bit */
256 write_register(gspca_dev, 0x12, 0x02);

As my comment on 255 indicates you can change the line 256 to:

256 write_register(gspca_dev, 0x12, 0x03);

Step 2 kinect.c:88-94 Choose a 11 bit format instead of "FORMAT_Y10B".

static const struct v4l2_pix_format video_camera_mode[] = {
        {640, 480, V4L2_PIX_FMT_Y10BPACK, V4L2_FIELD_NONE,
     .bytesperline = 640 * 10 / 8,
     .sizeimage =  640 * 480 * 10 / 8,
     .colorspace = V4L2_COLORSPACE_SRGB,
     .priv = MODE_640x480 | FORMAT_Y10B | FPS_HIGH},
};

btw: GitHub does not process the markdown in my eMail comments, I hope they fix it soon.

arunchettoor commented 10 years ago

@xxorde Thank you. Could you please try the earlier code i posted, to see whether i have any problem with the OpenCV. I got raw output from the camera. The code i used is this one:

#include <stdio.h>
#include <stdlib.h>
#define SIZE 307200 // number of pixels (640x480 for a frame)
int main() {
    FILE *camera, *grab;
    camera=fopen("/dev/video0", "rb");
    grab=fopen("grab.raw", "wb");
    int data[SIZE];
    fread(data, sizeof(data[0]), SIZE, camera);
    fwrite(data, sizeof(data[0]), SIZE, grab);
    fclose(camera);
    fclose(grab); 
    return 0;
}

Is this fine or whether I need to wait for any pixel value to start the cropping. If I am trying to find the depth values(by shifting 8 and adding next value) gives high values. I need to get the correct pixel distance from camera. Please give suggestions for this. Thank You.

kalibre92 commented 7 years ago

Hello @arunchettoor, I am new at using the kinect to get depth, and I am using this last code you have posted here, trying to analyse the raw data, and find the distances in each pixel. I have just opened the grab.raw in sublime and I got what u can see in the image

foto

This has 76800 lines and 8 columns, wich makes 8 characters for each pixel. Is this correct? Do you know how do I convert this values to an decimal one?

What I pretend to do in the end is detecting the location in the matrix for every pixel above a certain threshold (ie every pixel that idicates distance closer than 1 meter).

All of this is so I can detect a hand that is close enough from the kinect for exemple, and this way track its movement. If you have any other suggestions, I am happy to hear! (maybe if I can use open CV to get depth also)

I am sorry for lots of questions!

@xxorde if you have any suggestions also, I would gladely appreciate!

Thanks a lot!

lucyking commented 7 years ago

hi @kalibre92 , the raw data is in Y10B format. May you can transform it using this fx : get_raw().

kalibre92 commented 7 years ago

Thank you very much @lucyking!! I understood now, and your code in pickinect will help me a lot!

lucyking commented 7 years ago

@kalibre92 my pleasure.