int start_capture(RASPIVID_STATE *state) { if (!(state->isInit)) init_cam(state); //raspicamcontrol_set_flips(state->camera_component, state->camera_parameters.hflip, state->camera_parameters.vflip); raspicamcontrol_set_flips(state->camera_component, hflip, vflip); MMAL_PORT_T *camera_video_port = state->camera_component->output[MMAL_CAMERA_VIDEO_PORT]; //MMAL_PORT_T *encoder_output_port = state->encoder_component->output[0]; ROS_INFO("Starting video capture (%d, %d, %d, %d)\n", state->width, state->height, state->quality, state->framerate); if (mmal_port_parameter_set_boolean(camera_video_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS) { return 1; } // Send all the buffers to the video port { int num = mmal_queue_length(state->camera_pool->queue); int q; for (q=0; q < num; q++) { MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(state->camera_pool->queue); if (!buffer) vcos_log_error("Unable to get a required buffer %d from pool queue", q); //if (mmal_port_send_buffer(encoder_output_port, buffer)!= MMAL_SUCCESS) if (mmal_port_send_buffer(camera_video_port, buffer)!= MMAL_SUCCESS) vcos_log_error("Unable to send a buffer to encoder output port (%d)", q); } } ROS_INFO("Video capture started\n"); return 0; }
void init_struct(t_mega *all) { all->e.refresh = 1; init_hook(&all->hook); init_cam(&all->cam, (int)START_X, (int)START_Y); init_player(&all->player); init_textures(all); all->sprites = init_sprites(all); init_minimap(&all->e, &all->hook.minimap); stock_minimap(all); all->door.x = 0; }
int main () { double prev_time = 0.0; double accum_sim_time = 0.0; if (!start_gl (800, 800)) { fprintf (stderr, "ERROR: could not start opengl\n"); return 1; } init_cam (); init_terrain (); init_dash (); glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LESS); glClearColor (0.0, 0.5, 0.5, 1.0); prev_time = glfwGetTime (); while (!glfwWindowShouldClose (gl_window)) { // work out how much time has passed double curr_time = glfwGetTime (); double elapsed = curr_time - prev_time; prev_time = curr_time; accum_sim_time += elapsed; // work out simulation time steps while (accum_sim_time > TIME_STEP_SIZE) { accum_sim_time -= TIME_STEP_SIZE; update_player (TIME_STEP_SIZE); } glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport (0, 0, gl_width, gl_height); draw_terrain (); // i dont want the dashboard to ever intersect with background so // i do a clear of the depth buffer glClear (GL_DEPTH_BUFFER_BIT); draw_dash (); // can expect everything has updated camera matrices by now cam_P_dirty = false; cam_V_dirty = false; glfwPollEvents (); glfwSwapBuffers (gl_window); } return 0; }
static t_env *init_env(int **map) { t_env *e; e = (t_env*)malloc(sizeof(t_env) * 1); ft_init_sdl(e); ft_create_win_sdl(e, 0, 0); e->rend = ft_init_renderer(e); e->map = map; init_cam(&e->cam); init_keys(e); load_image(e, "ressources/menu.bmp"); load_sound(e, "ressources/test.wav"); return (e); }
int main(int ac, char **av) { GLFWwindow *win; t_env e; t_cam c; init_key_binding(); init_scene(&e); init_cam(&c, &e); if (!glfwInit()) exit(EXIT_FAILURE); glfwSetErrorCallback(error_callback); if (!(win = glfwCreateWindow(WIN_W, WIN_H, "visualisatron 2000", NULL, NULL))) ft_exit("failed to open window !"); e.map = malloc(4096); e.player_number = 4; e.memory_size = 4096; e.grid_width = 64; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_SAMPLES, 1); glfwSetFramebufferSizeCallback(win, framebuffer_size_callback); glfwSetKeyCallback(win, key_callback); glfwSetWindowSizeCallback(win, window_size_callback); glfwMakeContextCurrent(win); glfwSetCursorPosCallback(win, cursor_pos_callback); glfwSetMouseButtonCallback(win, mouse_click_callback); glfwSetScrollCallback(win, mouse_scroll_callback); glfwSwapInterval(1); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glfwShowWindow(win); init_msaa(); // printf("%s\n", glGetString( GL_EXTENSIONS ) ); while (!glfwWindowShouldClose(win)) main_loop(win, &e); glfwDestroyWindow(win); glfwTerminate(); return (0); (void)ac; (void)av; }
void init_scene(t_img *img) { init_cam(&img->scene.cam, init_vect(-2, -2, 0)); img->scene.light = create_light(init_vect(0, 0, -35), 0xffffff); img->scene.obj[0] = create_sphere(init_vect(0, 0, -10), 80, 0xffffff); img->scene.obj[1] = create_sphere(init_vect(-20, 24, -80), 50, 0x00ff00); img->scene.obj[2] = create_sphere(init_vect(10, 10, -100), 50, 0xfff700); img->scene.obj[3] = create_sphere(init_vect(200, 200, -150), 50, 0x0000ff); // img->scene.obj[4] = create_cone(init_vect(0, 0, -5), 20, 0xff00ff); img->scene.obj[4] = create_sphere(init_vect(600, 600, -150), 50, 0xff00ff); img->scene.obj[5] = create_cylinder(init_vect(2, 2, -110), init_vect(0, 1, 1), 50, 0x777777); img->scene.obj[6] = create_plane(init_vect(1, 0, 1), init_vect(0, 0, -200), 0xff0000); img->scene.obj[7] = create_plane(init_vect(0, 1, 1), init_vect(0, 0, -200), 0xffffcc); }
void init_object(t_env *raytracer, const char *file) { int elem; char *tmp; int i; elem = xopen(file, O_RDONLY); while ((tmp = get_next_line(elem))) { i = -1; while (++i < MAX && my_strncmp(tmp, functions[i].object_name, my_strlen(functions[i].object_name)) != 1); if (i < MAX) push_front(&(raytracer->objects[i]), (*(functions[i].init_func))(tmp)); else if (my_strncmp(tmp, "camera", 6) != 0) init_cam(&raytracer->camera, tmp); else if (my_strncmp(tmp, "plan", 4) != 0) init_plan(&raytracer->plan, tmp); printf("%s\n", tmp); } }
void init_test( const char * fname ) { atexit( quit_test ); printf( "Initializing SDL.\n" ); if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ) ) { printf( "Failed to load SDL2: %s\n" , SDL_GetError() ); exit(1); } printf( "Creating a window.\n" ); window = SDL_SetVideoMode(640, 480, 0, SDL_FULLSCREEN | SDL_SWSURFACE); if( ! window ) { printf( "Failed to create window: %s\n" , SDL_GetError() ); exit(1); } red_procentage = (int)fname; printf( "Starting camera\n" ); if( init_cam() ) { printf( "FAILED TO START CAMERA!\n" ); exit( 1 ); } pixels = ( Pixel * ) malloc( INPUT_SIZE * sizeof( Pixel ) ); dspixels = ( Pixel * ) malloc( DS_SIZE * sizeof( Pixel ) ); // Downscaled version input = SDL_CreateRGBSurfaceFrom( (byte *)pixels , INPUT_WIDTH, INPUT_HEIGHT, INPUT_DEPTH, INPUT_PITCH, MASK_R , MASK_G , MASK_B , MASK_A ); downscale = SDL_CreateRGBSurfaceFrom( (byte *)dspixels , DS_WIDTH, DS_HEIGHT, DS_DEPTH, DS_PITCH, MASK_R , MASK_G , MASK_B , MASK_A ); take_frame( (byte * )pixels ); if( !input ) { printf( "Failed to load input! %s\n" , SDL_GetError() ); exit( 1 ); } printf( "Initialized.\n" ); }
int main(int ac, char **av) { t_param param; t_obj_list *objects; t_cam cam; scene = NULL; if (ac != 2) return (write(2, "Usage : ./rt <scene>\n", 21)); if (get_scene(&objects, av[1])) return (1); if (!(param.mlx_ptr = mlx_init())) return (1); cam = init_cam(); param.win_ptr = mlx_new_window(param.mlx_ptr, WINX, WINY, "JazaRT"); param.cmap.img = mlx_new_image(param.mlx_ptr, WINX, WINY); if (!(draw_plan(param.cmap, &objects, &cam))) return (1); mlx_key_hook(param.win_ptr, gere_key, (void *)¶m); mlx_expose_hook(param.win_ptr, gere_expose, (void *)¶m); mlx_loop(param.mlx_ptr); return (0); }
int main(int argc, char *argv[]) { cam cam_object, *cam; Display *display; Screen *screen_num; gchar *poopoo = NULL; gchar *pixfilename = "camorama/camorama.png"; gchar *filename; //= "/usr/opt/garnome/share/camorama/camorama.glade"; int x = -1, y = -1; gboolean buggery = FALSE; GtkWidget *button; GConfClient *gc; const struct poptOption popt_options[] = { {"version", 'V', POPT_ARG_NONE, &ver, 0, N_("show version and exit"), NULL}, {"device", 'd', POPT_ARG_STRING, &poopoo, 0, N_("v4l device to use"), NULL}, {"debug", 'D', POPT_ARG_NONE, &buggery, 0, N_("enable debugging code"), NULL}, {"width", 'x', POPT_ARG_INT, &x, 0, N_("capture width"), NULL}, {"height", 'y', POPT_ARG_INT, &y, 0, N_("capture height"), NULL}, {"max", 'M', POPT_ARG_NONE, &max, 0, N_("maximum capture size"), NULL}, {"min", 'm', POPT_ARG_NONE, &min, 0, N_("minimum capture size"), NULL}, {"half", 'H', POPT_ARG_NONE, &half, 0, N_("middle capture size"), NULL}, {"read", 'R', POPT_ARG_NONE, &use_read, 0, N_("use read() rather than mmap()"), NULL}, POPT_TABLEEND }; cam = &cam_object; /* set some default values */ cam->frame_number = 0; cam->pic = NULL; cam->pixmap = NULL; cam->size = PICHALF; cam->video_dev = NULL; cam->read = FALSE; bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); setlocale (LC_ALL, ""); /* gnome_program_init - initialize everything (gconf, threads, etc) */ gnome_program_init (PACKAGE_NAME, PACKAGE_VERSION, LIBGNOMEUI_MODULE, argc, argv, GNOME_PARAM_APP_DATADIR, PACKAGE_DATA_DIR, GNOME_PARAM_POPT_TABLE, popt_options, GNOME_PARAM_HUMAN_READABLE_NAME, _("camorama"), NULL); /* gtk is initialized now */ camorama_stock_init(); camorama_filters_init(); cam->debug = buggery; cam->x = x; cam->y = y; glade_gnome_init (); glade_set_custom_handler (camorama_glade_handler, cam); if (ver) { fprintf (stderr, _("\n\nCamorama version %s\n\n"), VERSION); exit (0); } if (max) { cam->size = PICMAX; } if (min) { cam->size = PICMIN; } if (half) { cam->size = PICHALF; } if (use_read) { printf ("gah!\n"); cam->read = TRUE; } gc = gconf_client_get_default (); cam->gc = gc; gconf_client_add_dir (cam->gc, PATH, GCONF_CLIENT_PRELOAD_NONE, NULL); gconf_client_notify_add (cam->gc, KEY1, (void *) gconf_notify_func, cam->pixdir, NULL, NULL); gconf_client_notify_add (cam->gc, KEY5, (void *) gconf_notify_func, cam->rhost, NULL, NULL); gconf_client_notify_add (cam->gc, KEY2, (void *) gconf_notify_func, cam->capturefile, NULL, NULL); gconf_client_notify_add (cam->gc, KEY3, (void *) gconf_notify_func_int, GINT_TO_POINTER (cam->savetype), NULL, NULL); gconf_client_notify_add (cam->gc, KEY4, (void *) gconf_notify_func_bool, &cam->timestamp, NULL, NULL); if (!poopoo) { gchar const* gconf_device = gconf_client_get_string(cam->gc, KEY_DEVICE, NULL); if(gconf_device) { cam->video_dev = g_strdup(gconf_device); } else { cam->video_dev = g_strdup ("/dev/video0"); } } else { cam->video_dev = g_strdup (poopoo); } cam->pixdir = g_strdup (gconf_client_get_string (cam->gc, KEY1, NULL)); cam->capturefile = g_strdup (gconf_client_get_string (cam->gc, KEY2, NULL)); cam->rhost = g_strdup (gconf_client_get_string (cam->gc, KEY5, NULL)); cam->rlogin = g_strdup (gconf_client_get_string (cam->gc, KEY6, NULL)); cam->rpw = g_strdup (gconf_client_get_string (cam->gc, KEY7, NULL)); cam->rpixdir = g_strdup (gconf_client_get_string (cam->gc, KEY8, NULL)); cam->rcapturefile = g_strdup (gconf_client_get_string (cam->gc, KEY9, NULL)); cam->savetype = gconf_client_get_int (cam->gc, KEY3, NULL); cam->rsavetype = gconf_client_get_int (cam->gc, KEY10, NULL); cam->ts_string = g_strdup (gconf_client_get_string (cam->gc, KEY16, NULL)); cam->date_format = "%Y-%m-%d %H:%M:%S"; cam->timestamp = gconf_client_get_bool (cam->gc, KEY4, NULL); cam->rtimestamp = gconf_client_get_bool (cam->gc, KEY11, NULL); cam->cap = gconf_client_get_bool (cam->gc, KEY12, NULL); cam->rcap = gconf_client_get_bool (cam->gc, KEY13, NULL); cam->timefn = gconf_client_get_bool (cam->gc, KEY14, NULL); cam->rtimefn = gconf_client_get_bool (cam->gc, KEY15, NULL); cam->usestring = gconf_client_get_bool (cam->gc, KEY18, NULL); cam->usedate = gconf_client_get_bool (cam->gc, KEY19, NULL); cam->acap = gconf_client_get_bool (cam->gc, KEY20, NULL); cam->timeout_interval = gconf_client_get_int (cam->gc, KEY21, NULL); cam->show_adjustments = gconf_client_get_bool (cam->gc, KEY22, NULL); cam->show_effects = gconf_client_get_bool (cam->gc, KEY23, NULL); /* get desktop depth */ display = (Display *) gdk_x11_get_default_xdisplay (); screen_num = xlib_rgb_get_screen (); gdk_pixbuf_xlib_init (display, 0); cam->desk_depth = xlib_rgb_get_depth (); cam->dev = open (cam->video_dev, O_RDWR); camera_cap (cam); get_win_info (cam); /* query/set window attributes */ cam->vid_win.x = 0; cam->vid_win.y = 0; cam->vid_win.width = cam->x; cam->vid_win.height = cam->y; cam->vid_win.chromakey = 0; cam->vid_win.flags = 0; set_win_info (cam); get_win_info (cam); /* get picture attributes */ get_pic_info (cam); // set_pic_info(cam); /* set_pic_info(cam); */ cam->contrast = cam->vid_pic.contrast; cam->brightness = cam->vid_pic.brightness; cam->colour = cam->vid_pic.colour; cam->hue = cam->vid_pic.hue; cam->wb = cam->vid_pic.whiteness; cam->depth = cam->vid_pic.depth / 8; cam->pic_buf = malloc (cam->x * cam->y * cam->depth); cam->tmp = malloc (cam->vid_cap.maxwidth * cam->vid_cap.maxheight * cam->depth); //cam->tmp = NULL; /* set the buffer size */ if (cam->read == FALSE) { set_buffer (cam); } //cam->read = FALSE; /* initialize cam and create the window */ if (cam->read == FALSE) { pt2Function = timeout_func; init_cam (NULL, cam); } else { printf ("using read()\n"); cam->pic = realloc (cam->pic, (cam->vid_cap.maxwidth * cam->vid_cap.maxheight * 3)); pt2Function = read_timeout_func; } cam->pixmap = gdk_pixmap_new (NULL, cam->x, cam->y, cam->desk_depth); filename = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_DATADIR, "camorama/camorama.glade", TRUE, NULL); if (filename == NULL) { error_dialog (_ ("Couldn't find the main interface file (camorama.glade).")); exit (1); } //pixfilename = gnome_program_locate_file(NULL, GNOME_FILE_DOMAIN_APP_DATADIR, "pixmaps/camorama.png", TRUE, NULL); //printf("pixfile = %s\n",pixfilename); //pixfilename); //printf("pixfile = %s\n",pixfilename); cam->xml = glade_xml_new (filename, NULL, NULL); /*eggtray */ /*tray_icon = egg_tray_icon_new ("Our other cool tray icon"); * button = gtk_button_new_with_label ("This is a another\ncool tray icon"); * g_signal_connect (button, "clicked", * G_CALLBACK (second_button_pressed), tray_icon); * * gtk_container_add (GTK_CONTAINER (tray_icon), button); * gtk_widget_show_all (GTK_WIDGET (tray_icon)); */ load_interface (cam); cam->idle_id = gtk_idle_add ((GSourceFunc) pt2Function, (gpointer) cam); gtk_timeout_add (2000, (GSourceFunc) fps, cam->status); gtk_main (); return 0; }
int main() { // important variables used in most applications int rc; Fg_Struct *fg = NULL; int img_nr; TrackingWindow cur; int seq[] = SEQ; // following lines are for displaying images only! See OpenCV doc for more info. // they can be left out, if speed is important. IplImage *cvDisplay = NULL; cvDisplay = cvCreateImageHeader(cvSize(ROI_BOX, ROI_BOX), BITS_PER_PIXEL, NUM_CHANNELS); cvNamedWindow(DISPLAY, CV_WINDOW_AUTOSIZE); // initialize the tracking window (i.e. blob and ROI positions) memset(&cur, 0, sizeof(TrackingWindow)); set_initial_positions(&cur); // initialize the camera rc = init_cam(&fg, MEMSIZE(cur.roi_w, cur.roi_h), NUM_BUFFERS, CAMLINK); if(rc != FG_OK) { printf("init: %s\n", Fg_getLastErrorDescription(fg)); Fg_FreeGrabber(fg); return rc; } // start acquiring images (this function also writes any buffered ROIs to the camera) rc = acquire_imgs(fg, (int *) &seq, SEQ_LEN); if(rc != FG_OK) { printf("init: %s\n", Fg_getLastErrorDescription(fg)); Fg_FreeGrabber(fg); return rc; } // initialize parameters img_nr = 1; // start image loop and don't stop until the user presses 'q' printf("press 'q' at any time to quit this demo."); while(!(_kbhit() && _getch() == 'q')) { img_nr = Fg_getLastPicNumberBlocking(fg, img_nr, PORT_A, TIMEOUT); cur.img = (unsigned char *) Fg_getImagePtr(fg, img_nr, PORT_A); // make sure that camera returned a valid image if(cur.img != NULL) { // increment to the next desired frame. This has to be at least // +2, because the camera's ROI will not be active until the second // frame (see Silicon Software FastConfig doc) img_nr += NEXT_IMAGE; // process image threshold(&cur, THRESHOLD); erode(&cur); // update ROI position position(&cur); // at this point position(...) has updated the ROI, but it only stores // the updated values internal to the code. The next step is to flush // the ROI to the camera (see position(...) documentation). // write ROI position to camera to be updated on frame "img_nr" write_roi(fg, cur.roi, img_nr, !DO_INIT); // show image on screen display_tracking(&cur, cvDisplay); } else { // typically this state only occurs if an invalid ROI has been programmed // into the camera (e.g. roi_w == 4). printf("img is null: %d\n", img_nr); break; } } // free viewer resources cvReleaseImageHeader(&cvDisplay); // free camera resources rc = deinit_cam(fg); if(rc != FG_OK) { printf("deinit: %s\n", Fg_getLastErrorDescription(fg)); return rc; } return FG_OK; }