java contour_java OPENCV 连通域, Imgproc.findContours 例子,参数说明

http://stackoverflow.com/questions/29491669/real-time-paper-sheet-detection-using-opencv-in-android/29492699#29492699

at srcImg; //you may want to apply Canny or some threshold before searching for contours

List contours = new ArrayList();

Mat hierarchy;

Imgproc.findContours(srcImg, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);

MatOfPoint2f mat2fsrc, mat2fdst;

Scalar color = new Scalar(250, 250, 255);

for (int i = 0; i < contours.size(); i++) {

contours.get(i).convertTo(mat2fsrc, CvType.CV_32FC2);

Imgproc.approxPolyDP(mat2fsrc, mat2fdst, 0.01 * Imgproc.arcLength(mat2fsrc, true), true);

mat2fdst.convertTo(contours.get(i), CvType.CV_32S);

Imgproc.drawContours(srcImg, contours, i, color, 2, 8, hierarchy, 0, new Point());

}

===================================================================================================================================================================================================================

http://stackoverflow.com/questions/23134304/crop-out-part-from-images-findcontours-opencv-java

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

// reading image

Mat image = Highgui.imread(".\\testing2.jpg", Highgui.CV_LOAD_IMAGE_GRAYSCALE);

// clone the image

Mat original = image.clone();

// thresholding the image to make a binary image

Imgproc.threshold(image, image, 100, 128, Imgproc.THRESH_BINARY_INV);

// find the center of the image

double[] centers = {(double)image.width()/2, (double)image.height()/2};

Point image_center = new Point(centers);

// finding the contours

ArrayList contours = new ArrayList();

Mat hierarchy = new Mat();

Imgproc.findContours(image, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

// finding best bounding rectangle for a contour whose distance is closer to the image center that other ones

double d_min = Double.MAX_VALUE;

Rect rect_min = new Rect();

for (MatOfPoint contour : contours) {

Rect rec = Imgproc.boundingRect(contour);

// find the best candidates

if (rec.height > image.height()/2 & rec.width > image.width()/2)

continue;

Point pt1 = new Point((double)rec.x, (double)rec.y);

Point center = new Point(rec.x+(double)(rec.width)/2, rec.y +

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值