Пример #1
0
def draw_head(npimg,Centers,col,bol,k=[0]):
    tryvar = lambda varpos: Centers[varpos] if varpos in Centers.keys() else None
    lear = tryvar(17)
    rear = tryvar(16)
    leye = tryvar(15)
    reye = tryvar(14)
    nose = tryvar(0)
    neck = tryvar(1)

    if bol:
        k1,k2,k6 = read.k1()
        k3,k4,k5,k7,k8 = read.k2()
    else:
        k1,k2,k3,k4,k5,k6,k7,k8 = k
    
    if (neck and nose):
            
        if (lear and rear): #head circle if both ears are present
            lx = lear[0]
            rx = rear[0]
            hx = (lx + rx)/2 #Nope
            #taneyes = 0 #Bruker heller tangens her for å få en relativ vinkel.
            # Plasser etterpå "midpunktet" "over" basert på vinkel. 
            dx = int(np.linalg.norm(np.array(lear)-np.array(rear)))
            #^relation for headsize, distance between ears
            nx = neck[0] 
            hy =  int((rear[1]+lear[1])/2-dx/k2) #nope  #fight me
            earringsxl = int((lx+nx)/2.)
            earringsxr = int((rx+nx)/2.)  
            earringsy = (nose[1]+neck[1])/2 #neck nose mid
            limblen= int(dx/4)+1
            cv2.circle(npimg, (hx,hy), int(abs(dx*k1)), col, thickness=-limblen, lineType=8, shift=0)
            #limblen= int((dx/8+1)*k6)
            #cv2.line(npimg, (lx,lear[1]), (earringsxl,earringsy) , col, limblen)
            #cv2.line(npimg, (rx,rear[1]), (earringsxr,earringsy) , col, limblen)

        #head pointing left (left eye hidden)
        elif rear and leye:#head circle if right ear is present + faceline
            rx = rear[0]          
            dx = abs(leye[0]-rx)/10+1 #dist between ear n eye
            earringsxr = (rx+neck[0])/2
            earringsy = (nose[1]+neck[1])/2 #neck nose mid

            hx = int(rx+dx*4*k7) #- dx*20 / (rx-leye[0]))
            #Jacob's magic circle coord (next to ear) ?? wtf. fight me
            hy = int((rear[1]+leye[1])/2+dx*k3)
            limblen = int((dx+abs(rx-leye[0])/2)*0.4)+1
            cv2.circle(npimg, (hx,hy), int(abs(nose[0]-rx)*k4), col, thickness=-limblen, lineType=8, shift=0)
            #limblen = int((dx+1)*k5)
            #cv2.line(npimg, (leye[0]+dx,leye[1]), (leye[0]+dx,(nose[1]+neck[1])/2) , col, limblen)
            #cv2.line(npimg, (rx-int(dx*k8),rear[1]), (earringsxr-int(dx*k8),earringsy) , col,limblen)

                
        elif lear and reye:#head circle if left ear is present + faceline
            lx = lear[0]
            reyex = reye[0] 
            dx = abs(lx-reyex)/10+1
            earringsxl =(lx+neck[0])/2
            earringsy = (nose[1]+neck[1])/2 #neck nose mid
            hx = int(lx - dx*4*k7) #+ dx*20. /(lx-reyex))#circle center, next to ear
            hy = int((lear[1]+reye[1])/2+dx*k3)               #circle center, slightly above ear
            limblen = int((abs(lx-reyex)/2+dx)*k5)
            cv2.circle(npimg, (hx,hy), int(abs(nose[0]-lx)*k4), col, thickness=-limblen, lineType=8, shift=0)
            #limblen= int((dx+1)*k5)
            #cv2.line(npimg, (reyex+dx,reye[1]), (reyex+dx,(nose[1]+neck[1])/2) , col, limblen)
            #cv2.line(npimg, (lx+int(dx*k8),reye[1]), (earringsxl+int(dx*k8),earringsy) ,col, limblen)
        #NECK SIRCLE
        #r = ((neck[0]-nose[0])*(neck[0]-nose[0])+(neck[1]-nose[1])*(neck[1]-nose[1]))/200
        #cv2.circle(npimg, (neck[0],neck[1]), r, col, thickness=-1, lineType=8, shift=0)

    return npimg
Пример #2
0
def draw_head(npimg, imgog, Centers, col, bol, k=[0]):
    tryvar = lambda varpos: Centers[varpos] if varpos in Centers.keys(
    ) else None
    lear = tryvar(17)
    rear = tryvar(16)
    leye = tryvar(15)
    reye = tryvar(14)
    nose = tryvar(0)
    neck = tryvar(1)

    if bol:
        k1, k2, k6 = read.k1()
        k3, k4, k5, k7, k8 = read.k2()
    else:
        k1, k2, k3, k4, k5, k6, k7, k8 = k

    if (neck and nose):

        if (lear and rear):  #head circle if both ears are present
            lx = lear[0]
            rx = rear[0]
            hx = (lx + rx) / 2  #Nope
            angle = 0
            dy = lear[1] - rear[1]
            dx = float(lx - rx)
            if dy and dx:
                taneyes = dy / dx  #Bruker heller tangens her for å få en relativ vinkel.
                angle = np.arctan(taneyes) * 180 / np.pi

            # Plasser etterpå "midpunktet" "over" basert på vinkel.
            dx = int(np.linalg.norm(np.array(lear) - np.array(rear)))
            #^relation for headsize, distance between ears
            hy = int((rear[1] + lear[1]) / 2)  #-dx/k2) #nope  #fight me
            hy2 = hy - int(dx / 2.5)
            #limblen= int(dx/4)+1
            #l =8.*dx/(abs(nose[1]-neck[1])+1)
            #cv2.circle(npimg, (hx,hy), int(abs(dx*k1)), col, thickness=-limblen, lineType=8, shift=0)
            cv2.ellipse(npimg, (hx, hy),
                        (int(dx * k1 / 1.3), int(dx * k1 * 1.5)), angle, 180,
                        360, col, -1)
            cv2.ellipse(npimg, (hx + int(angle), hy2),
                        (int(dx * k1 / 1.2), int(dx * k1 / 1.3)), angle, 0,
                        360, col, -1)
            # Addition; jawline from helper funct.
            eye_jaw(npimg, [leye, reye], [False, False], col)
        #head pointing left (left eye hidden)
        elif rear and leye:  #head circle if right ear is present + faceline
            rx = rear[0]
            dx = leye[0] - rx  #/10+1 #dist between ear n eye
            dy = (leye[1] - rear[1])
            angle = 0
            if dy and dx:
                tan = dy / float(dx)
                angle = np.arctan(tan) * 180 / np.pi
            dx = int(np.linalg.norm(np.array(rear) - np.array(leye)))

            hx = int(rx + dx / 10. * 4 * k7 * 0.95)  #- dx*20 / (rx-leye[0]))
            #Jacob's magic circle coord (next to ear) ?? wtf. fight me ????
            hy = int((rear[1] + leye[1]) / 2 + dx / 10. * k3 * 1.6)
            hy2 = hy - dx / 10

            #limblen = int((dx+abs(rx-leye[0])/2)*0.4)+1
            #cv2.circle(npimg, (hx,hy), int(abs(nose[0]-rx)*k4), col, thickness=-limblen, lineType=8, shift=0)
            cv2.ellipse(npimg, (hx, hy),
                        (int(dx * k4 * 0.85), int(dx * k4 * 0.73)),
                        -angle - 20, 0, 360, col, -1)
            #cv2.ellipse(npimg,(hx,hy2),(int(abs(nose[0]-rx)*k4*0.85),int(abs(nose[0]-rx)*k4*0.65))  ,-20,0,360,col,-1)
            eye_jaw(npimg, [leye, reye], [False, rear], col)
        elif lear and reye:  #head circle if left ear is present + faceline
            lx = lear[0]
            reyex = reye[0]
            dx = (lx - reyex)  #/10+1
            dy = (lear[1] - reye[1])
            angle = 0
            if dy and dx:
                tan = dy / float(dx)
                angle = np.arctan(tan) * 180 / np.pi
            dx = int(np.linalg.norm(np.array(lear) - np.array(reye)))
            hx = int(lx - dx / 10. * 4 * k7 *
                     0.9)  #+ dx*20. /(lx-reyex))#circle center, next to ear
            hy = int((lear[1] + reye[1]) / 2 +
                     dx / 10. * k3 * 1.6)  #circle center, slightly above ear
            hy2 = hy - dx / 10
            #limblen = int((abs(lx-reyex)/2+dx)*k5)
            #cv2.circle(npimg, (hx,hy), int(abs(nose[0]-lx)*k4), col, thickness=-limblen, lineType=8, shift=0)
            cv2.ellipse(npimg, (hx, hy),
                        (int(dx * k4 * 0.85), int(dx * k4 * 0.73)),
                        -angle + 20, 0, 360, col, -1)
            #cv2.ellipse(npimg,(hx,hy2),(int(abs(nose[0]-lx)*k4*0.85),int(abs(nose[0]-lx)*k4*0.65))  ,20,0,360,col,-1)
            eye_jaw(npimg, [leye, reye], [lear, False], col)

    return npimg
Пример #3
0
def draw_humans(npimg, humans, bol=1, k=[0]):
    npimg *= 0
    image_h, image_w = npimg.shape[:2]
    centers = {}
    col = [255, 255, 255]
    if bol:
        k1, k2, k6 = read.k1()
        k3, k4, k5, k7, k8 = read.k2()
    else:
        k1, k2, k3, k4, k5, k6, k7, k8 = k

    for human in humans:
        # draw point

        Centers = {}
        for i in range(common.CocoPart.Background.value):
            if i not in human.body_parts.keys():
                continue

            body_part = human.body_parts[i]
            center = (int(body_part.x * image_w + 0.5),
                      int(body_part.y * image_h + 0.5))
            centers[i] = center
            Centers[i] = center
            #cv2.circle(npimg, center, 3, common.CocoColors[i], thickness=3, lineType=8, shift=0)

        #this is we're we customize the lines and circles around the human

        #BRRRÆPP
        # Generell rekkefølge for testser: (begge ører)
        #                                  (øre motsatt øye)
        #                                  (øye øye)
        #                                  (ett øye)
        # Som cond-ish liste:
        tryvar = lambda varpos: Centers[varpos] if varpos in Centers.keys(
        ) else None
        lear = tryvar(17)
        rear = tryvar(16)
        leye = tryvar(15)
        reye = tryvar(14)
        nose = tryvar(0)
        neck = tryvar(1)
        lshould = tryvar(5)
        rshould = tryvar(2)
        lhip = tryvar(11)
        rhip = tryvar(8)
        lelb = tryvar(6)
        relb = tryvar(3)
        lwrist = tryvar(7)
        rwrist = tryvar(4)
        lankle = tryvar(13)
        rankle = tryvar(10)
        lknee = tryvar(12)
        rknee = tryvar(9)
        #head and neck
        if (lear and rear and neck
                and nose):  #head circle if both ears are present
            lx = lear[0]
            rx = rear[0]
            hx = (lx + rx) / 2  #Nope
            #taneyes = 0 #Bruker heller tangens her for å få en relativ vinkel.
            # Plasser etterpå "midpunktet" "over" basert på vinkel.
            dx = int(np.linalg.norm(np.array(lear) - np.array(rear)))
            #^relation for headsize, distance between ears
            nx = neck[0]
            hy = int((rear[1] + lear[1]) / 2 - dx / k2)  #nope  #fight me
            earringsxl = int((lx + nx) / 2.)
            earringsxr = int((rx + nx) / 2.)
            earringsy = (nose[1] + neck[1]) / 2  #neck nose mid
            limblen = int(dx / 4) + 1
            cv2.circle(npimg, (hx, hy),
                       int(abs(dx * k1)),
                       col,
                       thickness=-limblen,
                       lineType=8,
                       shift=0)
            limblen = int((dx / 8 + 1) * k6)
            cv2.line(npimg, (lx, lear[1]), (earringsxl, earringsy), col,
                     limblen)
            cv2.line(npimg, (rx, rear[1]), (earringsxr, earringsy), col,
                     limblen)

        #head pointing left (left eye hidden)
        elif rear and neck and leye and nose:  #head circle if right ear is present + faceline
            rx = rear[0]
            dx = abs(leye[0] - rx) / 10 + 1  #dist between ear n eye
            earringsxr = (rx + neck[0]) / 2
            earringsy = (nose[1] + neck[1]) / 2  #neck nose mid

            hx = int(rx + dx * 4 * k7)  #- dx*20 / (rx-leye[0]))
            #Jacob's magic circle coord (next to ear) ?? wtf. fight me
            hy = int((rear[1] + leye[1]) / 2 + dx * k3)
            limblen = int((dx + abs(rx - leye[0]) / 2) * 0.4) + 1
            cv2.circle(npimg, (hx, hy),
                       int(abs(nose[0] - rx) * k4),
                       col,
                       thickness=-limblen,
                       lineType=8,
                       shift=0)
            limblen = int((dx + 1) * k5)
            cv2.line(npimg, (leye[0] + dx, leye[1]),
                     (leye[0] + dx, (nose[1] + neck[1]) / 2), col, limblen)
            cv2.line(npimg, (rx - int(dx * k8), rear[1]),
                     (earringsxr - int(dx * k8), earringsy), col, limblen)

        elif lear and neck and reye and nose:  #head circle if left ear is present + faceline
            lx = lear[0]
            reyex = reye[0]
            dx = abs(lx - reyex) / 10 + 1
            earringsxl = (lx + neck[0]) / 2
            earringsy = (nose[1] + neck[1]) / 2  #neck nose mid
            hx = int(
                lx -
                dx * 4 * k7)  #+ dx*20. /(lx-reyex))#circle center, next to ear
            hy = int((lear[1] + reye[1]) / 2 +
                     dx * k3)  #circle center, slightly above ear
            limblen = int((abs(lx - reyex) / 2 + dx) * k5)
            cv2.circle(npimg, (hx, hy),
                       int(abs(nose[0] - lx) * k4),
                       col,
                       thickness=-limblen,
                       lineType=8,
                       shift=0)
            limblen = int((dx + 1) * k5)
            cv2.line(npimg, (reyex + dx, reye[1]),
                     (reyex + dx, (nose[1] + neck[1]) / 2), col, limblen)
            cv2.line(npimg, (lx + int(dx * k8), reye[1]),
                     (earringsxl + int(dx * k8), earringsy), col, limblen)

        #shoulder throat connections
        if nose and neck and rshould and lshould:
            #right shoulder to throat
            throaty = (nose[1] + neck[1]) / 2  #neck nose mid
            throatx = (nose[0] + neck[0]) / 2  #neck nose mid
            limblen = int(abs(rshould[0] - lshould[0])) / 12 + 1
            #left shoulder to throat
            cv2.line(npimg, (rshould[0], rshould[1] - limblen / 2),
                     (throatx, throaty), col, limblen)
            cv2.line(npimg, (lshould[0], lshould[1] - limblen / 2),
                     (throatx, throaty), col, limblen)

        #shoulder hip connections
        if rhip and rshould:  #right hip
            hipy = rhip[1]  #neck nose mid
            hipx = rhip[0]  #neck nose mid
            shouldx = rshould[0]
            shouldy = rshould[1]
            limblen = int(
                np.sqrt((shouldx - hipx) * (shouldx - hipx) +
                        (shouldy - hipy) * (shouldy - hipy))) / 10 + 1
            cv2.line(npimg, (hipx, hipy), (shouldx, shouldy), col, limblen)

        if lhip and lshould:  #left hip
            hipy = lhip[1]  #neck nose mid
            hipx = lhip[0]  #neck nose mid
            shouldx = lshould[0]
            shouldy = lshould[1]
            limblen = int(
                np.sqrt((shouldx - hipx) * (shouldx - hipx) +
                        (shouldy - hipy) * (shouldy - hipy))) / 10 + 1
            cv2.line(npimg, (hipx, hipy), (shouldx, shouldy), col, limblen)

        if relb and rshould:  #right bicep

            bowy = relb[1]  #neck nose mid
            bowx = relb[0]  #neck nose mid
            shouldx = rshould[0]
            shouldy = rshould[1]
            d = int(
                np.sqrt((bowy - shouldy) * (bowy - shouldy) +
                        (bowx - shouldx) * (bowx - shouldx)) / 10)
            limblen = d + 1
            cv2.line(npimg, (shouldx + 2 * d, shouldy + 2 * d),
                     (bowx + 2 * d, bowy + 2 * d), col, limblen)
            cv2.line(npimg, (shouldx - d, shouldy - d), (bowx - d, bowy - d),
                     col, limblen)

        if lelb and lshould:  #left bicep

            bowy = lelb[1]  #neck nose mid
            bowx = lelb[0]  #neck nose mid
            shouldx = lshould[0]
            shouldy = lshould[1]
            d = int(
                np.sqrt((bowy - shouldy) * (bowy - shouldy) +
                        (bowx - shouldx) * (bowx - shouldx)) / 10)
            limblen = d + 1
            cv2.line(npimg, (bowx + d, bowy - d),
                     (shouldx + 2 * d, shouldy - d), col, limblen)
            cv2.line(npimg, (bowx - d, bowy + 2 * d),
                     (shouldx - d, shouldy + 2 * d), col, limblen)

        if relb and rwrist:  #right elbow-wrist
            bowy = relb[1]  #neck nose mid
            bowx = relb[0]  #neck nose mid
            wristx = rwrist[0]
            wristy = rwrist[1]
            dx = 1. * bowx - wristx
            dy = 1. * bowy - wristy
            d = int(np.sqrt((dy) * (dy) + (dx) * (dx)))
            normal = np.array([-dy / d, dx / d]) * d / 5.

            limblen = d / 8 + 1

            cv2.line(npimg, (bowx + int(normal[0]), bowy + int(normal[1])),
                     (wristx + int(normal[0]), wristy + int(normal[1])), col,
                     limblen)
            cv2.line(npimg, (bowx - int(normal[0]), bowy - int(normal[1]) / 2),
                     (wristx - int(normal[0]), wristy - int(normal[1]) / 2),
                     col, limblen)

        if lelb and lwrist:  #left elbow-wrist
            bowy = lelb[1]  #neck nose mid
            bowx = lelb[0]  #neck nose mid
            wristx = lwrist[0]
            wristy = lwrist[1]
            dx = 1. * bowx - wristx
            dy = 1. * bowy - wristy
            d = int(np.sqrt((dy) * (dy) + (dx) * (dx)))
            normal = np.array([-dy / d, dx / d]) * d / 5.

            limblen = d / 8 + 1

            cv2.line(npimg, (bowx + int(normal[0]), bowy + int(normal[1])),
                     (wristx + int(normal[0]), wristy + int(normal[1])), col,
                     limblen)
            cv2.line(npimg, (bowx - int(normal[0]), bowy - int(normal[1]) / 2),
                     (wristx - int(normal[0]), wristy - int(normal[1]) / 2),
                     col, limblen)

        if rhip and rknee:  #right elbow-wrist
            hipy = rhip[1]
            hipx = rhip[0]
            kx = rknee[0]
            ky = rknee[1]
            dx = 1. * hipx - kx
            dy = 1. * hipy - ky
            d = int(np.sqrt((dy) * (dy) + (dx) * (dx)))
            normal = np.array([-dy / d, dx / d]) * d / 5.

            limblen = d / 7 + 1

            cv2.line(npimg, (hipx + int(normal[0]), hipy + int(normal[1])),
                     (kx + int(normal[0]), ky + int(normal[1])), col, limblen)
            cv2.line(npimg, (hipx - int(normal[0]), hipy - int(normal[1])),
                     (kx - int(normal[0]), ky - int(normal[1])), col, limblen)

        if lhip and lknee:  #right elbow-wrist
            hipy = lhip[1]
            hipx = lhip[0]
            kx = lknee[0]
            ky = lknee[1]
            dx = 1. * hipx - kx
            dy = 1. * hipy - ky
            d = int(np.sqrt((dy) * (dy) + (dx) * (dx)))
            normal = np.array([-dy / d, dx / d]) * d / 5.

            limblen = d / 7 + 1

            cv2.line(npimg, (hipx + int(normal[0]), hipy + int(normal[1])),
                     (kx + int(normal[0]), ky + int(normal[1])), col, limblen)
            cv2.line(npimg, (hipx - int(normal[0]), hipy - int(normal[1])),
                     (kx - int(normal[0]), ky - int(normal[1])), col, limblen)

        if rankle and rknee:  #right elbow-wrist
            ay = rankle[1]
            ax = rankle[0]
            kx = rknee[0]
            ky = rknee[1]
            dx = 1. * kx - ax
            dy = 1. * ky - ay
            d = int(np.sqrt((dy) * (dy) + (dx) * (dx)))
            normal = np.array([-dy / d, dx / d]) * d / 5.

            limblen = d / 7 + 1

            cv2.line(npimg, (kx + int(normal[0]), ky + int(normal[1])),
                     (ax + int(normal[0]), ay + int(normal[1])), col, limblen)
            cv2.line(npimg, (kx - int(normal[0]), ky - int(normal[1])),
                     (ax - int(normal[0]), ay - int(normal[1])), col, limblen)

        if lankle and lknee:  #right elbow-wrist
            ay = lankle[1]
            ax = lankle[0]
            kx = lknee[0]
            ky = lknee[1]
            dx = 1. * kx - ax
            dy = 1. * ky - ay
            d = int(np.sqrt((dy) * (dy) + (dx) * (dx)))
            normal = np.array([-dy / d, dx / d]) * d / 5.

            limblen = d / 7 + 1

            cv2.line(npimg, (kx + int(normal[0]), ky + int(normal[1])),
                     (ax + int(normal[0]), ay + int(normal[1])), col, limblen)
            cv2.line(npimg, (kx - int(normal[0]), ky - int(normal[1])),
                     (ax - int(normal[0]), ay - int(normal[1])), col, limblen)

    return npimg, centers