mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
imgproc: add IntelligentScissors
This commit is contained in:
@@ -23,6 +23,9 @@ if(NOT BUILD_EXAMPLES OR NOT OCV_DEPENDENCIES_FOUND)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(DEPS_example_snippet_imgproc_segmentation opencv_core opencv_imgproc)
|
||||
set(DEPS_example_cpp_intelligent_scissors opencv_core opencv_imgproc opencv_imgcodecs opencv_highgui)
|
||||
|
||||
project(cpp_samples)
|
||||
ocv_include_modules_recurse(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
|
||||
file(GLOB_RECURSE cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
|
||||
@@ -32,11 +35,17 @@ endif()
|
||||
ocv_list_filterout(cpp_samples "real_time_pose_estimation/")
|
||||
foreach(sample_filename ${cpp_samples})
|
||||
set(package "cpp")
|
||||
if(sample_filename MATCHES "tutorial_code")
|
||||
if(sample_filename MATCHES "tutorial_code/snippet")
|
||||
set(package "snippet")
|
||||
elseif(sample_filename MATCHES "tutorial_code")
|
||||
set(package "tutorial")
|
||||
endif()
|
||||
ocv_define_sample(tgt ${sample_filename} ${package})
|
||||
ocv_target_link_libraries(${tgt} PRIVATE ${OPENCV_LINKER_LIBS} ${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
|
||||
set(deps ${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
|
||||
if(DEFINED DEPS_${tgt})
|
||||
set(deps ${DEPS_${tgt}})
|
||||
endif()
|
||||
ocv_target_link_libraries(${tgt} PRIVATE ${OPENCV_LINKER_LIBS} ${deps})
|
||||
if(sample_filename MATCHES "/gpu/" AND HAVE_opencv_cudaarithm AND HAVE_opencv_cuda_filters)
|
||||
ocv_target_link_libraries(${tgt} PRIVATE opencv_cudaarithm opencv_cudafilters)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/imgproc/segmentation.hpp"
|
||||
|
||||
using namespace cv;
|
||||
|
||||
static
|
||||
void usage_example_intelligent_scissors()
|
||||
{
|
||||
Mat image(Size(1920, 1080), CV_8UC3, Scalar::all(128));
|
||||
|
||||
//! [usage_example_intelligent_scissors]
|
||||
segmentation::IntelligentScissorsMB tool;
|
||||
tool.setEdgeFeatureCannyParameters(16, 100) // using Canny() as edge feature extractor
|
||||
.setGradientMagnitudeMaxLimit(200);
|
||||
|
||||
// calculate image features
|
||||
tool.applyImage(image);
|
||||
|
||||
// calculate map for specified source point
|
||||
Point source_point(200, 100);
|
||||
tool.buildMap(source_point);
|
||||
|
||||
// fast fetching of contours
|
||||
// for specified target point and the pre-calculated map (stored internally)
|
||||
Point target_point(400, 300);
|
||||
std::vector<Point> pts;
|
||||
tool.getContour(target_point, pts);
|
||||
//! [usage_example_intelligent_scissors]
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
usage_example_intelligent_scissors();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user