Exemple #1
0
int
main(int argc, char *argv[]) {
  if (!sdl_init(SCREEN_HEIGHT, SCREEN_WIDTH)) {
    return 1;
  }

  if (!kinect_init()) {
    return 1;
  }

  while (!sdl_pollevent()) {
    kinect_poll();
    draw_depths();
  }

  /* Shut down */
  kinect_shutdown();
  sdl_shutdown();
  return 0;
}
Exemple #2
0
int main(int argc, char **argv){

	int error = kinect_init(&G_kt);
	if ( error ){
		printf("Error\n");
		return 1;
	}

	
	//signal(SIGQUIT, intHandler);
	signal(SIGINT, intHandler);
	//signal(SIGHUP, intHandler);

	while ( !feof(stdin) ){
		kinect_read(&G_kt);
		printf("#end\n");
		fflush(stdout);
		usleep(20000);
	}
	kinect_finish(&G_kt);
	return 0;
}
Exemple #3
0
int main(int argc, char *argv[]) {
    SDL_Surface *screen;
    static struct option long_options[] = {
        {"no-kinect", no_argument, 0, 'k'},
        {"fullscreen", optional_argument, 0, 'f'},
        {"help", no_argument, 0, 'h'},
        {0, 0, 0, 0}
    };
    int option_index = 0, opt;
    bool init_kinect = true;
    bool fullscreen_mode = false;
    char *fullscreen_resolution = NULL;

    while ((opt = getopt_long(argc, argv, "khf:", long_options, &option_index)) != -1) {
        switch (opt) {
            case 'k':
                init_kinect = false;
                printf("Not initializing kinect (-k passed)\n");
                break;
            case 'f':
                printf("Starting in fullscreen mode\n");
                fullscreen_mode = true;
                if (optarg)
                    fullscreen_resolution = strdup(optarg);
                break;
            case 'h':
                printf("Syntax: %s [-k] [-h]\n", argv[0]);
                printf("\t--no-kinect\tDisables initializing kinect\n");
                printf("\t--fullscreen\tEnable fullscreen mode (default is windowed)\n");
                printf("\t\t\t(--fullscreen=1024x768 to overwrite the resolution)\n");
                exit(0);
                break;
        }
    }

    median_filter_init();
    glow_filter_init();
    if (init_kinect)
        kinect_init();
    mask_rgb_init();
    loadimg_init();
    
    /* Initialize SDL */
    SDL_Init(SDL_INIT_VIDEO);
    TTF_Init();

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);

    /* Initialize the screen / window */
    if (fullscreen_mode && fullscreen_resolution != NULL) {
        if (sscanf(fullscreen_resolution, "%dx", &SCREEN_WIDTH) != 1) {
            fprintf(stderr, "Invalid resolution specified: %s (needs to be WxH, e.g. 1024x768)\n", fullscreen_resolution);
            exit(1);
        }
        printf("Setting width to %d\n", SCREEN_WIDTH);
    }
    int flags = SDL_OPENGL | SDL_HWSURFACE | SDL_NOFRAME | SDL_DOUBLEBUF;
    if (fullscreen_mode)
        flags |= SDL_FULLSCREEN;
    screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, flags);
    if (screen == 0) {
        printf("set failed: %s\n", SDL_GetError());
        return 1;
    }
    SDL_WM_SetCaption("kinectboard", "");

    glewInit();

    /* Setup viewport */
    glEnable(GL_TEXTURE_2D);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    
    kb_ui_init();
    
    // Register callbacks
    kb_ui_register_void_callback("Exit",exit_callback);
    kb_ui_register_void_callback("Calibrate",run_calibration_callback);
    kb_ui_register_void_callback("StartCalibration",start_calibration_callback);
    kb_ui_register_void_callback("EndCalibration",end_calibration_callback);
    kb_ui_register_void_callback("ImageRight",kb_images_scroll_right);
    kb_ui_register_void_callback("ImageLeft",kb_images_scroll_left);
    kb_ui_register_value_callback("SetDistanceThreshold", set_distance_threshold_callback);
    kb_ui_register_value_callback("SetDepthMultiplier", set_depth_multiplier_callback);
    kb_ui_register_value_callback("SetDepthDifferenceThreshold", set_depth_difference_threshold_callback);
    kb_ui_register_value_callback("SetGlowAreaStart", set_glow_area_start_callback);
    kb_ui_register_value_callback("SetGlowAreaEnd", set_glow_area_end_callback);

    kb_ui_call_javascript("SetRGB", "142,51,19");

    // The CUDA Device Info requires a valid UI since the info is displayed there
    print_cuda_device_info();

    /* Allocate textures and buffers to draw into (from the GPU) */
    allocateGLTexture(&rawDepthBufferID, &rawDepthTextureID);
    allocateGLTexture(&medianBufferID, &medianTextureID);
    allocateGLTexture(&maskedMedianBufferID, &maskedMedianTextureID);
    allocateGLTexture(&glowBufferID, &glowTextureID);
    allocateGLTexture(&rawRgbBufferID, &rawRgbTextureID);
    allocateGLTexture(&maskRgbBufferID, &maskRgbTextureID);
    allocateGLTexture(&contRgbBufferID, &contRgbTextureID);

    kb_image_create("Raw depth image", rawDepthBufferID, rawDepthTextureID);
    kb_image_create("Median-filtered depth image", medianBufferID, medianTextureID);
    kb_image_create("Masked depth image", maskedMedianBufferID, maskedMedianTextureID);
    kb_image_create("Glowing depth", glowBufferID, glowTextureID);
    kb_image_create("Raw RGB image", rawRgbBufferID, rawRgbTextureID);
    kb_image_create("Masked kinect RGB image", maskRgbBufferID, maskRgbTextureID);
    kb_image_create("Cont RGB image", contRgbBufferID, contRgbTextureID);

    // Load a Texture
    //loadTextureFromFile("../data/calibration.bmp", &calibrationBufferID, &calibrationTextureID);
    //kb_image_create("Calibration", calibrationBufferID, calibrationTextureID);

    SDL_Surface* surface = SDL_LoadBMP("../data/calibration.bmp");
    cudaMalloc((void**)&(backgrounds[1]), 640 * 480 * 3 * sizeof(uint8_t));
    loadimg_convert((uint8_t*)surface->pixels, backgrounds[1]);

    surface = SDL_LoadBMP("../data/malen_haus.bmp");
    cudaMalloc((void**)&(backgrounds[2]), 640 * 480 * 3 * sizeof(uint8_t));
    loadimg_convert((uint8_t*)surface->pixels, backgrounds[2]);

    surface = SDL_LoadBMP("../data/malen_stern.bmp");
    cudaMalloc((void**)&(backgrounds[3]), 640 * 480 * 3 * sizeof(uint8_t));
    loadimg_convert((uint8_t*)surface->pixels, backgrounds[3]);


    surface = SDL_LoadBMP("../data/empty.bmp");
    cudaMalloc((void**)&(backgrounds[4]), 640 * 480 * 3 * sizeof(uint8_t));
    loadimg_convert((uint8_t*)surface->pixels, backgrounds[4]);


    printf("gl set up.\n");
 
    uchar4 *gpu_median_output,
           *gpu_masked_median_output,
           *gpu_glow_output,
           *gpu_mask_rgb_output,
           *gpu_raw_depth_output,
           *gpu_raw_rgb_output,
           *gpu_cont_rgb_output;

    int fps = 0;
    int last_time = 0;
    int current_time;

    while (1) {
        /* FPS counter */
        current_time = SDL_GetTicks();
        if ((current_time - last_time) >= 1000) {
            static char buffer[20] = {0};
            sprintf(buffer, "%d FPS", fps);
            SDL_WM_SetCaption(buffer, 0);
            kb_ui_call_javascript("SetFPS",buffer);
            fps = 0;
            last_time = current_time;
        }

        //kb_poll_events(list);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

        /* Reset viewport for rendering our images, it was modified by
         * kb_ui_render(). */
        glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        glClear(GL_COLOR_BUFFER_BIT);

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluOrtho2D(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT);

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        kb_poll_events();

        gpu_median_output = NULL;
        gpu_masked_median_output = NULL;
        gpu_glow_output = NULL;
        gpu_mask_rgb_output = NULL;
        gpu_raw_depth_output = NULL;
        gpu_raw_rgb_output = NULL;
        gpu_cont_rgb_output = NULL;

        cutilSafeCall(cudaGLMapBufferObject((void**)&gpu_raw_depth_output, rawDepthBufferID));
        cutilSafeCall(cudaGLMapBufferObject((void**)&gpu_median_output, medianBufferID));
        cutilSafeCall(cudaGLMapBufferObject((void**)&gpu_masked_median_output, maskedMedianBufferID));
        cutilSafeCall(cudaGLMapBufferObject((void**)&gpu_glow_output, glowBufferID));
        cutilSafeCall(cudaGLMapBufferObject((void**)&gpu_mask_rgb_output, maskRgbBufferID));
        cutilSafeCall(cudaGLMapBufferObject((void**)&gpu_raw_rgb_output, rawRgbBufferID));
        cutilSafeCall(cudaGLMapBufferObject((void**)&gpu_cont_rgb_output, contRgbBufferID));

        // XXX: Potential for optimization: We currently call functions like
        // median_filter(), median_mask() and mask_rgb() which are all
        // blocking. However, we could launch the kernel and perform more work
        // on the CPU while waiting for the kernel to complete (or maybe even
        // launch some in parallel and/or use async events).

        median_filter(take_depth_image(), gpu_median_output, gpu_raw_depth_output);
        done_depth_image();

        median_mask(calibration, gpu_median_output, gpu_masked_median_output);
        glow_filter(gpu_masked_median_output, gpu_glow_output, glow_start, glow_end);

        mask_rgb(gpu_glow_output, take_rgb_image(), gpu_mask_rgb_output, gpu_raw_rgb_output, gpu_cont_rgb_output, reference_color, FILTER_DISTANCE, backgrounds[current_background], calibrated_offset);
        done_rgb_image();

        cutilSafeCall(cudaGLUnmapBufferObject(maskedMedianBufferID));
        cutilSafeCall(cudaGLUnmapBufferObject(medianBufferID));
        cutilSafeCall(cudaGLUnmapBufferObject(glowBufferID));
        cutilSafeCall(cudaGLUnmapBufferObject(maskRgbBufferID));
        cutilSafeCall(cudaGLUnmapBufferObject(rawDepthBufferID));
        cutilSafeCall(cudaGLUnmapBufferObject(rawRgbBufferID));
        cutilSafeCall(cudaGLUnmapBufferObject(contRgbBufferID));

        if(fullscreen_canvas) {
           kb_images_render_canvas_only();
        } else {
            kb_images_render();
            kb_ui_update();
            kb_ui_render();
        }
            SDL_GL_SwapBuffers();
        fps++;
    }
}