Created
August 28, 2012 23:25
-
-
Save dlion/3505250 to your computer and use it in GitHub Desktop.
A simple snippet for retrieve frames from the webcam and make only the contourn of the image with Canny filter using OpenCV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Rilevatore di bordi con canny | |
* Snippet by Domenico Luciani aka DLion | |
*/ | |
#include <highgui.h> | |
#include <cv.h> | |
int main() | |
{ | |
IplImage *frame,*out; | |
CvCapture *immagine; | |
//Catturo dalla cam | |
immagine = cvCaptureFromCAM(0); | |
//Catturo il primo frame | |
frame= cvQueryFrame(immagine); | |
//Creo out ompatibile con frame, ad un solo canale. | |
out = cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,1); | |
//Creo una finestra chiamata "Bordi" | |
cvNamedWindow("Bordi",CV_WINDOW_AUTOSIZE); | |
//Ciclo finchè frame è disponibile | |
while(frame) | |
{ | |
//Converto l'immagine nella scala di grigi | |
cvCvtColor(frame, out, CV_BGR2GRAY); | |
//Giro l'immagine | |
cvFlip(out,out,1); | |
//Applico il filtro di canny | |
cvCanny(out,out,40,50,3); | |
//Dilato l'immagine per risaltare i contorni trovati | |
cvDilate(out,out,NULL,1); | |
//Mostro l'immagine | |
cvShowImage("Bordi",out); | |
//Prendo il frame successivo | |
frame = cvQueryFrame(immagine); | |
//Aspetto 10 millisecondi per vedere viene premuto q (tasto di uscita) | |
if(cvWaitKey(10) == 'q') break; | |
} | |
//Rimuovo tutto | |
cvReleaseCapture(&immagine); | |
cvReleaseImage(&frame); | |
cvReleaseImage(&out); | |
cvDestroyWindow("Bordi"); | |
return 0; | |
} | |
//If you want to see the example result you can see here: http://i.imgur.com/Peo11.jpg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment