void HUD_Lua_Class::start_draw(void) { alephone::Screen *scr = alephone::Screen::instance(); m_wr = scr->window_rect(); m_opengl = (get_screen_mode()->acceleration != _no_acceleration); m_masking_mode = _mask_disabled; #ifdef HAVE_OPENGL if (m_opengl) { glPushAttrib(GL_ALL_ATTRIB_BITS); glEnable(GL_TEXTURE_2D); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glDisable(GL_ALPHA_TEST); glDisable(GL_STENCIL_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_FOG); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glTranslatef(m_wr.x, m_wr.y, 0.0); m_surface = NULL; } else #endif { if (m_surface && (m_surface->w != SDL_GetVideoSurface()->w || m_surface->h != SDL_GetVideoSurface()->h)) { SDL_FreeSurface(m_surface); m_surface = NULL; } if (!m_surface) { m_surface = SDL_DisplayFormatAlpha(SDL_GetVideoSurface()); SDL_SetAlpha(m_surface, SDL_SRCALPHA, 0); } SDL_SetClipRect(m_surface, NULL); SDL_FillRect(m_surface, NULL, SDL_MapRGBA(m_surface->format, 0, 0, 0, 0)); SDL_SetAlpha(SDL_GetVideoSurface(), SDL_SRCALPHA, 0xff); } m_drawing = true; clear_mask(); }
static int am_uart_startup(struct uart_port *port) { struct am_uart_port * info = &am_ports[port->line]; am_uart_t *uart = uart_addr[info->line]; unsigned long mode; #ifdef PRINT_DEBUG if(info->line == DEBUG_PORT_ID) printk("%s\n", __FUNCTION__); #endif mutex_lock(&info->info_mutex); set_mask(&uart->mode, UART_RXRST|UART_TXRST|UART_CLEAR_ERR); clear_mask(&uart->mode, UART_RXRST|UART_TXRST|UART_CLEAR_ERR); mode = readl(&uart->mode); mode |= UART_RXENB | UART_TXENB; writel(mode, &uart->mode); mutex_unlock(&info->info_mutex); return 0; }
C_RESULT output_gtk_stage_transform( void *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out) { static int frame = 0; static int mass = 0, x_center = -1, y_center = -1; unsigned char mask_buf[WIDTH*HEIGHT]; uint8_t display_data[WIDTH*HEIGHT*3]; int is_hover; static int width, height; static int is_face = 0; int camshift_error; static float this_hue_buf[WIDTH*HEIGHT]; static float last_hue_buf[WIDTH*HEIGHT]; int i; static camshift_frames = 0; FILE *fp; char filename[50]; frame++; // GET FRAME FROM VIDEO FEED vp_os_mutex_lock(&video_update_lock); pixbuf_data = (uint8_t*)in->buffers[0]; vp_os_mutex_unlock(&video_update_lock); // Process frame for orange ball // UNCOMMENT TO DETECT BALL //process_frame_ball(pixbuf_data, mask_buf, &mass, &x_center, &y_center); // UNCOMMENT TO DETECT FACES if (is_face == 0) { //printf("Detecting face...\n"); process_frame_face(pixbuf_data, &mass, &x_center, &y_center, &width, &height); if (mass > 8) { is_face = 1; rgb2hue(pixbuf_data, last_hue_buf); printf("DETECT!!! x,y = %d, %d\n", x_center, y_center); } } else { rgb2hue(pixbuf_data, this_hue_buf); camshift_error = camshift(last_hue_buf, this_hue_buf, &x_center, &y_center, width, height); printf("camshift x,y = %d, %d\n", x_center, y_center); // copy this buffer to last buffer for (i=0; i<WIDTH*HEIGHT; i++) { last_hue_buf[i] = this_hue_buf[i]; } if (camshift_error) { printf("CAMSHIFT ERROR\n"); is_face = 0; x_center = -1; y_center = -1; } camshift_frames++; // about two seconds if (camshift_frames > 30) { printf("!!check to see if we are still tracking\n"); camshift_frames = 0; is_face = 0; } } // we did not use the mask, so make it all black clear_mask(mask_buf); // write pixbuf to file sprintf(filename, "/home/a/pixbuf/pixbuf_%d.ppm", frame); fp = fopen(filename, "w"); // write header fprintf(fp, "P6\n320 240\n255\n"); for (i=0; i<320*240*3; i++) { fprintf(fp, "%c", pixbuf_data[i]); } fclose(fp); fp = fopen("/home/a/meanshift_log.txt", "a"); // write log // framenum, mass, centroid_x, centroid_y, width, height fprintf(fp, "%d %d %d %d %d %d\n", frame, mass, x_center, y_center, width, height); // Get mask display display_mask(mask_buf, display_data, x_center, y_center); // Fly drone is_hover = fly(x_center, y_center, mass); // Print status printf("Frame number: %d\n", frame); printf("Mass: %d; Centroid: (%d, %d)\n", mass, x_center, y_center); printf("Meanshift Width: %d; Height: %d\n", width, height); printf("\033[2J"); gdk_threads_enter(); // GdkPixbuf structures to store the displayed picture static GdkPixbuf *pixbuf = NULL; static GdkPixbuf *maskbuf = NULL; if (pixbuf != NULL) { g_object_unref(pixbuf); pixbuf=NULL; } // Create GdkPixbuf from color frame data pixbuf = gdk_pixbuf_new_from_data(pixbuf_data, GDK_COLORSPACE_RGB, FALSE, // No alpha channel 8, // 8 bits per pixel 320, // Image width 240, 320 * 3, // new pixel every 3 bytes (3channel per pixel) NULL, // Function pointers NULL); // Create the GdkPixbuf from color mask display buffer maskbuf = gdk_pixbuf_new_from_data(display_data, GDK_COLORSPACE_RGB, FALSE, // No alpha channel 8, // 8 bits per pixel 320, // Image width 240, 320 * 3, // new pixel every 3 bytes (3channel per pixel) NULL, // Function pointers NULL); gui_t *gui = get_gui(); // Display the image if (gui && gui->cam) { gtk_image_set_from_pixbuf(GTK_IMAGE(gui->cam), pixbuf); // also display the pixbuf in a second window if (gui->mask_cam) { gtk_image_set_from_pixbuf(GTK_IMAGE(gui->mask_cam), maskbuf); } } gdk_threads_leave(); return (SUCCESS); }