#include <stdio.h>
int edgeThresh = 1;
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)";
static void onTrackbar(int, void*)
{
Canny(blurImage, edge1, edgeThresh, edgeThresh*3, 3);
cedge = Scalar::all(0);
image.copyTo(cedge, edge1);
Mat dx,dy;
Canny( dx,dy, edge2, edgeThreshScharr, edgeThreshScharr*3 );
cedge = Scalar::all(0);
image.copyTo(cedge, edge2);
}
static void help(const char** argv)
{
printf("\nThis sample demonstrates Canny edge detection\n"
"Call:\n"
" %s [image_name -- Default is fruits.jpg]\n\n", argv[0]);
}
const char* keys =
{
"{help h||}{@image |fruits.jpg|input image name}"
};
int main(
int argc,
const char** argv )
{
help(argv);
CommandLineParser parser(argc, argv, keys);
string filename = parser.get<string>(0);
if(image.empty())
{
printf("Cannot read image file: %s\n", filename.c_str());
help(argv);
return -1;
}
cedge.create(image.size(), image.type());
createTrackbar(
"Canny threshold default", window_name1, &edgeThresh, 100, onTrackbar);
createTrackbar(
"Canny threshold Scharr", window_name2, &edgeThreshScharr, 400, onTrackbar);
onTrackbar(0, 0);
return 0;
}
Size2i Size
Definition: modules/core/include/opencv2/core/types.hpp:370
#define CV_16S
Definition: core/include/opencv2/core/hal/interface.h:76
cv::String findFile(const cv::String &relative_path, bool required=true, bool silentMode=false)
Try to find requested data file.
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
Creates a window.
int createTrackbar(const String &trackbarname, const String &winname, int *value, int count, TrackbarCallback onChange=0, void *userdata=0)
Creates a trackbar and attaches it to the specified window.
@ IMREAD_COLOR
Same as IMREAD_COLOR_BGR.
Definition: imgcodecs.hpp:72
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
Loads an image from a file.
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0, AlgorithmHint hint=cv::ALGO_HINT_DEFAULT)
Converts an image from one color space to another.
@ COLOR_BGR2GRAY
convert between RGB/BGR and grayscale, color conversions
Definition: imgproc/include/opencv2/imgproc.hpp:555
void Canny(InputArray image, OutputArray edges, double threshold1, double threshold2, int apertureSize=3, bool L2gradient=false)
Finds edges in an image using the Canny algorithm .
void blur(InputArray src, OutputArray dst, Size ksize, Point anchor=Point(-1,-1), int borderType=BORDER_DEFAULT)
Blurs an image using the normalized box filter.
void Scharr(InputArray src, OutputArray dst, int ddepth, int dx, int dy, double scale=1, double delta=0, int borderType=BORDER_DEFAULT)
Calculates the first x- or y- image derivative using Scharr operator.
int main(int argc, char *argv[])
Definition: highgui_qt.cpp:3
Definition: core/include/opencv2/core.hpp:107