Last active
October 13, 2016 14:20
-
-
Save hazam/7edd89250840feef171bc9709cfc6d03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Core.inRange(mHsvMat, ncb.lowerBound, ncb.upperBound, mMask) | |
Imgproc.dilate(mMask, mDilatedMask, kernel) | |
val contours = ArrayList<MatOfPoint>() | |
Imgproc.findContours(mDilatedMask, contours, mHierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE) | |
// Imgproc.drawContours(rgbaImage, contours, -1, new Scalar( 0,255, 0, 255)); | |
// Find max contour area | |
var maxArea = 0.0 | |
var each = contours.iterator() | |
while (each.hasNext()) { | |
val wrapper = each.next() | |
if (isProbablyAMarker(wrapper, -1.0)) { | |
val area = Imgproc.contourArea(wrapper) | |
if (area > maxArea) { | |
maxArea = area | |
} | |
} | |
} | |
each = contours.iterator() | |
while (each.hasNext()) { | |
val contour = each.next() | |
if (isProbablyAMarker(contour, maxArea)) { | |
Core.multiply(contour, Scalar(2.0, 2.0), contour) | |
val area = Imgproc.contourArea(contour) | |
Timber.i("AREA", ncb.id + "AREA " + area) | |
mContours.add(contour) | |
val mu = Imgproc.moments(contour, false) | |
ncb.centroid.x = x + mu._m10 / mu._m00 | |
ncb.centroid.y = y + mu._m01 / mu._m00 | |
if (detected.contains(ncb)) | |
detected.remove(ncb) | |
detected.add(ncb) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment