mirror of
https://github.com/team2059/Dent
synced 2025-01-07 22:14:14 -05:00
Added edge detection and added to the display output
This commit is contained in:
parent
28789ebc51
commit
4303b189b1
28
vision.cpp
28
vision.cpp
@ -1,5 +1,8 @@
|
|||||||
#include "cv.h"
|
#include "cv.h"
|
||||||
#include "highgui.h"
|
#include "highgui.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
IplImage* GetThresholdedImage(IplImage* img){
|
IplImage* GetThresholdedImage(IplImage* img){
|
||||||
// Convert the image into an HSV image
|
// Convert the image into an HSV image
|
||||||
IplImage* imgHSV = cvCreateImage(cvGetSize(img), 8, 3);
|
IplImage* imgHSV = cvCreateImage(cvGetSize(img), 8, 3);
|
||||||
@ -11,6 +14,24 @@ IplImage* GetThresholdedImage(IplImage* img){
|
|||||||
cvReleaseImage(&imgHSV);
|
cvReleaseImage(&imgHSV);
|
||||||
return imgThreshed;
|
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()
|
int main()
|
||||||
{
|
{
|
||||||
// Initialize capturing live feed from the camera
|
// Initialize capturing live feed from the camera
|
||||||
@ -23,7 +44,6 @@ int main()
|
|||||||
printf("Could not initialize capturing...");
|
printf("Could not initialize capturing...");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
cvNamedWindow("video");
|
|
||||||
cvNamedWindow("thresh");
|
cvNamedWindow("thresh");
|
||||||
while(true){
|
while(true){
|
||||||
// Will hold a frame captured from the camera
|
// 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
|
// If this is the first frame, we need to initialize it
|
||||||
// Holds the yellow thresholded image (yellow = white, rest = black)
|
// Holds the yellow thresholded image (yellow = white, rest = black)
|
||||||
IplImage* imgYellowThresh = GetThresholdedImage(frame);
|
IplImage* imgYellowThresh = GetThresholdedImage(frame);
|
||||||
|
//Display the image after getting the edges of the yellowThresholded image
|
||||||
|
cvShowImage("thresh", GetImageEdges(imgYellowThresh));
|
||||||
cvShowImage("thresh", imgYellowThresh);
|
|
||||||
cvShowImage("video", frame);
|
|
||||||
// Quit on keypress
|
// Quit on keypress
|
||||||
int c = cvWaitKey(10);
|
int c = cvWaitKey(10);
|
||||||
if(c!=-1){
|
if(c!=-1){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user