diff --git a/.gitignore b/.gitignore index 567609b..7907dac 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ build/ +deps/ +3rdparty/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..fb61c26 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,12 @@ +{ + "files.associations": { + "*.lp": "plaintext", + "*.dat": "gmpl", + "ostream": "cpp", + "*.ipp": "cpp", + "cmath": "cpp", + "complex": "cpp", + "vector": "cpp", + "iostream": "cpp" + } +} \ No newline at end of file diff --git a/src/tp/checkerboard.cpp b/src/tp/checkerboard.cpp index 8789b83..b722ef7 100644 --- a/src/tp/checkerboard.cpp +++ b/src/tp/checkerboard.cpp @@ -13,14 +13,13 @@ using namespace cv; using namespace std; - // Display the help for the programm -void help( const char* programName ); +void help(const char *programName); // parse the input command line arguments -bool parseArgs( int argc, char**argv, Size &boardSize, string &inputFilename, Pattern &pattern ); +bool parseArgs(int argc, char **argv, Size &boardSize, string &inputFilename, Pattern &pattern); -int main( int argc, char** argv ) +int main(int argc, char **argv) { /******************************************************************/ /* CONSTANTS to use */ @@ -29,14 +28,12 @@ int main( int argc, char** argv ) // the name of the window const string WINDOW_NAME = "Image View"; - /******************************************************************/ /* VARIABLES TO use */ /******************************************************************/ Mat view; // it will contain the original image loaded from file - vector pointbuf; // it will contain the detected corners on the chessboard bool found; // it will be true if a chessboard is found, false otherwise @@ -50,21 +47,16 @@ int main( int argc, char** argv ) // Default pattern is chessboard Pattern pattern = CHESSBOARD; - - /******************************************************************/ /* READ THE INPUT PARAMETERS - DO NOT MODIFY */ /******************************************************************/ - if( !parseArgs( argc, argv, boardSize, inputFilename, pattern ) ) + if (!parseArgs(argc, argv, boardSize, inputFilename, pattern)) { cerr << "Aborting..." << endl; return EXIT_FAILURE; } - - - /******************************************************************/ /* PART TO DEVELOP */ /******************************************************************/ @@ -72,105 +64,104 @@ int main( int argc, char** argv ) /******************************************************************/ // create a window to display the image --> see namedWindow /******************************************************************/ - + namedWindow(WINDOW_NAME, WINDOW_AUTOSIZE); /******************************************************************/ // read the input image from file into "view" --> see imread /******************************************************************/ + view = imread(inputFilename, CV_LOAD_IMAGE_COLOR); - - //Measure the execution time, get time before function call - auto t = ( double ) getTickCount( ); + // Measure the execution time, get time before function call + auto t = (double)getTickCount(); /******************************************************************/ // call the function that detects the chessboard on the image // found = detectChessboard... /******************************************************************/ - + found = detectChessboard(view, pointbuf, boardSize, pattern); // get time after function call and display info - t = ( ( double ) getTickCount( ) - t ) / getTickFrequency( ); + t = ((double)getTickCount() - t) / getTickFrequency(); - cout << ( ( !found ) ? ( "No " ) : ( "" ) ) << "chessboard detected!" << endl; + cout << ((!found) ? ("No ") : ("")) << "chessboard detected!" << endl; cout << "Chessboard detection took " << t * 1000 << "ms" << endl; - /******************************************************************/ // if the chessboard is found draw the cornerns on top of it // --> see drawChessboardCorners /******************************************************************/ - + if (found) + { + drawChessboardCorners(view, boardSize, Mat(pointbuf), found); + } /******************************************************************/ // show the image inside the window --> see imshow /******************************************************************/ - + imshow(WINDOW_NAME, view); // wait for user input before ending --> see waitKey - waitKey( -1 ); - + waitKey(-1); return EXIT_SUCCESS; } - // Display the help for the programm -void help( const char* programName ) +void help(const char *programName) { cout << "Detect a chessboard in a given image" << endl - << "Usage: " << programName << endl - << " -w # the number of inner corners per one of board dimension" << endl - << " -h # the number of inner corners per another board dimension" << endl - << " [-pt ] # the type of pattern: chessboard or circles' grid" << endl - << " " << endl - << endl; + << "Usage: " << programName << endl + << " -w # the number of inner corners per one of board dimension" << endl + << " -h # the number of inner corners per another board dimension" << endl + << " [-pt ] # the type of pattern: chessboard or circles' grid" << endl + << " " << endl + << endl; } // parse the input command line arguments -bool parseArgs( int argc, char**argv, Size &boardSize, string &inputFilename, Pattern &pattern ) +bool parseArgs(int argc, char **argv, Size &boardSize, string &inputFilename, Pattern &pattern) { // check the minimum number of arguments - if( argc < 3 ) + if (argc < 3) { - help( argv[0] ); + help(argv[0]); return false; } - // Read the input arguments - for( int i = 1; i < argc; i++ ) + for (int i = 1; i < argc; i++) { - const char* s = argv[i]; - if( strcmp( s, "-w" ) == 0 ) + const char *s = argv[i]; + if (strcmp(s, "-w") == 0) { - if( sscanf( argv[++i], "%u", &boardSize.width ) != 1 || boardSize.width <= 0 ) + if (sscanf(argv[++i], "%u", &boardSize.width) != 1 || boardSize.width <= 0) { cerr << "Invalid board width" << endl; return false; } } - else if( strcmp( s, "-h" ) == 0 ) + else if (strcmp(s, "-h") == 0) { - if( sscanf( argv[++i], "%u", &boardSize.height ) != 1 || boardSize.height <= 0 ) + if (sscanf(argv[++i], "%u", &boardSize.height) != 1 || boardSize.height <= 0) { cerr << "Invalid board height" << endl; return false; } } - else if( s[0] != '-' ) + else if (s[0] != '-') { - inputFilename.assign( s ); + inputFilename.assign(s); } - else if( strcmp( s, "-pt" ) == 0 ) + else if (strcmp(s, "-pt") == 0) { i++; - if( !strcmp( argv[i], "circles" ) ) + if (!strcmp(argv[i], "circles")) pattern = CIRCLES_GRID; - else if( !strcmp( argv[i], "acircles" ) ) + else if (!strcmp(argv[i], "acircles")) pattern = ASYMMETRIC_CIRCLES_GRID; - else if( !strcmp( argv[i], "chess" ) ) + else if (!strcmp(argv[i], "chess")) pattern = CHESSBOARD; else { @@ -187,4 +178,3 @@ bool parseArgs( int argc, char**argv, Size &boardSize, string &inputFilename, Pa return true; } - diff --git a/src/tp/checkerboardvideo.cpp b/src/tp/checkerboardvideo.cpp index 9ae9216..39f783e 100644 --- a/src/tp/checkerboardvideo.cpp +++ b/src/tp/checkerboardvideo.cpp @@ -14,12 +14,12 @@ using namespace cv; using namespace std; // Display the help for the program -void help( const char* programName ); +void help(const char *programName); // parse the input command line arguments -bool parseArgs( int argc, char**argv, Size &boardSize, string &inputFilename, Pattern &pattern ); +bool parseArgs(int argc, char **argv, Size &boardSize, string &inputFilename, Pattern &pattern); -int main( int argc, char** argv ) +int main(int argc, char **argv) { /******************************************************************/ /* CONSTANTS to use */ @@ -48,163 +48,157 @@ int main( int argc, char** argv ) // Used to load the video and get the frames VideoCapture capture; - - /******************************************************************/ /* READ THE INPUT PARAMETERS - DO NOT MODIFY */ /******************************************************************/ - if( !parseArgs( argc, argv, boardSize, inputFilename, pattern ) ) + if (!parseArgs(argc, argv, boardSize, inputFilename, pattern)) { cerr << "Aborting..." << endl; return EXIT_FAILURE; } - - - /******************************************************************/ - /* PART TO DEVELOP */ + /* PART TO DEVELOP */ /******************************************************************/ - - /******************************************************************/ // create a window to display the image --> see namedWindow /******************************************************************/ - + namedWindow(WINDOW_NAME, CV_WINDOW_AUTOSIZE); /******************************************************************/ // read the input video with capture /******************************************************************/ - + capture.open(inputFilename); /******************************************************************/ // check it is really opened /******************************************************************/ - - - - - - - + if (!capture.isOpened()) + { + cerr << "Could not open the video file " << inputFilename << endl; + return EXIT_FAILURE; + } // processing loop - while(true) + while (true) { - Mat view; + Mat frame; /******************************************************************/ - // get the new frame from capture and copy it to view + // get the new frame from capture and copy it to frame /******************************************************************/ - + capture >> frame; + // capture.retrieve(frame); /******************************************************************/ // if no more images to process exit the loop /******************************************************************/ + if (frame.empty()) + { + break; + } - - - //Measure the execution time, get time before function call - auto t = ( double ) getTickCount( ); + // Measure the execution time, get time before function call + auto t = (double)getTickCount(); /******************************************************************/ // call the function that detects the chessboard on the image // found = detectChessboard... /******************************************************************/ - + found = detectChessboard(frame, pointbuf, boardSize, pattern); // get time after function call and display info - t = ( ( double ) getTickCount( ) - t ) / getTickFrequency( ); + t = ((double)getTickCount() - t) / getTickFrequency(); - cout << ( ( !found ) ? ( "No " ) : ( "" ) ) << "chessboard detected!" << endl; + cout << ((!found) ? ("No ") : ("")) << "chessboard detected!" << endl; cout << "Chessboard detection took " << t * 1000 << "ms" << endl; /******************************************************************/ // if the chessboard is found draw the corners on top of it // --> see drawChessboardCorners /******************************************************************/ - + if (found) + { + drawChessboardCorners(frame, boardSize, Mat(pointbuf), found); + } /******************************************************************/ // show the image inside the window --> see imshow /******************************************************************/ - + imshow(WINDOW_NAME, frame); // wait 20ms for user input before processing the next frame // Any user input will stop the execution - if( waitKey( 10 ) >= 0 ) + if (waitKey(10) >= 0) + { break; - + } } /******************************************************************/ // release the video resource /******************************************************************/ - - return EXIT_SUCCESS; } - // Display the help for the program -void help( const char* programName ) +void help(const char *programName) { cout << "Detect a chessboard in a given video" << endl - << "Usage: " << programName << endl - << " -w # the number of inner corners per one of board dimension" << endl - << " -h # the number of inner corners per another board dimension" << endl - << " [-pt ] # the type of pattern: chessboard or circles' grid" << endl - << "