Пример #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)
Пример #2
0
def fakeEyes(photoArray):
    print("fakeEyes ran")
    for photo in photoArray:
        # m3Show.imshow(photo.originalImage,"asdfasdf")
        temp = []
        temp.append(m3Class.Face([m3Class.Eye(photo.originalImage)]))
        photo.faces = temp
    return photoArray
Пример #3
0
def findEyes(photo, division, show=True):
    # print("photo type", type(photo))
    h, w, c = photo.originalImage.shape

    # downScaledDim = (round(w/100 *(scalePercent)),round(h/100 * (scalePercent)))
    downScaledDim = ((round(w / division)), round(h / division))
    copy = photo.originalImage.copy()
    pil_image = Image.fromarray(copy)
    inputImg = copy
    inputImg = cv2.resize(inputImg, downScaledDim)
    dimToScaleUp = division
    # if show:
    # print("originalShape", h, w, c)
    # print("downScaledDim", downScaledDim)
    # m3Show.imshow(m3F.typeSwap(pil_image), "image to find eyes on")
    # m3Show.imshow(photo.originalImage, " FINDEYS TEST")
    # print("proccesing", inputImgPath),

    # inputImg = cv2.imread(inputImgPath)

    face_landmarks_list = face_recognition.face_landmarks(inputImg)
    #print("I found {} face(s) in this photograph.".format(len(face_landmarks_list)))
    #print("face_landmarks_list type was", type(face_landmarks_list))
    # Create a PIL imagedraw object so we can draw on the picture
    # pil_image = Image.fromarray(inputImg)

    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:

        lEyeCoor = face_landmarks['left_eye']
        rEyeCoor = face_landmarks['right_eye']
        print()
        mg = (lEyeCoor[3][0] - lEyeCoor[0][0]) * 0.2 * 10

        # **********************************************************************
        imgwithPoints = inputImg.copy()
        for eye in (lEyeCoor, rEyeCoor):
            for x, y in eye:
                imgwithPoints = cv2.rectangle(imgwithPoints, (x - 2, y - 20),
                                              (x + 20, y + 20), (0, 0, 255),
                                              -1)
        # **********************************************************************
        # if debug:
        #     m3Show.imshow(imgwithPoints, "with points")
        eyes = []
        for eyeLandmarkPoints in lEyeCoor, rEyeCoor:
            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)
            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 = []
            for x, y in eyeLandmarkPoints:
                upscaledLandmarks.append((x * division, y * division))
                # y = y * division
            # print("upscaledLandmarks", upscaledLandmarks)
            eyes.append(
                m3Class.Eye(np.asarray(pil_image.crop(cropRect)), cropRect,
                            upscaledLandmarks))
        faces.append(m3Class.Face(eyes))
    return faces
Пример #4
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
Пример #5
0
def run(tempeye, tempResolution, tempMin_dist, tempParam_1, tempParam_2,
        tempMinRadius, tempMaxRadius, tempShow):
    print(
        "***************************************************************************************"
    )

    img = tempeye
    print(tempMinRadius)
    isEyeClass = False
    eye = None
    if isinstance(img, type(m3Class.Eye())):
        isEyeClass = True
        eye = tempeye
        img = eye.wip
    if not isinstance(img, type(None)):
        cimg = img

        if len(img.shape) == 3:
            img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

        circles = cv2.HoughCircles(img,
                                   cv2.HOUGH_GRADIENT,
                                   tempResolution,
                                   tempMin_dist,
                                   param1=tempParam_1,
                                   param2=tempParam_2,
                                   minRadius=tempMinRadius,
                                   maxRadius=tempMaxRadius)

        #        circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,,120,param1=200,param2=10,
        #                                   minRadius=int(m3F.typeSwap(img).height/6),maxRadius=int(m3F.typeSwap(img).height/2.5))

        if not isinstance(circles, type(None)):

            if (circles.size != 0):
                circles = np.uint16(np.around(circles))
                # print(circles)
                index = 0
                for i in circles[0, :]:
                    #if img[i[1],i[0]] < 15:

                    # draw the outer circle
                    cv2.circle(cimg, (i[0], i[1]), i[2], (0, 255 - index, 0),
                               2)
                    # draw the center of the circle
                    cv2.circle(cimg, (i[0], i[1]), 2, (0, 0, 255 - index), 3)
                    index += 30

            if (tempShow):
                m3F.imshow(cimg, "Circle")
                m3F.printGreen("CIRCLES FOUND^^^")
                print("img out", img.shape)
            if isEyeClass:
                eye.circle = circles
                print("RETURNED AN EYE WITH CIRCLES")
                return eye
            else:
                return img
        else:
            if (tempShow):
                m3F.imshow(cimg, "no circles found")
                m3F.printRed("NO CIRCLES FOUND^^^")
    else:
        m3F.printRed("Image is NONE")