diff --git a/.gitignore b/.gitignore index a01ee28..46d48be 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.*.swp +*.swp +desfournorm* diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0911bc5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required (VERSION 2.8) +project(miniprojet) + +set(PROJECT_CFLAGS "-Wall -Wextra -Wno-missing-braces -std=c++1z") +find_package(OpenCV REQUIRED) + +add_subdirectory(src) +add_subdirectory(examples) + diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..edfba88 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,17 @@ +include_directories (${CMAKE_SOURCE_DIR}/src) + +file( + GLOB + usage_examples + *.cpp +) + +foreach(f ${usage_examples}) + get_filename_component(exampleName ${f} NAME_WE) + add_executable(${exampleName} ${f}) + target_link_libraries(${exampleName} ${OpenCV_LIBS}) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${exampleName} + DESTINATION bin + RENAME ${CMAKE_PROJECT_NAME}-${exampleName}) +endforeach(f) + diff --git a/examples/cam-test.cpp b/examples/cam-test.cpp new file mode 100644 index 0000000..10a60bf --- /dev/null +++ b/examples/cam-test.cpp @@ -0,0 +1,30 @@ +#include "opencv2/opencv.hpp" + +using namespace cv; +using namespace std; + +int main(int argc, char* argv[]) { + VideoCapture cap(0); + + if ( !cap.isOpened() ) { + cout << "Cannot open webcam" << endl; + return -1; + } + namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); + while(1) { + Mat frame; + bool bSuccess = cap.read(frame); + if (!bSuccess) { + cout << "Cannot read the frame from webcam" << endl; + break; + } + + imshow("MyVideo", frame); + + if(waitKey(30) == 27) { + cout << "esc key is pressed by user" << endl; + break; + } + } + return 0; +} diff --git a/opencv/detection.cpp b/examples/detection.cpp similarity index 96% rename from opencv/detection.cpp rename to examples/detection.cpp index 1d63fe4..dfd81a0 100644 --- a/opencv/detection.cpp +++ b/examples/detection.cpp @@ -47,7 +47,7 @@ int main(int, char**) findContours(Binaire, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); Mat Dessin = Mat::zeros(X,Y, CV_8UC1); for(numc = 0; numc= 0) break; + if(waitKey(30) == 27) break; } // the camera will be deinitialized automatically in VideoCapture destructor return 0; diff --git a/examples/lireimage.cpp b/examples/lireimage.cpp new file mode 100644 index 0000000..de313c2 --- /dev/null +++ b/examples/lireimage.cpp @@ -0,0 +1,23 @@ +#include +#include + +int main( int argc, char** argv ) { + if(argc != 2) { + std::cout << "Usage: display_image ImageToLoadAndDisplay" << std::endl; + return -1; + } + + cv::Mat image; + image = cv::imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file + + if(!image.data) {// Check for invalid input + std::cout << "Could not open or find the image" << std::endl; + return -1; + } + + cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE ); //Create a window for display. + cv::imshow( "Display window", image ); //Show our image inside it. + + cv::waitKey(0); //Wait for a keystroke in the window + return 0; +} diff --git a/examples/lpe_col.cpp b/examples/lpe_col.cpp new file mode 100644 index 0000000..51b1e03 --- /dev/null +++ b/examples/lpe_col.cpp @@ -0,0 +1,88 @@ +#include "opencv2/opencv.hpp" + +int traitement(cv::VideoCapture cap, int seuil, cv::Vec3b couleur) { + cv::Mat trame, gris, flou, contx, conty, cont, contbin; + std::vector > contours; + std::vector hierarchy; + int X,Y,x,y,k,nbcont,numc,index; + cap>>trame; + X=trame.rows; + Y=trame.cols; + cv::namedWindow("Image", 1); + cv::imshow("Image", trame); + cv::cvtColor(trame, gris, CV_BGR2GRAY); + cv::GaussianBlur(gris, flou, cv::Size(5, 5), 0, 0); + cv::Sobel(flou, contx, CV_64F, 1, 0); + cv::Sobel(flou, conty, CV_64F, 0, 1); + cont = abs(contx) + abs(conty); + contbin = (cont> couleurs; + std::vector indexcoul; + couleurs.reserve(nbcont); + indexcoul.reserve(nbcont); + for(index = 0; index < nbcont; index++) { + for(k=0;k<3;k++) { + couleurs[index][k]=0.0; + } + indexcoul[index]=0.0; + } + for(x=0;x(x,y)-1; + if (index>=0) { + indexcoul[index]++; + for (k=0;k<3;k++) { + couleurs[index][k] = couleurs[index][k]+trame.at(x,y)[k]; + } + } + } + } + for(index=0;index(x,y)-1; + if (index>=0) { + for (k = 0; k < 3; k++) { + trame.at(x,y)[k] = couleurs[index][k]; + } + } + else { + trame.at(x,y) = couleur; + } + } + } + cv::namedWindow("LPE", 1); + cv::imshow("LPE", trame); + + if(cv::waitKey(30) == 27) { + return true; + } + return false; +} + +int main(int, char**) { + cv::VideoCapture cap(0); + int seuil=10; + cv::Vec3b couleur(128,128,128); + while(traitement(cap,seuil,couleur) == false); +} + + + diff --git a/opencv/exemplepython.jpg b/opencv/exemplepython.jpg deleted file mode 100644 index a5c9b8b..0000000 Binary files a/opencv/exemplepython.jpg and /dev/null differ diff --git a/opencv/genere b/opencv/genere deleted file mode 100755 index 1e3578c..0000000 --- a/opencv/genere +++ /dev/null @@ -1 +0,0 @@ -g++ -Wall `pkg-config --cflags --libs opencv` test.cpp -o test \ No newline at end of file diff --git a/opencv/genere_detection b/opencv/genere_detection deleted file mode 100755 index 21c6c59..0000000 --- a/opencv/genere_detection +++ /dev/null @@ -1 +0,0 @@ -g++ -Wall detection.cpp `pkg-config --cflags --libs opencv` -o detection diff --git a/opencv/genere_lireimage b/opencv/genere_lireimage deleted file mode 100755 index 291981c..0000000 --- a/opencv/genere_lireimage +++ /dev/null @@ -1 +0,0 @@ -g++ -Wall lireimage.cpp `pkg-config --cflags --libs opencv` -o lireimage diff --git a/opencv/genere_lpe_col b/opencv/genere_lpe_col deleted file mode 100755 index 8eec544..0000000 --- a/opencv/genere_lpe_col +++ /dev/null @@ -1 +0,0 @@ -g++ -Wall lpe_col.cpp `pkg-config --cflags --libs opencv` -o lpe_col diff --git a/opencv/genere_testcam b/opencv/genere_testcam deleted file mode 100755 index ba84cb6..0000000 --- a/opencv/genere_testcam +++ /dev/null @@ -1 +0,0 @@ -g++ -Wall testcam.cpp `pkg-config --cflags --libs opencv` -o testcam diff --git a/opencv/lireimage.cpp b/opencv/lireimage.cpp deleted file mode 100644 index 46a4c1d..0000000 --- a/opencv/lireimage.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include - -using namespace cv; -using namespace std; - -int main( int argc, char** argv ) -{ - if( argc != 2) - { - cout <<" Usage: display_image ImageToLoadAndDisplay" << endl; - return -1; - } - - Mat image; - image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file - - if(! image.data ) // Check for invalid input - { - cout << "Could not open or find the image" << std::endl ; - return -1; - } - - namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display. - imshow( "Display window", image ); // Show our image inside it. - - waitKey(0); // Wait for a keystroke in the window - return 0; -} \ No newline at end of file diff --git a/opencv/lpe_col.cpp b/opencv/lpe_col.cpp deleted file mode 100644 index bfc13c6..0000000 --- a/opencv/lpe_col.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "opencv2/opencv.hpp" - -using namespace cv; -using namespace std; - -int Traitement(VideoCapture cap,int seuil,Vec3b couleur) -{ - Mat trame,gris,flou,contx,conty,cont,contbin; - vector > contours; - vector hierarchy; - int X,Y,x,y,k,nbcont,numc,index; - cap>>trame; - X=trame.rows; - Y=trame.cols; - namedWindow("Image",1); - imshow("Image", trame); - cvtColor(trame,gris,COLOR_BGR2GRAY); - GaussianBlur(gris,flou,Size(5,5),0,0); - Sobel(flou,contx,CV_64F,1,0); - Sobel(flou,conty,CV_64F,0,1); - cont=abs(contx)+abs(conty); - contbin=(cont couleurs; - vector indexcoul; - couleurs.reserve(nbcont); - indexcoul.reserve(nbcont); - for(index=0;index(x,y)-1; - if (index>=0) - { - indexcoul[index]++; - for (k=0;k<3;k++) - couleurs[index][k]= - couleurs[index][k]+trame.at(x,y)[k]; - } - } - for(index=0;index(x,y)-1; - if (index>=0) - for (k=0;k<3;k++) - trame.at(x,y)[k]=couleurs[index][k]; - else - trame.at(x,y)=couleur; - } - namedWindow("LPE",1); - imshow("LPE", trame); - if(waitKey(30) >= 0) - return true; - else - return false; -} - -int main(int, char**) -{ - VideoCapture cap(0); - int seuil=10; - Vec3b couleur(128,128,128); - while(Traitement(cap,seuil,couleur)==false); -} - - - diff --git a/opencv/testcam.cpp b/opencv/testcam.cpp deleted file mode 100644 index b80e7c8..0000000 --- a/opencv/testcam.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "opencv2/opencv.hpp" - -using namespace cv; -using namespace std; - -int main(int argc, char* argv[]) -{ - VideoCapture cap(0); - - - if ( !cap.isOpened() ) - { - cout << "Cannot open webcam" << endl; - return -1; - } - namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); - while(1) - { - Mat frame; - bool bSuccess = cap.read(frame); - if (!bSuccess) - { - cout << "Cannot read the frame from webcam" << endl; - break; - } - - imshow("MyVideo", frame); - - if(waitKey(30) == 27) - { - cout << "esc key is pressed by user" << endl; - break; - } - } - return 0; -} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..ae8f07a --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,10 @@ +# file(GLOB headers *.hpp) +# file(GLOB lib_files *.cpp) + +# add_library(blk SHARED ${lib_files}) + +# target_include_directories(blk PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +# target_compile_options (blk PUBLIC -std=c++11 ) + +# install(TARGETS blk DESTINATION lib ) +# install(FILES ${headers} DESTINATION include/${CMAKE_PROJECT_NAME})