Ajoute de fichier cmake et réorganisation des fichiers.

This commit is contained in:
Guillaume Courrier 2019-10-29 16:57:18 +01:00
parent 8800ea79c8
commit edffb137b7
18 changed files with 181 additions and 159 deletions

3
.gitignore vendored
View file

@ -1 +1,2 @@
.*.swp *.swp
desfournorm*

9
CMakeLists.txt Normal file
View file

@ -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)

17
examples/CMakeLists.txt Normal file
View file

@ -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)

30
examples/cam-test.cpp Normal file
View file

@ -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;
}

View file

@ -47,7 +47,7 @@ int main(int, char**)
findContours(Binaire, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); findContours(Binaire, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
Mat Dessin = Mat::zeros(X,Y, CV_8UC1); Mat Dessin = Mat::zeros(X,Y, CV_8UC1);
for(numc = 0; numc<contours.size(); numc++) { for(numc = 0; numc<contours.size(); numc++) {
drawContours(Dessin, contours, id, 255); drawContours(Dessin, contours, numc, 255);
} }
imshow("Contours", Dessin); imshow("Contours", Dessin);
if(waitKey(30) == 27) { if(waitKey(30) == 27) {

View file

@ -18,7 +18,7 @@ int main(int, char**)
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5); GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3); Canny(edges, edges, 0, 30, 3);
imshow("edges", edges); imshow("edges", edges);
if(waitKey(30) >= 0) break; if(waitKey(30) == 27) break;
} }
// the camera will be deinitialized automatically in VideoCapture destructor // the camera will be deinitialized automatically in VideoCapture destructor
return 0; return 0;

23
examples/lireimage.cpp Normal file
View file

@ -0,0 +1,23 @@
#include <opencv2/opencv.hpp>
#include <iostream>
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;
}

88
examples/lpe_col.cpp Normal file
View file

@ -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<std::vector<cv::Point> > contours;
std::vector<cv::Vec4i> 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<seuil);
cv::namedWindow("Gradient", 1);
cv::imshow("Gradient", cont/255);
findContours(contbin, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE);
cv::Mat marqueurs = cv::Mat::zeros(X, Y, CV_32S);
nbcont = (int)contours.size();
index = 1;
for(numc = 0; numc < nbcont; numc++ ) {
if (hierarchy[numc][3]<0) {
cv::drawContours( marqueurs, contours, numc, index++);
}
}
cv::watershed(trame, marqueurs);
std::vector<std::array<double,3>> couleurs;
std::vector<double> 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;x++) {
for(y=0;y<Y;y++) {
index=marqueurs.at<int>(x,y)-1;
if (index>=0) {
indexcoul[index]++;
for (k=0;k<3;k++) {
couleurs[index][k] = couleurs[index][k]+trame.at<cv::Vec3b>(x,y)[k];
}
}
}
}
for(index=0;index<nbcont;index++) {
for (k=0;k<3;k++) {
couleurs[index][k]/=indexcoul[index];
}
}
for(x=0;x<X;x++) {
for(y = 0; y < Y; y++) {
index=marqueurs.at<int>(x,y)-1;
if (index>=0) {
for (k = 0; k < 3; k++) {
trame.at<cv::Vec3b>(x,y)[k] = couleurs[index][k];
}
}
else {
trame.at<cv::Vec3b>(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);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

View file

@ -1 +0,0 @@
g++ -Wall `pkg-config --cflags --libs opencv` test.cpp -o test

View file

@ -1 +0,0 @@
g++ -Wall detection.cpp `pkg-config --cflags --libs opencv` -o detection

View file

@ -1 +0,0 @@
g++ -Wall lireimage.cpp `pkg-config --cflags --libs opencv` -o lireimage

View file

@ -1 +0,0 @@
g++ -Wall lpe_col.cpp `pkg-config --cflags --libs opencv` -o lpe_col

View file

@ -1 +0,0 @@
g++ -Wall testcam.cpp `pkg-config --cflags --libs opencv` -o testcam

View file

@ -1,30 +0,0 @@
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
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;
}

View file

@ -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<vector<Point> > contours;
vector<Vec4i> 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<seuil);
namedWindow("Gradient",1);
imshow("Gradient",cont/255);
findContours(contbin,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_NONE);
Mat marqueurs = Mat::zeros(X,Y, CV_32S);
nbcont=(int)contours.size();
index=1;
for(numc = 0; numc < nbcont; numc++ )
if (hierarchy[numc][3]<0)
drawContours( marqueurs, contours, numc, index++);
watershed(trame,marqueurs);
vector<double[3]> couleurs;
vector<double> 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;x++)
for(y=0;y<Y;y++)
{
index=marqueurs.at<int>(x,y)-1;
if (index>=0)
{
indexcoul[index]++;
for (k=0;k<3;k++)
couleurs[index][k]=
couleurs[index][k]+trame.at<Vec3b>(x,y)[k];
}
}
for(index=0;index<nbcont;index++)
for (k=0;k<3;k++)
couleurs[index][k]/=indexcoul[index];
for(x=0;x<X;x++)
for(y=0;y<Y;y++)
{
index=marqueurs.at<int>(x,y)-1;
if (index>=0)
for (k=0;k<3;k++)
trame.at<Vec3b>(x,y)[k]=couleurs[index][k];
else
trame.at<Vec3b>(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);
}

View file

@ -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;
}

10
src/CMakeLists.txt Normal file
View file

@ -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})