Esempio n. 1
0
def findCircleSimpleEdge(eye, show):
    #run(eye, 1, 120, 60, 15, 10, 100, show)
    # print("eye type", type(eye))
    if isinstance(eye, type(m3Class.Eye())):
        run(eye, 1, 120, 200, 10, int(m3F.typeSwap(eye.wip).width), 0, show)
    else:
        run(eye, 1, 120, 200, 10, int(m3F.typeSwap(eye).width), 0, show)
Esempio n. 2
0
def findCircle(eye, resolution, min_dist, param_1, param_2,
               min_radius_width_divider, max_radius_width_divider, show):
    # old params for HoughCircle: img, cv2.HOUGH_GRADIENT, 1.5, 120, param1=60, param2=15, minRadius=0, maxRadius=int(m3F.typeSwap(img).height / 2))
    min_radius = int(m3F.typeSwap(eye.wip).width / min_radius_width_divider)
    max_radius = int(m3F.typeSwap(eye.wip).width / max_radius_width_divider)
    run(eye, resolution, min_dist, param_1, param_2, min_radius, max_radius,
        show)
Esempio n. 3
0
def removeEyelid(eye, show):
    gray = cv2.cvtColor(eye.iris, cv2.COLOR_BGR2GRAY)
    
    (minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(gray)

    height, width = gray.shape

    grayPil = m3F.typeSwap(gray)

    for i in eye.circle[0, :]:
        for y in range(width-1):
            for x in range(height-1):
                pixel = grayPil.getpixel((y,x))

                if math.sqrt(((y-i[0])**2)+((x-i[1])**2)) < i[2] and pixel != maxVal:
                    gray[x, y] = 255
                else:
                    gray[x,y] = 0
        break

    m3F.imshow(gray, "iris")

    kernel1 = np.ones((15, 15), np.uint8)
    kernel2 = np.ones((7, 7), np.uint8)
    closing1 = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel1,iterations=3)
    opening = cv2.morphologyEx(gray, cv2.MORPH_OPEN, kernel2)

    m3F.imshow(closing1,"closed. Kernel 15, 3 iterations")
    m3F.imshow(opening,"opened. Kernel 7")

    return closing1
def removeEyelid(eye, show):
    #m3F.imshow(eye.iris,"removeEyelid")
    print("type: eye, iris -", type(eye), type(eye.iris))
    print("length of iris -", len(eye.iris))
    gray = cv2.cvtColor(eye.iris, cv2.COLOR_BGR2GRAY)
    (minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(gray)
    print("maxVal", maxVal)
    print("minVal", minVal)

    height, width = gray.shape

    grayPil = m3F.typeSwap(gray)

    for i in eye.circle[0, :]:
        for y in range(width - 1):
            for x in range(height - 1):
                pixel = grayPil.getpixel((y, x))
                #print("pixel",pixel)
                if math.sqrt(((y - i[0])**2) + ((x - i[1])**2)) < i[2]:
                    if pixel != maxVal or math.sqrt(((y - i[0])**2) + (
                        (x - i[1])**2)) < i[2] / 2:
                        gray[x, y] = 255

                    else:
                        #print("done here")
                        #gray.putpixel((x,y),minVal)
                        gray[x, y] = 0
        break

    #gray = m3F.typeSwap(gray)

    m3F.imshow(gray, "iris blob")

    kernel1 = np.ones((15, 15), np.uint8)
    kernel2 = np.ones((7, 7), np.uint8)
    closing1 = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel1, iterations=3)
    #closing2 = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel2)
    opening = cv2.morphologyEx(gray, cv2.MORPH_OPEN, kernel2)

    m3F.imshow(closing1, "closed. Kernel 15, 3 iterations")
    m3F.imshow(opening, "opened. Kernel 7")
    #m3F.imshow(closing2,"closed. Kernel 3")
    return closing1
Esempio n. 5
0
def findEyes68(photo, division, show=True, debug=False):
    h, w, c = photo.originalImage.shape
    downScaledDim = ((round(w/division)), round(h/division))
    copy = photo.originalImage.copy()
    pil_image = Image.fromarray(copy)
    inputImg = copy
    inputImg = cv2.resize(inputImg, downScaledDim)
    photo.loResImage = inputImg

    if debug:
        print("originalShape", h, w, c)
        print("downScaledDim", downScaledDim)
        m3Show.imshow(m3F.typeSwap(pil_image), "image to find eyes on")

    face_landmarks_list = face_recognition.face_landmarks(inputImg)

    if debug:
        print("I found {} face(s) in this photograph.".format(len(face_landmarks_list)))
        print("face_landmarks_list type was", type(face_landmarks_list))

    if (len(face_landmarks_list) == 0):

        m3F.printRed(" found no faces in this picture")
        plt.imshow(cv2.cvtColor(inputImg, cv2.COLOR_RGB2BGR))
        plt.show()
        return [m3Class.Face(noFaceImg=inputImg)]

    faces = []
    for face_landmarks in face_landmarks_list:

        LeftEyeLandmarks = face_landmarks['left_eye']
        rightEyeLandmarks = face_landmarks['right_eye']

        # imgwithPoints = inputImg.copy()
        # for eye in (LeftEyeLandmarks, rightEyeLandmarks):
        #     for x, y in eye:
        #         imgwithPoints = cv2.rectangle(imgwithPoints, (x - 20, y - 20), (x + 20, y + 20), (0, 0, 255), -1)
        # **********************************************************************
        # if debug:
        #     m3Show.imshow(imgwithPoints, "with points")
        eyes = []
        for eyeLandmarkPoints in LeftEyeLandmarks, rightEyeLandmarks:
            xs, ys = [], []
            for x, y in eyeLandmarkPoints:
                xs.append(x)
                ys.append(y)
                # print("x y ", x, y)
            xs.sort(reverse=True)
            ys.sort(reverse=True)
            maxX = xs[0]
            maxY = ys[0]
            xs.sort(reverse=False)
            ys.sort(reverse=False)
            minX = xs[0]
            minY = ys[0]
            # print("maxX,maxY,minX,minY", maxX, maxY, minX, minY)
            # **********************************************************************
            margin = round((maxX - minX) * 0.2   )
            cropRect = (minX - margin, minY - margin,
                        maxX + margin, maxY + margin)
            cropRectNoMargin = (minX , minY ,
                        maxX, maxY )
            # **********************************************************************
            # margin = round((maxX - minX) * 0.2)
            # cropRect = (minX, minY,
            #             maxX, maxY)
            # **********************************************************************
            cropRect = [round(division*num) for num in cropRect]
            # for num in margin: num * division
            if show:
                m3Show.imshow(np.asarray(pil_image.crop(cropRect)), "cropRect")
            upscaledLandmarks = []
            # croprect: "The box is a 4-tuple defining the left, upper, right, and lower pixel coordinate"
            croppedEye = np.asarray(pil_image.crop(cropRect))
            # print("croppedEye.shape", croppedEye.shape)
            # print("cropRect", cropRect, [round(num/division) for num in cropRect])

            for x, y in eyeLandmarkPoints:
                upscaledLandmarks.append([((x - (minX-margin)) * division), ((y-(minY-margin)) * division)])


                # upscaledLandmarks.append([x * division, y *division])
                # print("minX, x, minY, y, division", (minX, x, minY, y, division, margin))
                #
                # x = x * division
                # y = y * division
                # left = cropRect[0] + margin
                # top = cropRect[1] + margin
                # upscaledLandmarks.append((x-left)-(y-top))
                # y = y * division
            # print("upscaledLandmarks", upscaledLandmarks)
            e = m3Class.Eye(croppedEye, cropRect, upscaledLandmarks)
            print(upscaledLandmarks)
            e.mask68 = makePolyMask(croppedEye, upscaledLandmarks)
            # cv2.imwrite("EXPORTS/COMPARISONS/mask68.jpg", e.mask68)

            e.margin = margin
            e.CRnoMargin = cropRectNoMargin
            e.minX = minX
            e.minY = minY
            eyes.append(e)
        faces.append(m3Class.Face(eyes))
    return faces
Esempio n. 6
0
def findCircleSimpleDouble(eye, show):
    #run(eye, 1, 120, 60, 15, 10, 100, show)
    runDouble(eye, 1, 120, 200, 10, int(m3F.typeSwap(eye).height / 6),
              int(m3F.typeSwap(eye).height / 2.5), show)