Example #1
0
def GUI():
    speak_thr = threading.Thread(target=speak)
    cnt = 0
    global mapCurr, frame, closestLabel, lang
    loop = True

    confidence = 0

    tempt, hum, wind, status = weather()
    now = datetime.datetime.today().now()
    #getCity

    font20 = pygame.font.SysFont("Franklin Gothic Medium Cond", 20)
    font80 = pygame.font.SysFont("Franklin Gothic Heavy", 80)
    font50 = pygame.font.SysFont("Franklin Gothic Heavy", 50)
    font60 = pygame.font.SysFont("Franklin Gothic Heavy", 60)
    font24 = pygame.font.SysFont("Franklin Gothic Medium Cond", 24)
    font16 = pygame.font.SysFont("Franklin Gothic Medium Cond", 16)
    font36 = pygame.font.SysFont("Franklin Gothic Heavy", 36)
    font32 = pygame.font.SysFont("Franklin Gothic Heavy", 32)

    threading.Timer(1, getCity).start()
    label = "Human"

    getMap()
    threading.Timer(1, getMap).start()

    back = pygame.image.load("back.png")
    top = pygame.image.load("top.png")

    temp = pygame.image.load("temperature.png")
    winds = pygame.image.load("windspeed.png")
    humid = pygame.image.load("humid.png")
    #speak_thr.start()
    while loop:
        cnt = 0
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                close()

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_q:
                    close()

        #_, frame = videoFeed.read()
        stime = time.time()
        label = "--"
        confidence = 0.0
        boxes = 0
        a = run(frame)

        closestLabel = None
        closestDist = float('inf')

        if 1:
            for color, result in zip(colors, results):
                tl = (result['topleft']['x'], result['topleft']['y'])
                br = (result['bottomright']['x'], result['bottomright']['y'])
                label = result['label']
                #print("tl is ",tl)
                vech = ['car', 'motercycle', 'truck', 'bus']
                confidence = result['confidence']
                print(confidence)
                rec = [
                    'traffic light', 'car', 'motercycle', 'truck', 'bus',
                    'stop sign', 'turn left', 'turn right', 'go straight', ''
                ]
                #confidence*100>35 and (label in rec)
                if (a != None):
                    if (a[0] != None):
                        realHeight = 75
                        dist = (5.5 * (realHeight) * 360) / ((a[3]) * 4.5)
                        if dist < closestDist:
                            closestDist = dist
                            closestLabel = str(a[0])
                        txt2 = '{}: {:.0f}% : Dist: {:.01f}cm'.format(
                            a[0], confidence * 100, dist / 10)
                        frame = cv2.putText(frame, txt2, tuple(a[1]),
                                            cv2.FONT_HERSHEY_COMPLEX, 1,
                                            (0, 100, 200), 2)

                if (confidence * 100 > 0 and (label in rec)):
                    text = '{}: {:.0f}%'.format(label, confidence * 100)
                    frame = cv2.rectangle(frame, tl, br, color, 5)
                    frame = cv2.putText(frame, text, tl,
                                        cv2.FONT_HERSHEY_COMPLEX, 1,
                                        (0, 0, 255), 2)
                    if label in vech:
                        cnt += 1

                    realHeight = 75
                    if label == "person":
                        realHeight = 500
                    dist = (5.5 * (realHeight) * 360) / ((br[1] - tl[1]) * 4.5)
                    if dist < closestDist:
                        closestDist = dist
                        closestLabel = str(label)

                    text = '{}: {:.0f}% : Dist: {:.0f}cm'.format(
                        label, confidence * 100, dist / 10)
                    frame = cv2.putText(frame, text, tl,
                                        cv2.FONT_HERSHEY_COMPLEX_SMALL, 1,
                                        (0, 100, 200), 1)

        image = cv2.resize(frame, (vWidth, vHeight),
                           interpolation=cv2.INTER_LINEAR)

        #speak_thr.join()

        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        image = np.rot90(image)
        image = np.flip(image, 0)
        image = pygame.surfarray.make_surface(image)

        display.fill((0, 0, 0))

        #Live Feed
        drawBackground(20, 20, 900, 350)
        display.blit(image, (30, 30))

        # Confidence
        #confidence = (confidence + 1)%100

        display.blit(back, (515, 60))

        if not closestLabel or (closestLabel == "person"):
            confidence = 0

        points = [(0, 0), (0, 80), (6, 80), (6, 0)]
        coords = []
        angle = 60 + 240 * (confidence)
        for point in points:
            coords.append(
                translate(600, 145, rotate(point, radians(angle), (3, 0))))

        pygame.draw.line(display, (91, 154, 213),
                         (602.3164801755993, 149.43101789615605),
                         (669.5063982331376, 187.59807621135332), 2)
        pygame.draw.line(display, (91, 154, 213),
                         (529.217967697245, 187.40192378864668),
                         (602.3164801755993, 149.43101789615605), 2)

        pygame.draw.polygon(display, (242, 119, 36), coords)
        display.blit(top, (555, 98))

        text = font36.render(str(int(confidence * 100)), True, (255, 255, 255))
        display.blit(text, (575, 125))
        text = font20.render("%", True, (255, 255, 255))
        display.blit(text, (620, 135))

        # Prediction
        text = font24.render(str(closestLabel), True, (255, 255, 255))
        display.blit(text, (730, 90))

        text = font24.render(str("Do This Action"), True, (255, 255, 255))
        display.blit(text, (730, 140))

        if closestLabel in vehicles:
            dist = closestDist
        else:
            dist = 0

        text = font24.render(
            "Distance From Next Vehicle: " + str(dist / 10) + " cm", True,
            (255, 255, 255))
        display.blit(text, (630, 280))

        # Map
        drawBackground(20, 390, 440, 270)
        display.blit(mapCurr, (25, 395))

        # Weather
        drawBackground(480, 390, 440, 270)
        # Temp
        display.blit(temp, (513, 410))

        text = font36.render(str(int(tempt)), True, (146, 208, 80))
        display.blit(text, (533, 510))
        text = font16.render("C", True, (146, 208, 80))
        display.blit(text, (580, 515))

        # Wind
        display.blit(winds, (656, 410))
        text = font36.render(str(int(wind)), True, (255, 192, 0))
        display.blit(text, (686, 510))
        text = font16.render("m/s", True, (255, 192, 0))
        display.blit(text, (715, 515))

        # Humid
        display.blit(humid, (800, 410))
        text = font36.render(str(int(hum)), True, (255, 205, 255))
        display.blit(text, (830, 510))
        text = font16.render("%", True, (255, 205, 255))
        display.blit(text, (880, 510))

        text = font50.render(str(status.title()), True, (157, 190, 230))
        pos = text.get_rect()
        pos.center = (480 + 220, 390 + 220)
        display.blit(text, pos)

        pygame.display.update()
        if closestLabel:
            if (closestLabel in vehicles and closestDist < 17 * 10):
                if (lang == 0):
                    playsound("./sounds/vehicle_ahead_hi.mp3")
                elif (lang == 1):
                    playsound("./sounds/vehicle_ahead_en.mp3")
                elif (lang == 2):
                    playsound("./sounds/vehicle_ahead_mh.mp3")
                elif (lang == 3):
                    playsound("./sounds/vehicle_ahead_bn.mp3")
            else:
                if (closestLabel == "stop sign"):
                    if (lang == 0):
                        playsound("./sounds/stop_hi.mp3")
                    elif (lang == 1):
                        playsound("./sounds/stop_en.mp3")
                    elif (lang == 2):
                        playsound("./sounds/stop_mh.mp3")
                    elif (lang == 3):
                        playsound("./sounds/stop_bn.mp3")
                elif (closestLabel == "turn left"):
                    if (lang == 0):
                        playsound("./sounds/tl_hi.mp3")
                    elif (lang == 1):
                        playsound("./sounds/tl_en.mp3")
                    elif (lang == 2):
                        playsound("./sounds/tl_mh.mp3")
                    elif (lang == 3):
                        playsound("./sounds/tl_bn.mp3")
                elif (closestLabel == "turn right"):
                    if (lang == 0):
                        playsound("./sounds/tr_hi.mp3")
                    elif (lang == 1):
                        playsound("./sounds/tr_en.mp3")
                    elif (lang == 2):
                        playsound("./sounds/tr_mh.mp3")
                    elif (lang == 3):
                        playsound("./sounds/tr_bn.mp3")

        clock.tick(60)
Example #2
0
            category_index,
            use_normalized_coordinates=True,
            line_thickness=8)


#output_frame = OutputFrame()
webcam_thread = camera("camera thread")
predictor_thread = predictclass("predictclass thread")
webcam_thread.start()
time.sleep(.1)
predictor_thread.start()

cnt = 0
while True:
    stime = time.time()
    a = run(frame)
    veh = 0
    #print(a)
    #ret, frame = cap.read()
    #results = tfnet.return_predict(frame)
    #results=output_frame.boxes
    #print("asdsasz",results)
    if 1:
        for color, result in zip(colors, results):
            tl = (result['topleft']['x'], result['topleft']['y'])
            br = (result['bottomright']['x'], result['bottomright']['y'])
            label = result['label']
            #print("tl is ",tl)
            vech = ['car', 'motercycle', 'truck', 'bus']
            confidence = result['confidence']
            rec = [