joonb14 / GoodScanner

Other
6 stars 3 forks source link

Document Contour Detection #5

Open blue-hope opened 2 years ago

joonb14 commented 2 years ago
// TODO : Image preprocessing - Find Contour
fun findContours(outmat: Mat): ArrayList<MatOfPoint?>? {
    val hierarchy = Mat()
    val contours: List<MatOfPoint> = ArrayList<MatOfPoint>()
    Imgproc.findContours(outmat, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE)
    val maxArea = 100.0
    var maxAreaIdx = -1
    val contourArray: ArrayList<MatOfPoint?> = ArrayList<MatOfPoint?>()
    for (idx in contours.indices) {
        val contour: MatOfPoint = contours[idx]
        val contourArea = Imgproc.contourArea(contour)
        if (contourArea > maxArea) {
            // maxArea = contourArea;
            maxAreaIdx = idx
            contourArray.add(contour)
            //  Imgproc.drawContours(image, contours, maxAreaIdx, new Scalar(0,0, 255));
        }
    }
    return contourArray
}
joonb14 commented 2 years ago

되긴하지만 성능 개선 필요