diff --git a/vision.cpp b/vision.cpp index 43de1aa..a994eba 100644 --- a/vision.cpp +++ b/vision.cpp @@ -1,5 +1,8 @@ #include "cv.h" #include "highgui.h" + +using namespace std; +using namespace cv; IplImage* GetThresholdedImage(IplImage* img){ // Convert the image into an HSV image IplImage* imgHSV = cvCreateImage(cvGetSize(img), 8, 3); @@ -11,6 +14,24 @@ IplImage* GetThresholdedImage(IplImage* img){ cvReleaseImage(&imgHSV); return imgThreshed; } + +IplImage* GetImageEdges(IplImage *img){ + const int lowerEdgeThresh = 10; + const int editRatio = 3; + Mat org, dst; + //Convert the IplImage to a mat + org = img; + //Blur the image "org" and output it to dst + GaussianBlur(org,dst,Size(5,5),0,0); + //Copy dst to org to keep naming correct + org = dst; + //Use canny to find edges + Canny(org,dst,lowerEdgeThresh,lowerEdgeThresh*3,3); + //Convert the Mat back to an image + img->imageData = (char *) dst.data; + return img; +} + int main() { // Initialize capturing live feed from the camera @@ -23,7 +44,6 @@ int main() printf("Could not initialize capturing..."); return -1; } - cvNamedWindow("video"); cvNamedWindow("thresh"); while(true){ // Will hold a frame captured from the camera @@ -35,10 +55,8 @@ int main() // If this is the first frame, we need to initialize it // Holds the yellow thresholded image (yellow = white, rest = black) IplImage* imgYellowThresh = GetThresholdedImage(frame); - - - cvShowImage("thresh", imgYellowThresh); - cvShowImage("video", frame); + //Display the image after getting the edges of the yellowThresholded image + cvShowImage("thresh", GetImageEdges(imgYellowThresh)); // Quit on keypress int c = cvWaitKey(10); if(c!=-1){