commit
bf4a35f2c8
19 changed files with 269 additions and 0 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,64 @@ |
|||||
|
#include "opencv2/opencv.hpp" |
||||
|
|
||||
|
using namespace cv; |
||||
|
using namespace std; |
||||
|
|
||||
|
int main(int, char**) |
||||
|
{ |
||||
|
int seuil=80; |
||||
|
char detect; |
||||
|
VideoCapture cap(0); |
||||
|
if(!cap.isOpened()) |
||||
|
return -1; |
||||
|
namedWindow("Image",1); |
||||
|
namedWindow("Detection",1); |
||||
|
namedWindow("Contours",1); |
||||
|
for(;;) { |
||||
|
int X,Y,DIM,index,indexNB; |
||||
|
unsigned int numc; |
||||
|
uchar R,G,B; |
||||
|
vector<vector<Point> > contours; |
||||
|
vector<Vec4i> hierarchy; |
||||
|
Mat frame; |
||||
|
cap >> frame; |
||||
|
X=frame.rows; |
||||
|
Y=frame.cols; |
||||
|
Mat Binaire(X,Y,CV_8UC1); |
||||
|
imshow("Image", frame); |
||||
|
GaussianBlur(frame, frame, Size(7,7), 1.5, 1.5); |
||||
|
X=frame.rows; |
||||
|
Y=frame.cols; |
||||
|
DIM=frame.channels(); |
||||
|
for (index=0,indexNB=0;index<DIM*X*Y;index+=DIM,indexNB++) |
||||
|
{ |
||||
|
detect=0; |
||||
|
B=frame.data[index ]; |
||||
|
G=frame.data[index + 1]; |
||||
|
R=frame.data[index + 2]; |
||||
|
if ((R>G) && (R>B)) |
||||
|
if (((R-B)>=seuil) || ((R-G)>=seuil)) |
||||
|
detect=1; |
||||
|
if (detect==1) |
||||
|
Binaire.data[indexNB]=255; |
||||
|
else |
||||
|
Binaire.data[indexNB]=0; |
||||
|
} |
||||
|
imshow("Detection", Binaire); |
||||
|
findContours(Binaire, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); |
||||
|
Mat Dessin = Mat::zeros(X,Y, CV_8UC1); |
||||
|
unsigned int max = 0; |
||||
|
int id = 0; |
||||
|
for(numc = 0; numc<contours.size(); numc++) { |
||||
|
if (contours[numc].size() > max) { |
||||
|
max = contours[numc].size(); |
||||
|
id = numc; |
||||
|
} |
||||
|
} |
||||
|
drawContours(Dessin, contours, id, 255); |
||||
|
imshow("Contours", Dessin); |
||||
|
if(waitKey(30) == 27) { |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
return 0; |
||||
|
} |
||||
|
After Width: | Height: | Size: 80 KiB |
@ -0,0 +1 @@ |
|||||
|
g++ -Wall `pkg-config --cflags --libs opencv` test.cpp -o test |
||||
@ -0,0 +1 @@ |
|||||
|
g++ -Wall detection.cpp `pkg-config --cflags --libs opencv` -o detection |
||||
@ -0,0 +1 @@ |
|||||
|
g++ -Wall lireimage.cpp `pkg-config --cflags --libs opencv` -o lireimage |
||||
@ -0,0 +1 @@ |
|||||
|
g++ -Wall lpe_col.cpp `pkg-config --cflags --libs opencv` -o lpe_col |
||||
@ -0,0 +1 @@ |
|||||
|
g++ -Wall testcam.cpp `pkg-config --cflags --libs opencv` -o testcam |
||||
Binary file not shown.
@ -0,0 +1,30 @@ |
|||||
|
#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; |
||||
|
} |
||||
@ -0,0 +1,85 @@ |
|||||
|
#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); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
@ -0,0 +1,25 @@ |
|||||
|
#include "opencv2/opencv.hpp" |
||||
|
|
||||
|
using namespace cv; |
||||
|
|
||||
|
int main(int, char**) |
||||
|
{ |
||||
|
VideoCapture cap(0); // open the default camera
|
||||
|
if(!cap.isOpened()) // check if we succeeded
|
||||
|
return -1; |
||||
|
|
||||
|
Mat edges; |
||||
|
namedWindow("edges",1); |
||||
|
for(;;) |
||||
|
{ |
||||
|
Mat frame; |
||||
|
cap >> frame; // get a new frame from camera
|
||||
|
cvtColor(frame, edges, CV_BGR2GRAY); |
||||
|
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5); |
||||
|
Canny(edges, edges, 0, 30, 3); |
||||
|
imshow("edges", edges); |
||||
|
if(waitKey(30) >= 0) break; |
||||
|
} |
||||
|
// the camera will be deinitialized automatically in VideoCapture destructor
|
||||
|
return 0; |
||||
|
} |
||||
Binary file not shown.
@ -0,0 +1,36 @@ |
|||||
|
#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; |
||||
|
} |
||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,24 @@ |
|||||
|
#include "opencv2/opencv.hpp" |
||||
|
|
||||
|
int main(int, char**) |
||||
|
{ |
||||
|
cv::VideoCapture cap(0); // open the default camera
|
||||
|
if(!cap.isOpened()) // check if we succeeded
|
||||
|
return -1; |
||||
|
|
||||
|
cv::Mat edges; |
||||
|
cv::namedWindow("edges",1); |
||||
|
while(1){ |
||||
|
cv::Mat frame; |
||||
|
cap >> frame; // get a new frame from camera
|
||||
|
//cv::cvtColor(frame, edges, CV_BGR2GRAY);
|
||||
|
//cv::GaussianBlur(edges, edges, cv::Size(7,7), 1.5, 1.5);
|
||||
|
//cv::Canny(edges, edges, 0, 30, 3);
|
||||
|
cv::imshow("edges", frame); |
||||
|
if(cv::waitKey(30) == 27) { |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
// the camera will be deinitialized automatically in VideoCapture destructor
|
||||
|
return 0; |
||||
|
} |
||||
Loading…
Reference in new issue