void* camera_action(void* parameters) { struct arguments* p = (struct arguments*) parameters; Set_Up_Camera(); Capture(&My_Buffer); thresholded=threshold(My_Buffer,Width,Height,refR_YELLOW,refG_YELLOW,refB_YELLOW,disD_YELLOW,refR_RED,refG_RED,refB_RED,disD_RED); make_bmp(My_Buffer,"Img1",Width,Height); make_bmp(thresholded,"Img2",Width,Height); find_XY(My_Buffer,Width,Height,refR_YELLOW,refG_YELLOW,refB_YELLOW,disD_YELLOW,&x_YELLOW,&y_YELLOW,refR_RED,refG_RED,refB_RED,disD_RED,&x_RED,&y_RED); p->curr_x=x_YELLOW; p->curr_y=y_YELLOW; p->prev_x=x_YELLOW; p->prev_y=y_YELLOW; while(1) { lock1=1; p->prev_x=p->curr_x; p->prev_y=p->curr_y; Capture(&My_Buffer); find_XY(My_Buffer,Width,Height,refR_YELLOW,refG_YELLOW,refB_YELLOW,disD_YELLOW,&x_YELLOW,&y_YELLOW,refR_RED,refG_RED,refB_RED,disD_RED,&x_RED,&y_RED); p->curr_x=x_YELLOW; p->curr_y=y_YELLOW; lock1=0; //printf("(%d,%d,%d,%d)\n",x_YELLOW,y_YELLOW,x_RED,y_RED); //handle_clicks(); if(abs(x_YELLOW-x_RED)<70&&abs(y_YELLOW-y_RED)<70&&left_pressed==0&&y_YELLOW>y_RED) { report_left_mouse_press(); printf("Mouse Pressed\n"); left_pressed=1; } if((!(abs(x_YELLOW-x_RED)<70&&abs(y_YELLOW-y_RED)<70)&&y_YELLOW>y_RED)&&left_pressed==1) { report_left_mouse_released(); printf("Mouse Released\n"); left_pressed=0; } usleep(200000); } return NULL; }
void *stream_func(void *ptr) { unsigned char *rgb_buffer; int ready_buf; char cur_name[64]; int i; if( b_shared_mem ) { rgb_buffer = p_shm; } else { rgb_buffer = (unsigned char *)malloc(req_width*req_height*3); } for(i=0; i<total_buffers; i++) { queue_buffer(i); } for(;;) { /* get the idx of ready buffer */ for(i=0; i<total_buffers; i++) { /* Check if the thread should stop. */ if( stream_finish ) return NULL; ready_buf = dequeue_buffer(); if( b_verbose ) { printf("Buffer %d ready. Length: %uB\n", ready_buf, image_buffers[ready_buf].length); } switch( check_pixelformat() ) { case V4L2_PIX_FMT_YUYV: /* convert data to rgb */ if( b_shared_mem ) sem_down(&shm_sem); if( convert_yuv_to_rgb_buffer( (unsigned char *)(image_buffers[ready_buf].start), rgb_buffer, req_width, req_height) == 0 ) { if( b_verbose ) { printf("\tConverted to rgb.\n"); } } if( b_shared_mem ) sem_up(&shm_sem); break; default: print_pixelformat(stderr); fprintf(stderr,"\n"); return NULL; } /* make the image */ /* create the file name */ if( b_named_pipe ) sprintf(cur_name, "%s", psz_named_pipe); switch( e_outfmt ) { case FORMAT_BMP: if( b_shared_mem ) { printf("Unsupported!\n"); break; } make_bmp(rgb_buffer, cur_name, req_width, req_height); break; case FORMAT_RGB: if( b_shared_mem ) { /* The buffer is already rgb :) */ break; } make_rgb(rgb_buffer, cur_name, req_width, req_height); break; default: fprintf(stderr, "Not supported format requested!\n"); break; } queue_buffer(ready_buf); } } return NULL; }
void *capture_func(void *ptr) { unsigned char *rgb_buffer; int ready_buf; char cur_name[64]; int i; struct timeval timestamp; if( b_shared_mem ) { rgb_buffer = p_shm; } else { rgb_buffer = (unsigned char *)malloc(req_width*req_height*3); } for(;;) { /* Wait for the start condition */ pthread_mutex_lock(&cond_mutex); pthread_cond_wait(&condition, &cond_mutex); pthread_mutex_unlock(&cond_mutex); /* queue one buffer and 'refresh it' */ /* @todo Change 2 to some #define */ for(i=0; i<2; i++) { queue_buffer(i); } for(i=0; i<2 - 1; i++) { dequeue_buffer(); } /* get the idx of ready buffer */ ready_buf = dequeue_buffer(); if( b_verbose ) { printf("Buffer %d ready. Length: %uB\n", ready_buf, image_buffers[ready_buf].length); } switch( check_pixelformat() ) { case V4L2_PIX_FMT_YUYV: /* convert data to rgb */ if( convert_yuv_to_rgb_buffer( (unsigned char *)(image_buffers[ready_buf].start), rgb_buffer, req_width, req_height) == 0 ) { if( b_verbose ) { printf("\tConverted to rgb.\n"); } } break; default: print_pixelformat(stderr); fprintf(stderr,"\n"); return NULL; } timestamp = query_buffer(0); /* make the image */ /* create the file name */ if( b_named_filename ) { sprintf(cur_name, "%s%s", psz_output_dir, psz_output_filename); } else if( !b_named_pipe ) sprintf(cur_name, "%scamshot_%lu.bmp", psz_output_dir, timestamp.tv_sec); else sprintf(cur_name, "%s", psz_named_pipe); switch( e_outfmt ) { case FORMAT_BMP: make_bmp(rgb_buffer, cur_name, req_width, req_height); break; case FORMAT_RGB: make_rgb(rgb_buffer, cur_name, req_width, req_height); break; default: fprintf(stderr, "Not supported format requested!\n"); break; } } return NULL; }