p/videojoiner/VideoJoiner.cpp
///************************Funcion para seleccionar los puntos de las esquinas en cada video
Funcion para seleccionar los puntos de las esquinas en cada video
Funcion para seleccionar los puntos de las esquinas en cada video
int SelectSingleVideoCorners(void)
{
	cout << "-== Single video point selection mode ==-" << endl;
	cout << ".:: Working on LEFT video ::." << endl;
	cout << "Select corners on left video..." << endl;
	namedWindow( "Display video", CV_WINDOW_NORMAL | CV_GUI_NORMAL);
	Mat frame;
	setMouseCallback("Display video", mouseEventSource, &frame);
	frame=vlh.GetFrame(yp.joiner_parms["start_frame"]);
	int corner = TOP_LEFT;
	while( corner < 4 )
	{
		cout << "Select the " << corners[corner] << " corner.." << endl;
		imshow("Display video", frame);
		int key = waitKey(0);
		if(key == yp.joiner_parms["enter_key"] and (mpt.x not_eq 0) and (mpt.y not_eq 0)){
			spt.x=mpt.x; spt.y=mpt.y;
			if(corner==TOP_LEFT){
				cout << "top left captured" << endl;
				yp.joiner_parms["left_video_top_left_x"]=(int)spt.x;
				yp.joiner_parms["left_video_top_left_y"]=(int)spt.y;
			}
			else if(corner==TOP_RIGHT){
				cout << "top right captured" << endl;
				yp.joiner_parms["left_video_top_right_x"]=(int)spt.x;
				yp.joiner_parms["left_video_top_right_y"]=(int)spt.y;
			}
			else if(corner==BOTTOM_LEFT){
				cout << "bottom left captured" << endl;
				yp.joiner_parms["left_video_bottom_left_x"]=(int)spt.x;
				yp.joiner_parms["left_video_bottom_left_y"]=(int)spt.y;
			}				
			else if(corner==BOTTOM_RIGHT){
				cout << "bottom right captured" << endl;
				yp.joiner_parms["left_video_bottom_right_x"]=(int)spt.x;
				yp.joiner_parms["left_video_bottom_right_y"]=(int)spt.y;
			}
			else
				cout << "No more corners to select" << endl;
			mpt.x=0.0;mpt.y=0.0;
			corner++;
		}
		else if(key == yp.joiner_parms["safe_key"]){
			cout << "Saving selected points" << endl;
			yp.StoreJoinerConfig(config_file,yp.joiner_parms);
			return 0;
		}
		else if(key == yp.joiner_parms["quit_key"]){
			cout << "Closing program" << endl;
			return 0;
		}
		else{
			cout << "Key pressed: " << key << endl;	
		}
	}
	cout << ".:: Working on RIGHT video ::." << endl;	
	cout << "Select corners on right video" << endl;
	frame=vrh.GetFrame(yp.joiner_parms["start_frame"]);
	corner = TOP_LEFT;
	while( corner < 4 )
	{
		cout << "Select the " << corners[corner] << " corner.. " << endl;
		imshow("Display video", frame);
		int key = waitKey(0);
		if(key == yp.joiner_parms["enter_key"] and (mpt.x not_eq 0) and (mpt.y not_eq 0)){
			spt.x=mpt.x; spt.y=mpt.y;
			if(corner==TOP_LEFT){
				cout << "Top right captured" << endl;
				yp.joiner_parms["right_video_top_left_x"]=(int)spt.x;
				yp.joiner_parms["right_video_top_left_y"]=(int)spt.y;
			}
			else if(corner==TOP_RIGHT){
				cout << "Top right captured" << endl;
				yp.joiner_parms["right_video_top_right_x"]=(int)spt.x;
				yp.joiner_parms["right_video_top_right_y"]=(int)spt.y;
			}
			else if(corner==BOTTOM_LEFT){
				cout << "Bottom left captured" << endl;
				yp.joiner_parms["right_video_bottom_left_x"]=(int)spt.x;
				yp.joiner_parms["right_video_bottom_left_y"]=(int)spt.y;
			}				
			else if(corner==BOTTOM_RIGHT){
				cout << "bottom right captured" << endl;
				yp.joiner_parms["right_video_bottom_right_x"]=(int)spt.x;
				yp.joiner_parms["right_video_bottom_right_y"]=(int)spt.y;
			}
			else
				cout << "No more corners to select" << endl;
			mpt.x=0.0;mpt.y=0.0;
			corner++;
		}
		else if(key == yp.joiner_parms["safe_key"]){
			cout << "Saving selected points" << endl;
			yp.StoreJoinerConfig(config_file,yp.joiner_parms);
			return 0;
		}
		else if(key == yp.joiner_parms["quit_key"]){
			cout << "Closing program" << endl;
			return 0;
		}
		else
			cout << "Key pressed: " << key << endl;	
	}
	destroyAllWindows();
	int run = TRUE;
	while (run) {
		string answer = "N";
		cout << "Save selected points as corners for videos? (y/N)" << endl;
		getline(cin, answer);
		if (answer.length() == 1) {
			if(answer[0] == 'n')
				run = FALSE;
			else if(answer[0] == 'y'){
				yp.StoreJoinerConfig(config_file,yp.joiner_parms);
				run = FALSE;
			}
			else{
				cout << "Invalid character " << answer << ", please try again" << endl;		
				run = TRUE;
			}
		}
	}	
	cout << "No more corners to select, start next time with the selection mode off" << endl;
	return 0;			
}
int SelectSingleVideoCorners ( void ) { cout << " " << endl ; cout << " " << endl ; cout << " " << endl ; namedWindow ( " " , CV_WINDOW_NORMAL | CV_GUI_NORMAL ) ; Mat frame ; setMouseCallback ( " " , mouseEventSource , & frame ) ; frame = vlh . GetFrame ( yp . joiner_parms [ " " ] ) ; int corner = TOP_LEFT ; while ( corner < 4 ) { cout << " " << corners [ corner ] << " " << endl ; imshow ( " " , frame ) ; int key = waitKey ( 0 ) ; if ( key == yp . joiner_parms [ " " ] and ( mpt . x not_eq 0 ) and ( mpt . y not_eq 0 ) ) { spt . x = mpt . x ; spt . y = mpt . y ; if ( corner == TOP_LEFT ) { cout << " " << endl ; yp . joiner_parms [ " " ] = ( int ) spt . x ; yp . joiner_parms [ " " ] = ( int ) spt . y ; } else if ( corner == TOP_RIGHT ) { cout << " " << endl ; yp . joiner_parms [ " " ] = ( int ) spt . x ; yp . joiner_parms [ " " ] = ( int ) spt . y ; } else if ( corner == BOTTOM_LEFT ) { cout << " " << endl ; yp . joiner_parms [ " " ] = ( int ) spt . x ; yp . joiner_parms [ " " ] = ( int ) spt . y ; } else if ( corner == BOTTOM_RIGHT ) { cout << " " << endl ; yp . joiner_parms [ " " ] = ( int ) spt . x ; yp . joiner_parms [ " " ] = ( int ) spt . y ; } else cout << " " << endl ; mpt . x = 0.0 ; mpt . y = 0.0 ; corner ++ ; } else if ( key == yp . joiner_parms [ " " ] ) { cout << " " << endl ; yp . StoreJoinerConfig ( config_file , yp . joiner_parms ) ; return 0 ; } else if ( key == yp . joiner_parms [ " " ] ) { cout << " " << endl ; return 0 ; } else { cout << " " << key << endl ; } } cout << " " << endl ; cout << " " << endl ; frame = vrh . GetFrame ( yp . joiner_parms [ " " ] ) ; corner = TOP_LEFT ; while ( corner < 4 ) { cout << " " << corners [ corner ] << " " << endl ; imshow ( " " , frame ) ; int key = waitKey ( 0 ) ; if ( key == yp . joiner_parms [ " " ] and ( mpt . x not_eq 0 ) and ( mpt . y not_eq 0 ) ) { spt . x = mpt . x ; spt . y = mpt . y ; if ( corner == TOP_LEFT ) { cout << " " << endl ; yp . joiner_parms [ " " ] = ( int ) spt . x ; yp . joiner_parms [ " " ] = ( int ) spt . y ; } else if ( corner == TOP_RIGHT ) { cout << " " << endl ; yp . joiner_parms [ " " ] = ( int ) spt . x ; yp . joiner_parms [ " " ] = ( int ) spt . y ; } else if ( corner == BOTTOM_LEFT ) { cout << " " << endl ; yp . joiner_parms [ " " ] = ( int ) spt . x ; yp . joiner_parms [ " " ] = ( int ) spt . y ; } else if ( corner == BOTTOM_RIGHT ) { cout << " " << endl ; yp . joiner_parms [ " " ] = ( int ) spt . x ; yp . joiner_parms [ " " ] = ( int ) spt . y ; } else cout << " " << endl ; mpt . x = 0.0 ; mpt . y = 0.0 ; corner ++ ; } else if ( key == yp . joiner_parms [ " " ] ) { cout << " " << endl ; yp . StoreJoinerConfig ( config_file , yp . joiner_parms ) ; return 0 ; } else if ( key == yp . joiner_parms [ " " ] ) { cout << " " << endl ; return 0 ; } else cout << " " << key << endl ; } destroyAllWindows ( ) ; int run = TRUE ; while ( run ) { string answer = " " ; cout << " " << endl ; getline ( cin , answer ) ; if ( answer . length ( ) == 1 ) { if ( answer [ 0 ] == ' ' ) run = FALSE ; else if ( answer [ 0 ] == ' ' ) { yp . StoreJoinerConfig ( config_file , yp . joiner_parms ) ; run = FALSE ; } else { cout << " " << answer << " " << endl ; run = TRUE ; } } } cout << " " << endl ; return 0 ; }
Funcion para seleccionar los puntos de las esquinas en cada video
Funcion para seleccionar los puntos de las esquinas en cada video
/// Create display Window /// Set the callback function for any mouse event on source frame /// Read frame of left video //cout << "Umm " << yp.joiner_parms["save_key"] << endl; /// Read frame of right video