001// 002// This file is auto-generated. Please don't modify it! 003// 004package org.opencv.imgproc; 005 006import org.opencv.core.Mat; 007import org.opencv.core.Point; 008import org.opencv.imgproc.IntelligentScissorsMB; 009 010// C++: class IntelligentScissorsMB 011/** 012 * Intelligent Scissors image segmentation 013 * 014 * This class is used to find the path (contour) between two points 015 * which can be used for image segmentation. 016 * 017 * Usage example: 018 * SNIPPET: snippets/imgproc_segmentation.cpp usage_example_intelligent_scissors 019 * 020 * Reference: <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.138.3811&rep=rep1&type=pdf">"Intelligent Scissors for Image Composition"</a> 021 * algorithm designed by Eric N. Mortensen and William A. Barrett, Brigham Young University 022 * CITE: Mortensen95intelligentscissors 023 */ 024public class IntelligentScissorsMB { 025 026 protected final long nativeObj; 027 protected IntelligentScissorsMB(long addr) { nativeObj = addr; } 028 029 public long getNativeObjAddr() { return nativeObj; } 030 031 // internal usage only 032 public static IntelligentScissorsMB __fromPtr__(long addr) { return new IntelligentScissorsMB(addr); } 033 034 // 035 // C++: cv::segmentation::IntelligentScissorsMB::IntelligentScissorsMB() 036 // 037 038 public IntelligentScissorsMB() { 039 nativeObj = IntelligentScissorsMB_0(); 040 } 041 042 043 // 044 // C++: IntelligentScissorsMB cv::segmentation::IntelligentScissorsMB::setWeights(float weight_non_edge, float weight_gradient_direction, float weight_gradient_magnitude) 045 // 046 047 /** 048 * Specify weights of feature functions 049 * 050 * Consider keeping weights normalized (sum of weights equals to 1.0) 051 * Discrete dynamic programming (DP) goal is minimization of costs between pixels. 052 * 053 * @param weight_non_edge Specify cost of non-edge pixels (default: 0.43f) 054 * @param weight_gradient_direction Specify cost of gradient direction function (default: 0.43f) 055 * @param weight_gradient_magnitude Specify cost of gradient magnitude function (default: 0.14f) 056 * @return automatically generated 057 */ 058 public IntelligentScissorsMB setWeights(float weight_non_edge, float weight_gradient_direction, float weight_gradient_magnitude) { 059 return new IntelligentScissorsMB(setWeights_0(nativeObj, weight_non_edge, weight_gradient_direction, weight_gradient_magnitude)); 060 } 061 062 063 // 064 // C++: IntelligentScissorsMB cv::segmentation::IntelligentScissorsMB::setGradientMagnitudeMaxLimit(float gradient_magnitude_threshold_max = 0.0f) 065 // 066 067 /** 068 * Specify gradient magnitude max value threshold 069 * 070 * Zero limit value is used to disable gradient magnitude thresholding (default behavior, as described in original article). 071 * Otherwize pixels with {@code gradient magnitude >= threshold} have zero cost. 072 * 073 * <b>Note:</b> Thresholding should be used for images with irregular regions (to avoid stuck on parameters from high-contract areas, like embedded logos). 074 * 075 * @param gradient_magnitude_threshold_max Specify gradient magnitude max value threshold (default: 0, disabled) 076 * @return automatically generated 077 */ 078 public IntelligentScissorsMB setGradientMagnitudeMaxLimit(float gradient_magnitude_threshold_max) { 079 return new IntelligentScissorsMB(setGradientMagnitudeMaxLimit_0(nativeObj, gradient_magnitude_threshold_max)); 080 } 081 082 /** 083 * Specify gradient magnitude max value threshold 084 * 085 * Zero limit value is used to disable gradient magnitude thresholding (default behavior, as described in original article). 086 * Otherwize pixels with {@code gradient magnitude >= threshold} have zero cost. 087 * 088 * <b>Note:</b> Thresholding should be used for images with irregular regions (to avoid stuck on parameters from high-contract areas, like embedded logos). 089 * 090 * @return automatically generated 091 */ 092 public IntelligentScissorsMB setGradientMagnitudeMaxLimit() { 093 return new IntelligentScissorsMB(setGradientMagnitudeMaxLimit_1(nativeObj)); 094 } 095 096 097 // 098 // C++: IntelligentScissorsMB cv::segmentation::IntelligentScissorsMB::setEdgeFeatureZeroCrossingParameters(float gradient_magnitude_min_value = 0.0f) 099 // 100 101 /** 102 * Switch to "Laplacian Zero-Crossing" edge feature extractor and specify its parameters 103 * 104 * This feature extractor is used by default according to article. 105 * 106 * Implementation has additional filtering for regions with low-amplitude noise. 107 * This filtering is enabled through parameter of minimal gradient amplitude (use some small value 4, 8, 16). 108 * 109 * <b>Note:</b> Current implementation of this feature extractor is based on processing of grayscale images (color image is converted to grayscale image first). 110 * 111 * <b>Note:</b> Canny edge detector is a bit slower, but provides better results (especially on color images): use setEdgeFeatureCannyParameters(). 112 * 113 * @param gradient_magnitude_min_value Minimal gradient magnitude value for edge pixels (default: 0, check is disabled) 114 * @return automatically generated 115 */ 116 public IntelligentScissorsMB setEdgeFeatureZeroCrossingParameters(float gradient_magnitude_min_value) { 117 return new IntelligentScissorsMB(setEdgeFeatureZeroCrossingParameters_0(nativeObj, gradient_magnitude_min_value)); 118 } 119 120 /** 121 * Switch to "Laplacian Zero-Crossing" edge feature extractor and specify its parameters 122 * 123 * This feature extractor is used by default according to article. 124 * 125 * Implementation has additional filtering for regions with low-amplitude noise. 126 * This filtering is enabled through parameter of minimal gradient amplitude (use some small value 4, 8, 16). 127 * 128 * <b>Note:</b> Current implementation of this feature extractor is based on processing of grayscale images (color image is converted to grayscale image first). 129 * 130 * <b>Note:</b> Canny edge detector is a bit slower, but provides better results (especially on color images): use setEdgeFeatureCannyParameters(). 131 * 132 * @return automatically generated 133 */ 134 public IntelligentScissorsMB setEdgeFeatureZeroCrossingParameters() { 135 return new IntelligentScissorsMB(setEdgeFeatureZeroCrossingParameters_1(nativeObj)); 136 } 137 138 139 // 140 // C++: IntelligentScissorsMB cv::segmentation::IntelligentScissorsMB::setEdgeFeatureCannyParameters(double threshold1, double threshold2, int apertureSize = 3, bool L2gradient = false) 141 // 142 143 /** 144 * Switch edge feature extractor to use Canny edge detector 145 * 146 * <b>Note:</b> "Laplacian Zero-Crossing" feature extractor is used by default (following to original article) 147 * 148 * SEE: Canny 149 * @param threshold1 automatically generated 150 * @param threshold2 automatically generated 151 * @param apertureSize automatically generated 152 * @param L2gradient automatically generated 153 * @return automatically generated 154 */ 155 public IntelligentScissorsMB setEdgeFeatureCannyParameters(double threshold1, double threshold2, int apertureSize, boolean L2gradient) { 156 return new IntelligentScissorsMB(setEdgeFeatureCannyParameters_0(nativeObj, threshold1, threshold2, apertureSize, L2gradient)); 157 } 158 159 /** 160 * Switch edge feature extractor to use Canny edge detector 161 * 162 * <b>Note:</b> "Laplacian Zero-Crossing" feature extractor is used by default (following to original article) 163 * 164 * SEE: Canny 165 * @param threshold1 automatically generated 166 * @param threshold2 automatically generated 167 * @param apertureSize automatically generated 168 * @return automatically generated 169 */ 170 public IntelligentScissorsMB setEdgeFeatureCannyParameters(double threshold1, double threshold2, int apertureSize) { 171 return new IntelligentScissorsMB(setEdgeFeatureCannyParameters_1(nativeObj, threshold1, threshold2, apertureSize)); 172 } 173 174 /** 175 * Switch edge feature extractor to use Canny edge detector 176 * 177 * <b>Note:</b> "Laplacian Zero-Crossing" feature extractor is used by default (following to original article) 178 * 179 * SEE: Canny 180 * @param threshold1 automatically generated 181 * @param threshold2 automatically generated 182 * @return automatically generated 183 */ 184 public IntelligentScissorsMB setEdgeFeatureCannyParameters(double threshold1, double threshold2) { 185 return new IntelligentScissorsMB(setEdgeFeatureCannyParameters_2(nativeObj, threshold1, threshold2)); 186 } 187 188 189 // 190 // C++: IntelligentScissorsMB cv::segmentation::IntelligentScissorsMB::applyImage(Mat image) 191 // 192 193 /** 194 * Specify input image and extract image features 195 * 196 * @param image input image. Type is #CV_8UC1 / #CV_8UC3 197 * @return automatically generated 198 */ 199 public IntelligentScissorsMB applyImage(Mat image) { 200 return new IntelligentScissorsMB(applyImage_0(nativeObj, image.nativeObj)); 201 } 202 203 204 // 205 // C++: IntelligentScissorsMB cv::segmentation::IntelligentScissorsMB::applyImageFeatures(Mat non_edge, Mat gradient_direction, Mat gradient_magnitude, Mat image = Mat()) 206 // 207 208 /** 209 * Specify custom features of input image 210 * 211 * Customized advanced variant of applyImage() call. 212 * 213 * @param non_edge Specify cost of non-edge pixels. Type is CV_8UC1. Expected values are {@code {0, 1}}. 214 * @param gradient_direction Specify gradient direction feature. Type is CV_32FC2. Values are expected to be normalized: {@code x^2 + y^2 == 1} 215 * @param gradient_magnitude Specify cost of gradient magnitude function: Type is CV_32FC1. Values should be in range {@code [0, 1]}. 216 * @param image <b>Optional parameter</b>. Must be specified if subset of features is specified (non-specified features are calculated internally) 217 * @return automatically generated 218 */ 219 public IntelligentScissorsMB applyImageFeatures(Mat non_edge, Mat gradient_direction, Mat gradient_magnitude, Mat image) { 220 return new IntelligentScissorsMB(applyImageFeatures_0(nativeObj, non_edge.nativeObj, gradient_direction.nativeObj, gradient_magnitude.nativeObj, image.nativeObj)); 221 } 222 223 /** 224 * Specify custom features of input image 225 * 226 * Customized advanced variant of applyImage() call. 227 * 228 * @param non_edge Specify cost of non-edge pixels. Type is CV_8UC1. Expected values are {@code {0, 1}}. 229 * @param gradient_direction Specify gradient direction feature. Type is CV_32FC2. Values are expected to be normalized: {@code x^2 + y^2 == 1} 230 * @param gradient_magnitude Specify cost of gradient magnitude function: Type is CV_32FC1. Values should be in range {@code [0, 1]}. 231 * @return automatically generated 232 */ 233 public IntelligentScissorsMB applyImageFeatures(Mat non_edge, Mat gradient_direction, Mat gradient_magnitude) { 234 return new IntelligentScissorsMB(applyImageFeatures_1(nativeObj, non_edge.nativeObj, gradient_direction.nativeObj, gradient_magnitude.nativeObj)); 235 } 236 237 238 // 239 // C++: void cv::segmentation::IntelligentScissorsMB::buildMap(Point sourcePt) 240 // 241 242 /** 243 * Prepares a map of optimal paths for the given source point on the image 244 * 245 * <b>Note:</b> applyImage() / applyImageFeatures() must be called before this call 246 * 247 * @param sourcePt The source point used to find the paths 248 */ 249 public void buildMap(Point sourcePt) { 250 buildMap_0(nativeObj, sourcePt.x, sourcePt.y); 251 } 252 253 254 // 255 // C++: void cv::segmentation::IntelligentScissorsMB::getContour(Point targetPt, Mat& contour, bool backward = false) 256 // 257 258 /** 259 * Extracts optimal contour for the given target point on the image 260 * 261 * <b>Note:</b> buildMap() must be called before this call 262 * 263 * @param targetPt The target point 264 * @param contour The list of pixels which contains optimal path between the source and the target points of the image. Type is CV_32SC2 (compatible with {@code std::vector<Point>}) 265 * @param backward Flag to indicate reverse order of retrived pixels (use "true" value to fetch points from the target to the source point) 266 */ 267 public void getContour(Point targetPt, Mat contour, boolean backward) { 268 getContour_0(nativeObj, targetPt.x, targetPt.y, contour.nativeObj, backward); 269 } 270 271 /** 272 * Extracts optimal contour for the given target point on the image 273 * 274 * <b>Note:</b> buildMap() must be called before this call 275 * 276 * @param targetPt The target point 277 * @param contour The list of pixels which contains optimal path between the source and the target points of the image. Type is CV_32SC2 (compatible with {@code std::vector<Point>}) 278 */ 279 public void getContour(Point targetPt, Mat contour) { 280 getContour_1(nativeObj, targetPt.x, targetPt.y, contour.nativeObj); 281 } 282 283 284 @Override 285 protected void finalize() throws Throwable { 286 delete(nativeObj); 287 } 288 289 290 291 // C++: cv::segmentation::IntelligentScissorsMB::IntelligentScissorsMB() 292 private static native long IntelligentScissorsMB_0(); 293 294 // C++: IntelligentScissorsMB cv::segmentation::IntelligentScissorsMB::setWeights(float weight_non_edge, float weight_gradient_direction, float weight_gradient_magnitude) 295 private static native long setWeights_0(long nativeObj, float weight_non_edge, float weight_gradient_direction, float weight_gradient_magnitude); 296 297 // C++: IntelligentScissorsMB cv::segmentation::IntelligentScissorsMB::setGradientMagnitudeMaxLimit(float gradient_magnitude_threshold_max = 0.0f) 298 private static native long setGradientMagnitudeMaxLimit_0(long nativeObj, float gradient_magnitude_threshold_max); 299 private static native long setGradientMagnitudeMaxLimit_1(long nativeObj); 300 301 // C++: IntelligentScissorsMB cv::segmentation::IntelligentScissorsMB::setEdgeFeatureZeroCrossingParameters(float gradient_magnitude_min_value = 0.0f) 302 private static native long setEdgeFeatureZeroCrossingParameters_0(long nativeObj, float gradient_magnitude_min_value); 303 private static native long setEdgeFeatureZeroCrossingParameters_1(long nativeObj); 304 305 // C++: IntelligentScissorsMB cv::segmentation::IntelligentScissorsMB::setEdgeFeatureCannyParameters(double threshold1, double threshold2, int apertureSize = 3, bool L2gradient = false) 306 private static native long setEdgeFeatureCannyParameters_0(long nativeObj, double threshold1, double threshold2, int apertureSize, boolean L2gradient); 307 private static native long setEdgeFeatureCannyParameters_1(long nativeObj, double threshold1, double threshold2, int apertureSize); 308 private static native long setEdgeFeatureCannyParameters_2(long nativeObj, double threshold1, double threshold2); 309 310 // C++: IntelligentScissorsMB cv::segmentation::IntelligentScissorsMB::applyImage(Mat image) 311 private static native long applyImage_0(long nativeObj, long image_nativeObj); 312 313 // C++: IntelligentScissorsMB cv::segmentation::IntelligentScissorsMB::applyImageFeatures(Mat non_edge, Mat gradient_direction, Mat gradient_magnitude, Mat image = Mat()) 314 private static native long applyImageFeatures_0(long nativeObj, long non_edge_nativeObj, long gradient_direction_nativeObj, long gradient_magnitude_nativeObj, long image_nativeObj); 315 private static native long applyImageFeatures_1(long nativeObj, long non_edge_nativeObj, long gradient_direction_nativeObj, long gradient_magnitude_nativeObj); 316 317 // C++: void cv::segmentation::IntelligentScissorsMB::buildMap(Point sourcePt) 318 private static native void buildMap_0(long nativeObj, double sourcePt_x, double sourcePt_y); 319 320 // C++: void cv::segmentation::IntelligentScissorsMB::getContour(Point targetPt, Mat& contour, bool backward = false) 321 private static native void getContour_0(long nativeObj, double targetPt_x, double targetPt_y, long contour_nativeObj, boolean backward); 322 private static native void getContour_1(long nativeObj, double targetPt_x, double targetPt_y, long contour_nativeObj); 323 324 // native support for java finalize() 325 private static native void delete(long nativeObj); 326 327}