Skip to content

Instantly share code, notes, and snippets.

@hkhojasteh
Last active January 30, 2019 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkhojasteh/27da434736e4f4a26610edf1f1e4a791 to your computer and use it in GitHub Desktop.
Save hkhojasteh/27da434736e4f4a26610edf1f1e4a791 to your computer and use it in GitHub Desktop.
Mat detected_edges, img_mask;
int const max_lowThreshold = 255;
int lowThreshold = 210, ratio = 3, kernel_size = 3;
char* window_name = "Edge Map";
//CannyThreshold: Trackbar callback - Canny thresholds input with a ratio 1:3
void CannyThreshold(int, void*){
blur(img_mask, detected_edges, Size(3, 3)); //Reduce noise with a kernel 3x3
Canny(detected_edges, detected_edges, lowThreshold, lowThreshold * ratio, kernel_size); //Canny detector
imshow(window_name, detected_edges); //Using Canny's output as a mask, and display our result
}
detected_edges.create(img_mask.size(), img_mask.type()); //Create a window
namedWindow(window_name);
createTrackbar("Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold); // Create a Trackbar for user to enter threshold
CannyThreshold(0, 0); //Show the image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment