mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 11:40:44 +08:00
d566c6bc86
This reverts commit 54a202b3d5
.
Conflicts:
modules/core/doc/command_line_parser.rst
modules/core/include/opencv2/core/core.hpp
modules/core/src/cmdparser.cpp
modules/gpu/perf/main.cpp
modules/gpu/test/main.cpp
modules/ts/src/ts_perf.cpp
68 lines
1.4 KiB
C++
68 lines
1.4 KiB
C++
#include "opencv2/imgproc/imgproc.hpp"
|
|
#include "opencv2/highgui/highgui.hpp"
|
|
|
|
#include <stdio.h>
|
|
|
|
using namespace cv;
|
|
using namespace std;
|
|
|
|
int edgeThresh = 1;
|
|
Mat image, gray, edge, cedge;
|
|
|
|
// define a trackbar callback
|
|
static void onTrackbar(int, void*)
|
|
{
|
|
blur(gray, edge, Size(3,3));
|
|
|
|
// Run the edge detector on grayscale
|
|
Canny(edge, edge, edgeThresh, edgeThresh*3, 3);
|
|
cedge = Scalar::all(0);
|
|
|
|
image.copyTo(cedge, edge);
|
|
imshow("Edge map", cedge);
|
|
}
|
|
|
|
static void help()
|
|
{
|
|
printf("\nThis sample demonstrates Canny edge detection\n"
|
|
"Call:\n"
|
|
" /.edge [image_name -- Default is fruits.jpg]\n\n");
|
|
}
|
|
|
|
const char* keys =
|
|
{
|
|
"{@image |fruits.jpg|input image name}"
|
|
};
|
|
|
|
int main( int argc, const char** argv )
|
|
{
|
|
help();
|
|
|
|
CommandLineParser parser(argc, argv, keys);
|
|
string filename = parser.get<string>(1);
|
|
|
|
image = imread(filename, 1);
|
|
if(image.empty())
|
|
{
|
|
printf("Cannot read image file: %s\n", filename.c_str());
|
|
help();
|
|
return -1;
|
|
}
|
|
cedge.create(image.size(), image.type());
|
|
cvtColor(image, gray, CV_BGR2GRAY);
|
|
|
|
// Create a window
|
|
namedWindow("Edge map", 1);
|
|
|
|
// create a toolbar
|
|
createTrackbar("Canny threshold", "Edge map", &edgeThresh, 100, onTrackbar);
|
|
|
|
// Show the image
|
|
onTrackbar(0, 0);
|
|
|
|
// Wait for a key stroke; the same function arranges events processing
|
|
waitKey(0);
|
|
|
|
return 0;
|
|
}
|