					if(connected_cams>(0+camera_offset)){
						//static int dummy_int=0;
						//dummy_int++;
						sample_number_when_image_asked=sample_number;
						cvGrabFrame( capture0 );
						if(connected_cams>(1+camera_offset))
							cvGrabFrame( capture1 );
						frame0 = cvRetrieveFrame( capture0 );
						if( frame0->origin != IPL_ORIGIN_TL ){
							//cvFlip( frame0, frame0, 0 );
							cvFlip(frame0, frame0,0);
						}
						//cvResetImageROI(big_image);
						if(connected_cams>(1+camera_offset)){
							frame1 = cvRetrieveFrame( capture1 );
						}
						if(connected_cams>(1+camera_offset)){
							if( frame1->origin != IPL_ORIGIN_TL )
								cvFlip( frame1, frame1, 0 );
							
							CvRect rect;
							rect.x=0;
							rect.y=0;
							rect.width=capture_width;
							rect.height=capture_height;
							cvSetImageROI(big_image,rect);
							cvResize(frame0,big_image);
							cvResetImageROI(big_image);
							//	CvRect
							rect.y=capture_height;
							rect.height=2*capture_height;
							cvSetImageROI(big_image,rect);
							cvResize(frame1,big_image);
							cvResetImageROI(big_image);
						}
						else
							cvCopy(frame0,big_image);

						cvShowImage( "Video", big_image );

											//Save images
						if(state=='n'||state=='r'){
							char temp_image_name[60];
							char small_buffer[10];
							strcpy(temp_image_name,cam1_folder);
							strcat(temp_image_name,"/a_");
							itoa(sample_number_when_image_asked,small_buffer,10);
							strcat(temp_image_name,small_buffer);
							strcat(temp_image_name,".jpg");
							if(!cvSaveImage(temp_image_name,big_image)) 
								printf("Could not save: %s\n",temp_image_name);
						}

					}

					




			/*
			if(connected_cams<=(0+camera_offset))
				thread_status=FALSE;//No webcam connected
			//-----------------Thread0 Start------------------------------------
			if(thread_status==TRUE)
			{
				if(consume_data==TRUE){	// Ayto shmainei pws to thread exei ektelestei
					GetExitCodeThread(a_thread, &thread_result);
					//printf("Thread joined, it returned %d\n", thread_result);
					//printf("thread_message is now %s\n", thread_message);
					
					if(connected_cams>(0+camera_offset))
						frame0 = cvRetrieveFrame( capture0 );
					if(connected_cams>(1+camera_offset))
						frame1 = cvRetrieveFrame( capture1 );

					//
					if( frame0->origin != IPL_ORIGIN_TL ){
						//cvFlip( frame0, frame0, 0 );
						cvFlip(frame0, frame0,0);
					}
					cvResetImageROI(big_image);
					//cvShowImage( "cam0", frame0 );
					if(connected_cams>(1+camera_offset)){
						if( frame1->origin != IPL_ORIGIN_TL )
							cvFlip( frame1, frame1, 0 );
						
						CvRect rect;
						rect.x=0;
						rect.y=0;
						rect.width=capture_width;
						rect.height=capture_height;
						cvSetImageROI(big_image,rect);
						cvResize(frame0,big_image);
						cvResetImageROI(big_image);
						//	CvRect
						rect.y=capture_height;
						rect.height=2*capture_height;
						cvSetImageROI(big_image,rect);
						cvResize(frame1,big_image);
						cvResetImageROI(big_image);
					}
					else
						cvCopy(frame0,big_image);
					
					cvShowImage( "Video", big_image );
					
					//Save images
					if(state=='n'||state=='r'){
						char temp_image_name[60];
						char small_buffer[10];
						strcpy(temp_image_name,cam1_folder);
						strcat(temp_image_name,"/a_");
						itoa(sample_number_when_image_asked,small_buffer,10);
						strcat(temp_image_name,small_buffer);
						strcat(temp_image_name,".jpg");
						if(!cvSaveImage(temp_image_name,big_image)) 
							printf("Could not save: %s\n",temp_image_name);
					}

					//

				}//(consume0_data==TRUE)
				//------------------------thread create----------------------------
				// Create a new thread.
				thread_status=FALSE;
				consume_data=FALSE;
				strcpy(thread_message,"eaa");
				sample_number_when_image_asked=sample_number;

				if(connected_cams>(0+camera_offset))
					cvGrabFrame( capture0 );
				if(connected_cams>(1+camera_offset))
					cvGrabFrame( capture1 );	

				a_thread = CreateThread(NULL, 0, thread_function, (PVOID)thread_message,0, &a_threadId);

				if (a_thread == NULL) {
					perror("Thread creation failed");
					exit(EXIT_FAILURE);
				}//(a_thread0 == NULL)
			}//-----------------Thread0 end------------------------------------
			*/