Home:ALL Converter>Contour detection person holding paper sheet

Contour detection person holding paper sheet

Ask Time:2018-06-08T22:03:02         Author:err4o4

Json Formatter

I need to detect white paper held by a person. Problem here is fingers, which breaks contour lines. Some contours contain some sort of, I call it noise, in the shape.

Contours with fingers:
Contours with fingers

Original img:
Original img

import cv2
import imutils
import numpy as np

image = cv2.imread('test.jpg')
ratio = image.shape[0] / 500.0
orig = image.copy()
image = imutils.resize(image, height = 500)

orig = image.copy()

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (5,5), 0)
edged = cv2.Canny(gray, 100, 200)

image, cnts, hierarchy = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:10]

for c in cnts:
    # approximate the contour

    peri = cv2.arcLength(c, True)
    approx = cv2.approxPolyDP(c, 0.1 * peri, True)

    #epsilon = 0.1*cv2.arcLength(c,True)
    #approx = cv2.approxPolyDP(c,epsilon,True)
    #approx = cv2.approxPolyDP(c,0.1*cv2.arcLength(c,True),True)

    if len(approx) == 4:
        screenCnt = approx
        break


cv2.drawContours(orig, [screenCnt], -1, (0, 255, 0), 2)
cv2.imshow("Found", image)

cv2.waitKey(0)
cv2.destroyAllWindows()

And second question

How to insert image into contour

Author:err4o4,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50762401/contour-detection-person-holding-paper-sheet
yy