示例#1
0
def enrichEmbed(img1,img2,img3):
    img1_location = api.human_locations(img1)
    img2_location = api.human_locations(img2)
    img3_location = api.human_locations(img3)

    img_1_human = api.crop_human(img1, img1_location)
    img_2_human = api.crop_human(img2, img2_location)
    img_3_human = api.crop_human(img3, img3_location)

    human_1_1 = img_1_human[0]
    # plt.imshow(human_1_1)

    human_1_2 = img_2_human[0]
    # plt.imshow(human_1_2)

    # human 1 photo 2
    human_1_3 = img_3_human[0]
    # plt.imshow(human_1_3)


    human_1_1_vector = api.human_vector(human_1_1)
    human_1_2_vector = api.human_vector(human_1_2)
    human_1_3_vector = api.human_vector(human_1_3)

    return (human_1_1_vector +human_1_2_vector +human_1_3_vector )/3
示例#2
0
def compare(path1, path2):
    img1 = cv2.imread(path1)[:, :, ::-1]
    img2 = cv2.imread(path2)[:, :, ::-1]
    human_1_vector = api.human_vector(img1)
    human_2_vector = api.human_vector(img2)
    #print(api.human_distance(human_1_vector, human_2_vector))
    if (api.human_distance(human_1_vector, human_2_vector) < 20):
        return True
    else:
        return False
示例#3
0
    def find(self, img, past_ppl, qimg_vec):
        maxp = 0
        fd = 1
        current_img_vector = api.human_vector(img)
        folders = os.listdir(past_ppl)
        ans = False
        dist = api.human_distance(current_img_vector, qimg_vec)
        if (dist < 15):
            ans = True
        else:
            ans = False
        for folder in folders:
            same = 0
            diff = 0

            files = os.listdir(past_ppl + '/' + folder)
            file = -1
            for f in files:
                file += 1
                #print(f)
                #print(folder)
                #print(Videoreid.past_ppl_vector)
                #print(int(folder))
                #print(file)
                file_vector = Videoreid.past_ppl_vector[int(folder) - 1][file]
                distance = api.human_distance(current_img_vector, file_vector)
                if (distance < 15):
                    same = +1
                else:
                    diff = +1
            p = 100 * float(same) / float(same + diff)
            if (maxp < p):
                maxp = p
                fd = folder

        if (maxp > 90):
            files = os.listdir(past_ppl + '/' + fd)
            person_no = len(files) + 1
            cv2.imwrite(past_ppl + '/' + fd + '/' + str(person_no) + '.jpg',
                        img)
            print('old person detected at ' + str(fd) + ' ' +
                  str(datetime.now().time()))
            current_folder = Videoreid.past_ppl_vector[int(fd) - 1]
            current_folder.append(current_img_vector)
            Videoreid.past_ppl_vector[int(fd) - 1] = current_folder
            return [ans, int(fd)]

        else:
            l = len(folders) + 1
            print('new person detected at ' + str(l) + ' ' +
                  str(datetime.now().time()))
            os.makedirs(past_ppl + '/' + str(l))
            cv2.imwrite(past_ppl + '/' + str(l) + '/1.jpg', img)
            folder_vector = []
            folder_vector.append(current_img_vector)
            Videoreid.past_ppl_vector.append(folder_vector)
            #print(Videoreid.past_ppl_vector)
            return [ans, l]
示例#4
0
 def video_reid(self, path, path_qimg):
     arr = []
     present = False
     qimg = cv2.imread(path_qimg)
     qimg_vec = api.human_vector(qimg)
     cap = cv2.VideoCapture(path)
     frame_height = int(cap.get(4))
     frame_width = int(cap.get(3))
     fps = int(cap.get(5))
     fourcc = cv2.VideoWriter_fourcc(*'VP80')
     base = os.path.basename(path)
     filename = os.path.splitext(base)[0]
     out = cv2.VideoWriter('../Output_Videos/' + filename + '.webm', fourcc,
                           fps, (frame_width, frame_height))
     videoOn = True
     past_ppl = '../Identity_Gallery'
     while (videoOn):
         ret, frame = cap.read()
         if (ret == False):
             break
         arr = []
         img_location = api.human_locations(frame)
         img_human = api.crop_human(frame, img_location)
         for j in range(len(img_human)):
             arr.append(self.find(img_human[j], past_ppl, qimg_vec))
         f = self.draw_boxes(frame, img_location, arr)
         frame = f[0]
         if (f[1] == True):
             present = True
         cv2.imshow('Video', frame)
         if cv2.waitKey(1) & 0xFF == ord('q'):
             break
         out.write(frame)
     cap.release()
     out.release()
     cv2.destroyAllWindows()
     print('end')
     return ['Project/Output_Videos/' + filename + '.webm', present]
    def find1(self, img, past_ppl, ans):
        maxp = 0
        fd = 1
        current_img_vector = api.human_vector(img)
        folders = os.listdir(past_ppl)

        for folder in folders:
            same = 0
            diff = 0

            files = os.listdir(past_ppl + '/' + folder)
            file = -1
            for f in files:
                file += 1
                #print(f)
                #print(folder)
                #print(Videoreid.past_ppl_vector)
                #print(int(folder))
                #print(file)
                file_vector = Videoreid.past_ppl_vector[int(folder) - 1][file]
                distance = api.human_distance(current_img_vector, file_vector)
                if (distance < 15):
                    same = +1
                else:
                    diff = +1
            p = 100 * float(same) / float(same + diff)
            if (maxp < p):
                maxp = p
                fd = folder

        if (maxp > 90):
            ans.add(int(fd))
            print('Person ' + str(fd) + ' detected in second video' + ' ' +
                  str(datetime.now().time()))
            return [int(fd), True]
        else:
            l = len(folders) + 1
            return [l, False]
示例#6
0
# human 1 photo 2
human_1_2 = img_2_human[0]
plt.imshow(human_1_2)

# In[5]:

# human 2 photo 1
human_2_1 = img_3_human[0]
plt.imshow(human_2_1)

# # Make vector of human image

# In[6]:

t1 = timeit.default_timer()
human_1_1_vector = api.human_vector(human_1_1)
human_1_2_vector = api.human_vector(human_1_2)
human_2_1_vector = api.human_vector(human_2_1)
t2 = timeit.default_timer()
print('Time elapsed: {} sec'.format(round(t2 - t1, 3)))

# # Comparing vector

# In[7]:

api.human_distance(human_1_1_vector, human_1_2_vector)

# In[8]:

api.human_distance(human_1_2_vector, human_2_1_vector)