18 changed files with 181 additions and 159 deletions
@ -1 +1,2 @@ |
|||||
.*.swp |
*.swp |
||||
|
desfournorm* |
||||
|
|||||
@ -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) |
||||
|
|
||||
@ -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) |
||||
|
|
||||
@ -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; |
||||
|
} |
||||
@ -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; |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
Before Width: | Height: | Size: 80 KiB |
@ -1 +0,0 @@ |
|||||
g++ -Wall `pkg-config --cflags --libs opencv` test.cpp -o test |
|
||||
@ -1 +0,0 @@ |
|||||
g++ -Wall detection.cpp `pkg-config --cflags --libs opencv` -o detection |
|
||||
@ -1 +0,0 @@ |
|||||
g++ -Wall lireimage.cpp `pkg-config --cflags --libs opencv` -o lireimage |
|
||||
@ -1 +0,0 @@ |
|||||
g++ -Wall lpe_col.cpp `pkg-config --cflags --libs opencv` -o lpe_col |
|
||||
@ -1 +0,0 @@ |
|||||
g++ -Wall testcam.cpp `pkg-config --cflags --libs opencv` -o testcam |
|
||||
@ -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; |
|
||||
} |
|
||||
@ -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); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
|
|
||||
@ -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; |
|
||||
} |
|
||||
@ -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}) |
||||
Loading…
Reference in new issue