|
|
|
@ -9,19 +9,34 @@ using namespace cv; |
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
|
int edgeThresh = 1; |
|
|
|
|
Mat image, gray, edge, cedge; |
|
|
|
|
int edgeThreshScharr=1; |
|
|
|
|
|
|
|
|
|
Mat image, gray, blurImage, edge1, edge2, cedge; |
|
|
|
|
|
|
|
|
|
const char* window_name1 = "Edge map : Canny default (Sobel gradient)"; |
|
|
|
|
const char* window_name2 = "Edge map : Canny with custom gradient (Scharr)"; |
|
|
|
|
|
|
|
|
|
// define a trackbar callback
|
|
|
|
|
static void onTrackbar(int, void*) |
|
|
|
|
{ |
|
|
|
|
blur(gray, edge, Size(3,3)); |
|
|
|
|
blur(gray, blurImage, Size(3,3)); |
|
|
|
|
|
|
|
|
|
// Run the edge detector on grayscale
|
|
|
|
|
Canny(edge, edge, edgeThresh, edgeThresh*3, 3); |
|
|
|
|
Canny(blurImage, edge1, edgeThresh, edgeThresh*3, 3); |
|
|
|
|
cedge = Scalar::all(0); |
|
|
|
|
|
|
|
|
|
image.copyTo(cedge, edge); |
|
|
|
|
imshow("Edge map", cedge); |
|
|
|
|
image.copyTo(cedge, edge1); |
|
|
|
|
imshow(window_name1, cedge); |
|
|
|
|
|
|
|
|
|
/// Canny detector with scharr
|
|
|
|
|
Mat dx,dy; |
|
|
|
|
Scharr(blurImage,dx,CV_16S,1,0); |
|
|
|
|
Scharr(blurImage,dy,CV_16S,0,1); |
|
|
|
|
Canny( dx,dy, edge2, edgeThreshScharr, edgeThreshScharr*3 ); |
|
|
|
|
/// Using Canny's output as a mask, we display our result
|
|
|
|
|
cedge = Scalar::all(0); |
|
|
|
|
image.copyTo(cedge, edge2); |
|
|
|
|
imshow(window_name2, cedge); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void help() |
|
|
|
@ -57,10 +72,12 @@ int main( int argc, const char** argv ) |
|
|
|
|
cvtColor(image, gray, COLOR_BGR2GRAY); |
|
|
|
|
|
|
|
|
|
// Create a window
|
|
|
|
|
namedWindow("Edge map", 1); |
|
|
|
|
namedWindow(window_name1, 1); |
|
|
|
|
namedWindow(window_name2, 1); |
|
|
|
|
|
|
|
|
|
// create a toolbar
|
|
|
|
|
createTrackbar("Canny threshold", "Edge map", &edgeThresh, 100, onTrackbar); |
|
|
|
|
createTrackbar("Canny threshold default", window_name1, &edgeThresh, 100, onTrackbar); |
|
|
|
|
createTrackbar("Canny threshold Scharr", window_name2, &edgeThreshScharr, 400, onTrackbar); |
|
|
|
|
|
|
|
|
|
// Show the image
|
|
|
|
|
onTrackbar(0, 0); |
|
|
|
|