Ejemplo n.º 1
1
int main()
{
	int i;
	struct picture_t pic;
	struct encoded_pic_t encoded_pic;
	errno = 0;
	if(!camera_init(&pic))
		goto error_cam;
	if(!encoder_init(&pic)){
		fprintf(stderr,"failed to initialize encoder\n");
		goto error_encoder;
	}
	if(!preview_init(&pic))
		goto error_preview;
	if(!output_init(&pic))
		goto error_output;
	if(!encoder_encode_headers(&encoded_pic))
		goto error_output;
	if(!output_write_headers(&encoded_pic))
		goto error_output;
	if(!camera_on())
		goto error_cam_on;
	if(signal(SIGINT, stop_recording) == SIG_ERR){
		fprintf(stderr,"signal() failed\n");
		goto error_signal;
	}
	printf("Press ctrl-c to stop recording...\n");
	recording = 1;
	for(i=0; recording; i++){
		if(!camera_get_frame(&pic))
			break;
		gen_osd_info();
		osd_print(&pic, osd_string);
		if((i&7)==0) // i%8==0
			preview_display(&pic);
		if(!encoder_encode_frame(&pic, &encoded_pic))
			break;
		applog_flush();
		if(!output_write_frame(&encoded_pic))
			break;
	}
	printf("\nrecorded %d frames\n", i);

error_signal:
	camera_off();
error_cam_on:
	output_close();
error_output:
	preview_close();
error_preview:
	encoder_close();
error_encoder:
	camera_close();
error_cam:
	return 0;
}
Ejemplo n.º 2
1
void *cam_thread()  
{  	
	int number,FileSize;
	number=0;
	FileSize =0; 
	fd_set fds;  
    struct timeval tv;  
    int r;
    printf ("cam_thread : I'm thread 1\n");
	while (!g_s32Quit) 
		{		
			/* Timeout. */  
			tv.tv_sec = 0;  
			tv.tv_usec = 33333;  
			nanosleep(&tv,NULL);
			if(!camera_get_frame(&pic)){
				printf("error1\r\n");
				break;
			}	
			gen_osd_info();
			osd_print(&pic, osd_string);
			if(!encoder_encode_frame(&pic, &encoded_pic))
				break;
			FileSize+=encoded_pic.length;
			if(g_s32DoPlay>0)
				ringput(encoded_pic.buffer,encoded_pic.length,encoded_pic.frame_type);
			if ((FileSize>MAX_SIZE) && (encoded_pic.frame_type ==FRAME_TYPE_I)) {
				output_close();	
				get_filename();
				printf("file:%s\n",mkv_filename);
				if(!output_init(&pic,mkv_filename))
					break;
				if(!output_write_headers(&header_pic,&psp))
					break;
				FileSize=0;
				ResetTime(&pic,&encoded_pic);
				if(!output_write_frame(&encoded_pic))
					break;
				encoder_release(&encoded_pic);
			} else {
				if(!output_write_frame(&encoded_pic))
					break;
				encoder_release(&encoded_pic);
				}
		}

	printf("exit the enc_thread\n");
	g_s32Quit= 0;
    //pthread_exit(NULL);  
} 
void* videoFrame(void){
	int cnt = 0;
	
	VideoCopy black;
		
	
	while(1){
		vidbuf = camera_get_frame(fdCamera);
		
		memcpy(vidbuf_overlay.ycbcr.y,vidbuf->ycbcr.y,len_vidbuf);
		memcpy(vidbuf_overlay.ycbcr.cb,vidbuf->ycbcr.cb,len_vidbuf/2);
		memcpy(vidbuf_overlay.ycbcr.cr,vidbuf->ycbcr.cr,len_vidbuf/2);
		
		memcpy(bufCopy.ycbcr.y,vidbuf->ycbcr.y,len_vidbuf);
		memcpy(bufCopy.ycbcr.cb,vidbuf->ycbcr.cb,len_vidbuf/2);
		memcpy(bufCopy.ycbcr.cr,vidbuf->ycbcr.cr,len_vidbuf/2);
		
		camera_release_frame(fdCamera,vidbuf);
			
		if(stopflag == 1)
			break;
	}
	
	camera_stop(fdCamera);
	camera_close(fdCamera);
}
Ejemplo n.º 4
0
// Caculate direction and produce command value
void refreshImage(void) {
	//get frame from cam
	vidbuf = camera_get_frame(fdCamera);
	usleep(3000000); // delay 3sec
	camera_release_frame(fdCamera, vidbuf);
	vidbuf = camera_get_frame(fdCamera);

	//copy frame to var
	memcpy(vidbuf_overlay.ycbcr.y, vidbuf->ycbcr.y,len_vidbuf);
	memcpy(vidbuf_overlay.ycbcr.cb, vidbuf->ycbcr.cb,len_vidbuf/2);
	memcpy(vidbuf_overlay.ycbcr.cr, vidbuf->ycbcr.cr,len_vidbuf/2);
	
	memcpy(bufCopy.ycbcr.y,vidbuf->ycbcr.y,len_vidbuf);
    memcpy(bufCopy.ycbcr.cb,vidbuf->ycbcr.cb,len_vidbuf/2);
    memcpy(bufCopy.ycbcr.cr,vidbuf->ycbcr.cr,len_vidbuf/2);
   
	// !!essential!!
	// put image to screen & clean buffer 
	camera_release_frame(fdCamera, vidbuf);
}
Ejemplo n.º 5
0
void* videoFrame(void){
	int cnt = 0;
	while(1){
		vidbuf = camera_get_frame(fdCamera);
	
		memcpy(bufCopy.ycbcr.y,vidbuf->ycbcr.y,len_vidbuf);
		memcpy(bufCopy.ycbcr.cb,vidbuf->ycbcr.cb,len_vidbuf/2);
		memcpy(bufCopy.ycbcr.cr,vidbuf->ycbcr.cr,len_vidbuf/2);
		
		camera_release_frame(fdCamera,vidbuf);

	}
}
Ejemplo n.º 6
0
void copyImage()
{
    vidbuf = camera_get_frame(fdCamera);
		
    memcpy(vidbuf_overlay.ycbcr.y,vidbuf->ycbcr.y,len_vidbuf);
    memcpy(vidbuf_overlay.ycbcr.cb,vidbuf->ycbcr.cb,len_vidbuf/2);
    memcpy(vidbuf_overlay.ycbcr.cr,vidbuf->ycbcr.cr,len_vidbuf/2);
    
    memcpy(bufCopy.ycbcr.y,vidbuf->ycbcr.y,len_vidbuf);
    memcpy(bufCopy.ycbcr.cb,vidbuf->ycbcr.cb,len_vidbuf/2);
    memcpy(bufCopy.ycbcr.cr,vidbuf->ycbcr.cr,len_vidbuf/2);
    
    camera_release_frame(fdCamera,vidbuf);
}
Ejemplo n.º 7
0
void screenFoundObject()
{
	int i=0, j=0, index;
	for(i = minX; i<maxX; i++){
		for(j = minY; j<maxY; j++){
			index = i*320+j;
			vidbuf = camera_get_frame(fdCamera);
			//copy frame to var
			vidbuf->ycbcr.y[index] = 100;
			vidbuf->ycbcr.cb[index/2] = 20;
			vidbuf->ycbcr.cr[index/2] = 200;			
		}
	}
}
Ejemplo n.º 8
0
void* videoFrame(void){
	int cnt = 0;
	while(1){
		vidbuf = camera_get_frame(fdCamera);
		
		memcpy(vidbuf_overlay.ycbcr.y,vidbuf->ycbcr.y,len_vidbuf);
		memcpy(vidbuf_overlay.ycbcr.cb,vidbuf->ycbcr.cb,len_vidbuf/2);
		memcpy(vidbuf_overlay.ycbcr.cr,vidbuf->ycbcr.cr,len_vidbuf/2);
		
		memcpy(bufCopy.ycbcr.y,vidbuf->ycbcr.y,len_vidbuf);
		memcpy(bufCopy.ycbcr.cb,vidbuf->ycbcr.cb,len_vidbuf/2);
		memcpy(bufCopy.ycbcr.cr,vidbuf->ycbcr.cr,len_vidbuf/2);
		
		camera_release_frame(fdCamera,vidbuf);
			
		if(stopFlag == 1)
			break;
		/*
		if(obj.x_point >=0 && obj.x_point <320 && obj.y_point >=0 && obj.y_point < 240){
		 
		  
		  int i, j;
		  for(i  = obj.x_point; i<obj.x_point + 10; i++){
		   for(j = obj.y_point; j<obj.y_point + 10; j++){
		      int index = j*320 + i;
		       
		   
		      vidbuf_overlay.ycbcr.y[index] = 120;
		      vidbuf_overlay.ycbcr.cb[index/2] = 230;
		      vidbuf_overlay.ycbcr.cr[index/2] = 30;
		      
		    
		   }
		  }
		  
		}
		*/
	}
	
	camera_stop(fdCamera);
	camera_close(fdCamera);
}
void map_read(void){
	sleep(2);

	//vals
	int i, timecount;
	//thread vals
	pthread_t netReadThread;
	int thread_id;

	timecount = 0;
	


	//malloc project vals
	vProjection = (int*)malloc(sizeof(int)*cImg.width);

	//netReadThread start
//	pthread_create(&netReadThread, NULL, netReadThreadFunc, (void*)NULL);
	//pre();
	while(1){
		//get frame from cam
		vidbuf = camera_get_frame(fdCamera);

		//copy frame to var
		memcpy(vidbuf_overlay.ycbcr.y,vidbuf->ycbcr.y,len_vidbuf);
		memcpy(vidbuf_overlay.ycbcr.cb,vidbuf->ycbcr.cb,len_vidbuf/2);
		memcpy(vidbuf_overlay.ycbcr.cr,vidbuf->ycbcr.cr,len_vidbuf/2);
		
		if( timecount < 81 ) {
			timecount++;

			//init mode
			if( timecount == 50 ){
				command = 26;
			}
			//turn head
			else if ( timecount == 55){
				#ifdef SERVERMODE
				command = 1;				
				makeImg (&cImg, 1, 0, &vidbuf_overlay);				
				#endif
				#ifdef CLIENTMODE
				command = 3;
				makeImg (&cImg, 0, 1, &vidbuf_overlay);				
				#endif		
			}
			//return head
			else if ( timecount == 70){
				#ifdef SERVERMODE
				command = 3;
				makeImg (&cImg, 0, 1, &vidbuf_overlay);
				#endif
				#ifdef CLIENTMODE
				command = 1;
				makeImg (&cImg, 1, 0, &vidbuf_overlay);				
				#endif
			}
			//print img to lcd
			else if ( timecount == 80 ){
				command = 2;
				//vertical projection
				//labeling();
				//printf("labling complete!!");
				integrateImg(&cImg, &vidbuf_overlay);
				printf("Image Integrating complete!!");
				//stereo(boundary, recBoundary, heights, recHeights, cordinate);
				//printf("stereo complete!!");
				sleep(3);
			}
		}
		camera_release_frame(fdCamera,vidbuf);
		if( timecount >= 80 ) 
			break;
	}

	free(vProjection);
	return 0;
}