mirror of
https://github.com/opencv/opencv.git
synced 2025-01-10 22:28:13 +08:00
f8fb3a7f55
#25006 #25314 This pull request removes hed_pretrained caffe model to the SOTA dexined onnx model for edge detection. Usage of conventional methods like canny has also been added The obsolete cpp and python sample has been removed TODO: - [ ] Remove temporary hack for quantized models. Refer issue https://github.com/opencv/opencv_zoo/issues/273 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
85 lines
2.2 KiB
C++
85 lines
2.2 KiB
C++
#include "opencv2/core/utility.hpp"
|
|
#include "opencv2/imgproc.hpp"
|
|
#include "opencv2/imgcodecs.hpp"
|
|
#include "opencv2/highgui.hpp"
|
|
|
|
#include <stdio.h>
|
|
|
|
using namespace cv;
|
|
using namespace std;
|
|
|
|
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)";
|
|
|
|
// define a trackbar callback
|
|
static void onTrackbar(int, void*)
|
|
{
|
|
blur(gray, blurImage, Size(3,3));
|
|
|
|
// Run the edge detector on grayscale
|
|
Canny(blurImage, edge1, edgeThresh, edgeThresh*3, 3);
|
|
cedge = Scalar::all(0);
|
|
|
|
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(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);
|
|
|
|
image = imread(samples::findFile(filename), IMREAD_COLOR);
|
|
if(image.empty())
|
|
{
|
|
printf("Cannot read image file: %s\n", filename.c_str());
|
|
help(argv);
|
|
return -1;
|
|
}
|
|
cedge.create(image.size(), image.type());
|
|
cvtColor(image, gray, COLOR_BGR2GRAY);
|
|
|
|
// Create a window
|
|
namedWindow(window_name1, 1);
|
|
namedWindow(window_name2, 1);
|
|
|
|
// create a toolbar
|
|
createTrackbar("Canny threshold default", window_name1, &edgeThresh, 100, onTrackbar);
|
|
createTrackbar("Canny threshold Scharr", window_name2, &edgeThreshScharr, 400, onTrackbar);
|
|
|
|
// Show the image
|
|
onTrackbar(0, 0);
|
|
|
|
// Wait for a key stroke; the same function arranges events processing
|
|
waitKey(0);
|
|
|
|
return 0;
|
|
} |