示例#1
0
    def push_frame(self):
        print('push frame')
        global ABNORMAL_DETECT_STATUS_DELTA

        # # 防止多线程时 command 未被设置
        # while True:
        #     if len(self.command) > 0:
        #
        #         print('set pipe info')
        #
        #         # 管道配置
        #         p = sp.Popen(self.command, stdin=sp.PIPE)
        #         break

        K.clear_session()
        config = tf.ConfigProto()
        config.gpu_options.allocator_type = 'BFC'  # A "Best-fit with coalescing" algorithm, simplified from a version of dlmalloc.
        config.gpu_options.per_process_gpu_memory_fraction = 1
        config.gpu_options.allow_growth = True
        set_session(tf.Session(config=config))
        yolo = YOLO()

        gl.clear_detect_items()
        print('clear after:', gl.DETECT_TYPE)

        # for camera_event_type_item in self.detect_items:
        #     gl.set_detect_items(camera_event_type_item)
        #
        # for camera_event_type_id_item in self.detect_items_index:
        #     gl.set_note_event_id(camera_event_type_id_item)

        gl.set_detect_items('安全帽检测')
        gl.set_detect_items('安全带检测')
        print(gl.DETECT_TYPE)
        # print(gl.NOTE_EVENT_ID)

        # deep_sort
        model_filename = '/Users/apple/Desktop/Git/Track/deep_sort_yolov3_lastest/model_data/mars-small128.pb'
        # model_filename = 'model_data/mars-small128.pb'

        encoder = gdet.create_box_encoder(model_filename, batch_size=1)

        # 非极大值抑制
        metric = nn_matching.NearestNeighborDistanceMetric("cosine", 0.3, None)
        tracker = Tracker(metric)

        cnt = 0
        befor_worker_status={}

        while True:
            try:
                if self.frame_queue.empty() != True:
                    #print('-----------------queue size: ', self.frame_queue.qsize())
                    if self.frame_queue.qsize() > 5:
                        frame = self.frame_queue.get()
                        # process fr
                        t3 = time.time()
                        #frame = cv2.resize(frame, dsize=(VIDEO_HEIGHT,VIDEO_WEIGHT), interpolation=cv2.INTER_CUBIC)
                        print('shape:',frame.shape)
                        #frame = np.rot90(frame, -2)
                        print('resize cost:',time.time()-t3)
                        if frame.shape[0] < frame.shape[1]:
                          frame = np.rot90(frame, -1)

                        image = Image.fromarray(frame[..., ::-1])  # bgr to rgb
                        t4=time.time()
                        print('image convert cost:',t4-t3)

                        # 人框,所有目标框
                        boxs, other_boxs = yolo.detect_image(image)
                        t5=time.time()

                        print(cnt,' box:',other_boxs,boxs,'detect cost:',t5-t4)
                        frame1=copy.deepcopy(frame)
                        features = encoder(frame, boxs)
                        detections = [Detection(bbox, 1.0, feature) for bbox, feature in zip(boxs, features)]

                        # Run non-maxima suppression.
                        boxes = np.array([d.tlwh for d in detections])
                        scores = np.array([d.confidence for d in detections])
                        indices = preprocessing.non_max_suppression(boxes, 1.0, scores)
                        detections = [detections[i] for i in indices]

                        tracker.predict()
                        tracker.update(detections)
                        t6=time.time()
                        print('track decode cost:',t6-t5)

                        update_flag = False
                        current_worker_status = {}
                        for track in tracker.tracks:
                            if not track.is_confirmed() or track.time_since_update > 1:
                                continue

                            if track.corresponding_detect == -1:
                                continue
                            b = detections[track.corresponding_detect].tlwh
                            bbox = [int(b[0]), int(b[1]), int(b[0] + b[2]), int(b[1] + b[3])]
                            bbox[0] = min(max(0,bbox[0]),frame.shape[1])
                            bbox[1] = min(max(0,bbox[1]),frame.shape[0])
                            bbox[2] = min(max(0,bbox[2]),frame.shape[1])
                            bbox[3] = min(max(0,bbox[3]),frame.shape[0])
                            # bbox = track.to_tlbr()
                            frame = frame.astype(np.uint8)
                            frame = frame.copy()
                            cv2.putText(frame, str(track.track_id),(int((bbox[0]+bbox[2])/2), int(bbox[1])),cv2.FONT_HERSHEY_SIMPLEX,1, (0,255,0),2)

                            # 安全带/安全帽匹配
                            t7=time.time()
                            single_person_box = [int(bbox[0]), int(bbox[1]), int(bbox[2]), int(bbox[3]), track.track_id]
                            match_ok,current_wear_list = person_status_match(single_person_box, other_boxs, current_worker_status)

                            add_flag = False
                            note_violation_behavior(track.track_id,current_wear_list)
                            if track.track_id in ABNORMAL_DETECT_STATUS_DELTA.keys() and ABNORMAL_DETECT_STATUS_DELTA[track.track_id]['count']==EVNENT_NOTE_COUNT_THRESH:
                                add_flag, current_wear_list, violation_item, event_id_list = status_change_note(befor_worker_status, current_worker_status, track.track_id)
                                update_flag = True
                            print(ABNORMAL_DETECT_STATUS_DELTA)

                            if float(int(frame.shape[0]) - bbox[3]) / float(frame.shape[0]) >= CLIMB_FLAG:
                                # 未带安全帽
                                t10 = time.time()
                                if add_flag or 0 in current_wear_list:
                                    frame1 = frame1.copy()
                                    cv2.rectangle(frame1, (int(bbox[0]), int(bbox[1])), (int(bbox[2]), int(bbox[3])), color_red,2)

                                    cv2.putText(frame1, str(track.track_id),(int((bbox[0] + bbox[2]) / 2), int(bbox[1])), cv2.FONT_HERSHEY_SIMPLEX, 1,color_green,2)
                                    wear_list = current_worker_status[track.track_id]

                                    for i in range(len(wear_list)):
                                        wear_box = other_boxs[wear_list[i][1]]
                                        cv2.rectangle(frame1, (int(wear_box[0]), int(wear_box[1])),(int(wear_box[2]), int(wear_box[3])), color_white, 2)

                                    if add_flag:
                                        post_data = {
                                            # "employId": str(track.track_id),
                                            "cameraId": str(0),
                                            "eventTypeId": str(0),
                                            "photo": "pic.jpg",
                                            "photoHeight": str(VIDEO_WEIGHT),
                                            "photoWeight": str(VIDEO_HEIGHT)
                                        }
                                        self.post_queue.put((frame, post_data))

                                        print('##添加事件   ',str(track.track_id)+'未佩戴:',violation_item)

                                else:
                                    frame1 = frame1.copy()
                                    cv2.rectangle(frame1, (int(bbox[0]), int(bbox[1])), (int(bbox[2]), int(bbox[3])), color_blue,2)
                                    cv2.putText(frame1, str(track.track_id),(int((bbox[0] + bbox[2]) / 2), int(bbox[1])), cv2.FONT_HERSHEY_SIMPLEX, 1,color_green,2)

                                    wear_list = current_worker_status[track.track_id]
                                    for i in range(len(wear_list)):
                                        wear_box = other_boxs[wear_list[i][1]]
                                        cv2.rectangle(frame1, (int(wear_box[0]), int(wear_box[1])),(int(wear_box[2]), int(wear_box[3])), color_white, 2)

                                    t12 = time.time()
                                    print(track.track_id,' not add cost:',t12-t10)
                                    continue

                            else:
                                if DEBUG:
                                    frame1=frame1.copy()
                                    # color = colors[int(track.track_id) % len(colors)]
                                    # color = [i * 255 for i in color]

                                    cv2.rectangle(frame1, (int(bbox[0]), int(bbox[1])), (int(bbox[2]), int(bbox[3])), color_blue, 2)

                                    cv2.putText(frame1, str(track.track_id),
                                                (int((bbox[0] + bbox[2]) / 2), int(bbox[1])), cv2.FONT_HERSHEY_SIMPLEX, 1, color_green,
                                                2)

                                    wear_list=current_worker_status[track.track_id]
                                    for i in range(len(wear_list)):
                                        wear_box=other_boxs[wear_list[i][1]]
                                        cv2.rectangle(frame1, (int(wear_box[0]), int(wear_box[1])), (int(wear_box[2]), int(wear_box[3])), color_blue, 2)

                        if update_flag:
                            befor_worker_status = current_worker_status

                        t9=time.time()
                        print('track cost:',t9-t6)

                        frame1 = frame1.copy()
                        cv2.line(frame1,(0,int((1-CLIMB_FLAG)*frame1.shape[0])),(frame1.shape[1],int((1-CLIMB_FLAG)*frame1.shape[0])),(0,255,0),3)
                        image_tmp = Image.fromarray(frame1)
                        image_tmp.show(str(cnt))
                        print('fps:',1.0/(t9-t3))
                        print('')
                        print('')
                        print('')
                        # write to pipe
                        # p.stdin.write(frame1.tostring())
            except:
                pass
示例#2
0
    from yolo import YOLO
    yolo = YOLO()
    deepsort_preprocess = DeepSortPreprocess()
    deepsort = DeepSort()

    video_capture = cv2.VideoCapture('../data/PETS09-S2L1.mp4')
    frame_i = -1
    while True:
        frame_i += 1
        ret, frame = video_capture.read()  # frame shape 640*480*3
        if ret is not True:
            break

        # 检测框
        image_for_yolo = Image.fromarray(frame[..., ::-1])  # bgr to rgb
        boxs = yolo.detect_image(image_for_yolo)

        features = deepsort_preprocess.get_features(frame, boxs)
        # 追踪
        track_new_id_list, track_delete_id_list, not_confirmed_detected_track, detected_track = deepsort.update(
            boxs, features)

        for track_data in not_confirmed_detected_track:
            track_id = track_data['trackID']
            track_bbox = track_data['body_box']
            cv2.rectangle(frame, (int(track_bbox[0]), int(track_bbox[1])),
                          (int(track_bbox[2]), int(track_bbox[3])),
                          (255, 0, 255), 2)
            cv2.putText(frame, str(track_id),
                        (int(track_bbox[0]), int(track_bbox[1])), 0,
                        5e-3 * 200, (0, 255, 0), 2)
示例#3
0
def main(model, lang):
    parser = argparse.ArgumentParser(description='model_data/trained_weights_final.h5')
    # modelが保存されているpathを引数で指定してください
    # parser.add_argument('--model_path', default=None, help="path to saved_mode")
    parser.add_argument('--model_path', default='/home/pi/dive_groupwork/yolo_test/model_data/trained_weights_final.h5', help="path to saved_mode")

    # デバッグの処理
    parser.add_argument('--time_debug', default=False, help="debug_mode True or False")
    
    # 引数を読み込み
    args = parser.parse_args()

    # モデル+重みを読込み
    
    # self_model = load_model(args.model_path, compile=False)

    #商品価格等の情報をbottle_masterから読み込み
    # name_price_dict = bottle_master.bottle_master_dict()
    # _, label_dict = bottle_master.bottle_label_dirpath()
    # bottle_label = {}
    # for key, value in label_dict.items():
    #     bottle_label[value] = key
    bottle_master_df = bottle_master.bottle_master_df(model="YOLO")
    
    """
    # 言語モードを選択
    while True:
        print("Please select a language!!")
        print()
        lang = input('Kinyarwanda :「k」,English :「e」,French :「f」,Japanese :「j」')
        print()
        if lang not in ['k', 'e', 'f', 'j']:
            print('Please input correctly')
            print()
        else:
            break
    """

    # yolo.pyのYOLOクラスをインスタンス化
    yolo = YOLO()
    # yoloの初回起動
    init_yolo(yolo)

    while True:
        # 空のdfを作成
        total_df = pd.DataFrame(columns=['name', 'price'])
        while True:
            # 「商品を置いてenterを押してください」
            while True:
                scene = "scan_start"
                input(translate_language(lang, scene))
                print()

                # 時間を図る self.time_debugに応じて対応
                if args.time_debug is True:
                    time_start = perf_counter()

                # 写真撮影をしてnumpy_arrayで受け取る
                image_array = shutter2image.shutter_array()

                # numpy_arrayをPILへ変換してモデルの入力用に加工
                img = Image.fromarray(image_array)

                # 読み込んだmodelでpridictを実行

                # predicted_classes = yolo_video.main(img)
                # start = timer()
                # _, _, predicted_classes = yolo.detect_image(img)
            
                predict_index_list, _, _ = yolo.detect_image(img)
                if predict_index_list.any():
                    break
                else:
                    scene = 'not_registered'
                    print(translate_language(lang, scene))
                    print()
            # end = timer()
            # print(end - start)
            

            # 時間計測
            if args.time_debug is True:
                time_end = perf_counter()
                print('デバッグ用、本番環境ではいらない、予測されたラベルインデックスのリスト {}'.format(predict_index_list))
                scene = "time"
                print(translate_language(lang, scene).format(time_end-time_start))



            # 予測されたindexのリストからdfを作成
            predict_df = bottle_master_df.iloc[predict_index_list, [2, 3]].reset_index(drop=True)

            # 小計をdiplay
            scene = "read_message"
            # 10/18 translate.pyの上記sceneの文言変更
            # print(translate_language(self.lang, scene).format('test_bottle', random_price))
            print(translate_language(lang, scene))
            print()
            print(predict_df)
            print()

            # print('商品 : {} 値段 : {} が読み取られました'.format(name, name_price_dict[name]))

            while True:
                scene = "correct?"
                key = input(translate_language(lang, scene))
                print()

                if key != 'y' and key != 'n':
                     # 正しく入力されていません
                    scene = "input_error"
                    print(translate_language(lang, scene))
                    print()
                else:
                    break
                
            if key == 'y':
                total_df = pd.concat([total_df, predict_df], axis=0).reset_index(drop=True)
                print(total_df)
                print()
                # 小計
                scene = "subtotal"
                print(translate_language(lang, scene).format(total_df["price"].sum()))
                print()

                while True:
                    # 続けて商品をスキャンする場合は「y」、会計する場合は「f」、\n キャンセルする商品がある場合は「x」を押して下さい。
                    scene = "continue?"
                    key = input(translate_language(lang, scene))
                    print()
                    if key != 'y' and key != 'f' and key != 'x':
                        # 正しく入力されていません
                        scene = "input_error"
                        print(translate_language(lang, scene))
                        print()
                    # 商品をdeleteする処理
                    elif key == 'x':
                        while True:
                            print(total_df)
                            print()
                            # scene設定, translate.pyへ追加
                            scene = 'delete'
                            key = input(translate_language(lang, scene).format(len(total_df)-1))
                            print()
                            key_list = [str(i) for i in range(len(total_df))] + ['n']
                            if key not in key_list:
                                # 正しく入力されていません
                                scene = "input_error"
                                print(translate_language(lang, scene))
                                print()
                            elif key == 'n':
                                break
                            else:
                                scene = 'delete_complete'
                                print(translate_language(lang, scene))
                                print()
                                print(total_df[int(key):int(key)+1])
                                print()
                                # total_dfから消去
                                total_df = total_df.drop(index=int(key))
                                # indexをreset
                                total_df = total_df.reset_index(drop=True)
                    else:
                        break

                if key == 'f':
                    # 合計
                    print(total_df)
                    print()
                    scene = "total"
                    print(translate_language(lang, scene).format(total_df['price'].sum()))
                    print()

                    # ありがとうございました
                    scene = "thanks"
                    print(translate_language(lang, scene))
                    move = input("next step to enter :")
                    if move == "quit":
                        test = MAIN(model, lang)
                        test.mode_select()
                    else:
                        break
                elif key == 'y':
                    # 次の商品を指定の位置に置いてください。
                    scene = "next"
                    print(translate_language(lang, scene))
                    print()
yolo = YOLO()
# 调用摄像头
capture=cv2.VideoCapture(0) # capture=cv2.VideoCapture("1.mp4")

fps = 0.0
while(True):
    t1 = time.time()
    # 读取某一帧
    ref,frame=capture.read()
    # 格式转变,BGRtoRGB
    frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
    # 转变成Image
    frame = Image.fromarray(np.uint8(frame))

    # 进行检测
    frame = np.array(yolo.detect_image(frame))

    # RGBtoBGR满足opencv显示格式
    frame = cv2.cvtColor(frame,cv2.COLOR_RGB2BGR)
    
    fps  = ( fps + (1./(time.time()-t1)) ) / 2
    print("fps= %.2f"%(fps))
    frame = cv2.putText(frame, "fps= %.2f"%(fps), (0, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
    
    cv2.imshow("video",frame)
    c= cv2.waitKey(30) & 0xff 
    if c==27:
        capture.release()
        break

yolo.close_session()
示例#5
0
ymax_list = []


def get_class(classes_path):
    with open(classes_path) as f:
        class_names = f.readlines()
    class_names = [c.strip() for c in class_names]
    return class_names


for i in range(len(text_list)):
    start = time.time()
    print('开始检测第'+str(i+1)+'张图片。')
    image_path = 'VOCdevkit/VOC2007/JPEGImages/' + text_list[i] + '.jpg'
    image = Image.open(image_path)
    image, label_record, score_record, top_record, left_record, bottom_record, right_record = yolo.detect_image(
        image)
    image.save('results_imgs/{}.png'.format(text_list[i]))
    all_classes = get_class('model_data/my_classes.txt')
    xmin_list.extend(left_record)
    ymin_list.extend(top_record)
    xmax_list.extend(right_record)
    ymax_list.extend(bottom_record)
    jpg = [text_list[i] + '.jpg'] * len(label_record)
    jpg_list.extend(jpg)
    print('第'+str(i+1)+'张图片检测完毕,检测出了'+str(len(label_record))+'个物体。')
    end = time.time()
    print('检测总共花费的时间为: {0:.2f}s'.format(end - start))


result = pd.DataFrame()
name_list = []
    def Counting_People(path):
        yolo = YOLO()
        global total

        global track_list
        # Definition of the parameters
        max_cosine_distance = 0.3
        nn_budget = None
        nms_max_overlap = 1.0

        # deep_sort
        model_filename = 'model_data/mars-small128.pb'
        encoder = gdet.create_box_encoder(model_filename, batch_size=1)

        metric = nn_matching.NearestNeighborDistanceMetric(
            "cosine", max_cosine_distance, nn_budget)
        tracker = Tracker(metric)

        writeVideo_flag = True

        video_capture = cv2.VideoCapture(path)

        if writeVideo_flag:
            # Define the codec and create VideoWriter object
            w = int(video_capture.get(3))
            h = int(video_capture.get(4))
            fourcc = cv2.VideoWriter_fourcc(*'MJPG')
            out = cv2.VideoWriter('output.avi', fourcc, 15, (w, h))
            list_file = open('detection.txt', 'w')
            frame_index = -1

        fps = 0.0
        while True:
            ret, frame = video_capture.read()  # frame shape 640*480*3
            if ret != True:
                break
            t1 = time.time()

            image = Image.fromarray(frame)
            boxs = yolo.detect_image(image)
            # print("box_num",len(boxs))
            features = encoder(frame, boxs)

            # score to 1.0 here).
            detections = [
                Detection(bbox, 1.0, feature)
                for bbox, feature in zip(boxs, features)
            ]

            # Run non-maxima suppression.
            boxes = np.array([d.tlwh for d in detections])
            scores = np.array([d.confidence for d in detections])
            indices = preprocessing.non_max_suppression(
                boxes, nms_max_overlap, scores)
            detections = [detections[i] for i in indices]

            # Call the tracker
            tracker.predict()
            tracker.update(detections)

            for track in tracker.tracks:
                if track.is_confirmed() and track.time_since_update > 1:
                    continue
                    # count=0
                bbox = track.to_tlbr()
                cv2.rectangle(frame, (int(bbox[0]), int(bbox[1])),
                              (int(bbox[2]), int(bbox[3])), (255, 255, 255), 2)
                cv2.putText(frame, str(track.track_id),
                            (int(bbox[0]), int(bbox[1])), 0, 5e-3 * 200,
                            (0, 255, 0), 2)
                # count=count+1
                # track.track_id=1
                list1 = track.track_id
                # print(track_list)

                track_list.append(track.track_id)
                # for t in track_list:
                # print("Debugging",t)
                # else:

                #     for var in list1:
                #         print("Debugging for TrackId value",var)
                #     my_list=[]
                # print(track.track_id)

            for det in detections:
                bbox = det.to_tlbr()
                cv2.rectangle(frame, (int(bbox[0]), int(bbox[1])),
                              (int(bbox[2]), int(bbox[3])), (255, 0, 0), 2)

            cv2.imshow('', frame)

            if writeVideo_flag:
                # save a frame
                out.write(frame)
                frame_index = frame_index + 1
                # count=0
                # count=count+1
                # print(count)
                list_file.write(str(frame_index) + ' ')

                if len(boxs) != 0:
                    for i in range(0, len(boxs)):
                        list_file.write(
                            str(boxs[i][0]) + ' ' + str(boxs[i][1]) + ' ' +
                            str(boxs[i][2]) + ' ' + str(boxs[i][3]) + ' ')
                list_file.write('\n')

            fps = (fps + (1. / (time.time() - t1))) / 2
            # print (my_list)
            print("fps= %f" % (fps))

            # Press Q to stop!
            if cv2.waitKey(1) & 0xFF == ord('q'):
                brea

        video_capture.release()
        if writeVideo_flag:
            out.release()
            list_file.close()
        cv2.destroyAllWindows()
        # print(frame_index)
        # print(list_file)
        # print(track_list)
        total = (len(set(track_list)))
        print("Total Number of People In Whole Video Are :", total)
示例#7
0
import cv2
import numpy as np
from PIL import Image
from yolo import YOLO
import tensorflow as tf
tf.compat.v1.disable_eager_execution()

model = YOLO(model_path="model_data/yolov3.h5",
             anchors_path="model_data/yolo_anchors.txt",
             classes_path="model_data/coco_classes.txt")

camera = cv2.VideoCapture(0)
while camera.isOpened():
    success, frame = camera.read()
    if not success:
        break

    img = cv2.resize(frame, (416, 416))
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    img = Image.fromarray(img)
    img = model.detect_image(img)
    img = np.asarray(img)

    cv2.imshow("frame", frame)
    cv2.imshow("image", img)
    if cv2.waitKey(1) in [ord('q'), 27]:
        break
camera.release()
cv2.destroyAllWindows()
示例#8
0
def main():

    yolo = YOLO()
    max_cosine_distance = 0.3
    nn_budget = None
    nms_max_overlap = 1.0
    model_filename = 'model_data/mars-small128.pb'
    encoder = gdet.create_box_encoder(model_filename, batch_size=1)
    metric = nn_matching.NearestNeighborDistanceMetric("cosine",
                                                       max_cosine_distance,
                                                       nn_budget)
    tracker = Tracker(metric)
    parser = argparse.ArgumentParser(
        description='Training codes for Openpose using Tensorflow')
    parser.add_argument('--checkpoint_path',
                        type=str,
                        default='checkpoints/train/2018-12-13-16-56-49/')
    parser.add_argument('--backbone_net_ckpt_path',
                        type=str,
                        default='checkpoints/vgg/vgg_19.ckpt')
    parser.add_argument('--image', type=str, default=None)
    # parser.add_argument('--run_model', type=str, default='img')
    parser.add_argument('--video', type=str, default=None)
    parser.add_argument('--train_vgg', type=bool, default=True)
    parser.add_argument('--use_bn', type=bool, default=False)
    parser.add_argument('--save_video', type=str, default='result/our.mp4')
    args = parser.parse_args()
    checkpoint_path = args.checkpoint_path
    logger.info('checkpoint_path: ' + checkpoint_path)

    with tf.name_scope('inputs'):
        raw_img = tf.placeholder(tf.float32, shape=[None, None, None, 3])
        img_size = tf.placeholder(dtype=tf.int32,
                                  shape=(2, ),
                                  name='original_image_size')

    img_normalized = raw_img / 255 - 0.5

    # define vgg19
    with slim.arg_scope(vgg.vgg_arg_scope()):
        vgg_outputs, end_points = vgg.vgg_19(img_normalized)

    # get net graph
    logger.info('initializing model...')
    net = PafNet(inputs_x=vgg_outputs, use_bn=args.use_bn)
    hm_pre, cpm_pre, added_layers_out = net.gen_net()
    hm_up = tf.image.resize_area(hm_pre[5], img_size)
    cpm_up = tf.image.resize_area(cpm_pre[5], img_size)
    # hm_up = hm_pre[5]
    # cpm_up = cpm_pre[5]
    smoother = Smoother({'data': hm_up}, 25, 3.0)
    gaussian_heatMat = smoother.get_output()

    max_pooled_in_tensor = tf.nn.pool(gaussian_heatMat,
                                      window_shape=(3, 3),
                                      pooling_type='MAX',
                                      padding='SAME')
    tensor_peaks = tf.where(tf.equal(gaussian_heatMat, max_pooled_in_tensor),
                            gaussian_heatMat, tf.zeros_like(gaussian_heatMat))

    logger.info('initialize saver...')
    # trainable_var_list = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, scope='openpose_layers')
    # trainable_var_list = []
    trainable_var_list = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES,
                                           scope='openpose_layers')
    if args.train_vgg:
        trainable_var_list = trainable_var_list + tf.get_collection(
            tf.GraphKeys.TRAINABLE_VARIABLES, scope='vgg_19')

    restorer = tf.train.Saver(tf.get_collection(
        tf.GraphKeys.TRAINABLE_VARIABLES, scope='vgg_19'),
                              name='vgg_restorer')
    saver = tf.train.Saver(trainable_var_list)

    logger.info('initialize session...')
    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    with tf.Session(config=config) as sess:
        sess.run(tf.group(tf.global_variables_initializer()))
        logger.info('restoring vgg weights...')
        restorer.restore(sess, args.backbone_net_ckpt_path)
        logger.info('restoring from checkpoint...')
        #saver.restore(sess, tf.train.latest_checkpoint(checkpoint_dir=checkpoint_path))
        saver.restore(sess, args.checkpoint_path + 'model-59000.ckpt')
        logger.info('initialization done')
        writeVideo_flag = True
        if args.image is None:
            if args.video is not None:
                cap = cv2.VideoCapture(args.video)
                w = int(cap.get(3))
                h = int(cap.get(4))

            else:
                cap = cv2.VideoCapture("images/video.mp4")
                #cap = cv2.VideoCapture("rtsp://*****:*****@192.168.43.51:554//Streaming/Channels/1")
                #cap = cv2.VideoCapture("http://*****:*****@192.168.1.111:8081")
                #cap = cv2.VideoCapture("rtsp://*****:*****@192.168.1.106:554//Streaming/Channels/1")
            _, image = cap.read()
            #print(_,image)
            if image is None:
                logger.error("Can't read video")
                sys.exit(-1)
            fps = cap.get(cv2.CAP_PROP_FPS)
            ori_w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
            ori_h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
            #print(fps,ori_w,ori_h)
            if args.save_video is not None:
                fourcc = cv2.VideoWriter_fourcc(*'MP4V')
                video_saver = cv2.VideoWriter('result/our.mp4', fourcc, fps,
                                              (ori_w, ori_h))
                logger.info('record vide to %s' % args.save_video)
            logger.info('fps@%f' % fps)
            size = [int(654 * (ori_h / ori_w)), 654]
            h = int(654 * (ori_h / ori_w))
            time_n = time.time()
            #print(time_n)

            max_boxs = 0
            person_track = {}
            yolo2 = YOLO2()

            while True:
                face = []
                cur1 = conn.cursor()  # 获取一个游标
                sql = "select * from worker"
                cur1.execute(sql)
                data = cur1.fetchall()
                for d in data:
                    # 注意int类型需要使用str函数转义
                    name = str(d[1]) + '_' + d[2]

                    face.append(name)
                cur1.close()  # 关闭游标

                _, image_fist = cap.read()
                #穿戴安全措施情况检测

                img = Image.fromarray(
                    cv2.cvtColor(image_fist, cv2.COLOR_BGR2RGB))
                image, wear = yolo2.detect_image(img)
                image = np.array(image)
                image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)

                # # 获取警戒线
                cv2.line(image, (837, 393), (930, 300), (0, 255, 255), 3)
                transboundaryline = t.line_detect_possible_demo(image)

                #openpose二维姿态检测
                img = np.array(cv2.resize(image, (654, h)))
                # cv2.imshow('raw', img)
                img_corner = np.array(
                    cv2.resize(image, (360, int(360 * (ori_h / ori_w)))))
                img = img[np.newaxis, :]
                peaks, heatmap, vectormap = sess.run(
                    [tensor_peaks, hm_up, cpm_up],
                    feed_dict={
                        raw_img: img,
                        img_size: size
                    })
                bodys = PoseEstimator.estimate_paf(peaks[0], heatmap[0],
                                                   vectormap[0])

                image, person = TfPoseEstimator.draw_humans(image,
                                                            bodys,
                                                            imgcopy=False)
                #取10右脚 13左脚

                foot = []
                if len(person) > 0:
                    for p in person:
                        foot_lr = []
                        if 10 in p and 13 in p:
                            foot_lr.append(p[10])
                            foot_lr.append(p[13])

                        if len(foot_lr) > 1:
                            foot.append(foot_lr)

                fps = round(1 / (time.time() - time_n), 2)
                image = cv2.putText(image,
                                    str(fps) + 'fps', (10, 15),
                                    cv2.FONT_HERSHEY_COMPLEX_SMALL, 1,
                                    (255, 255, 255))
                time_n = time.time()

                #deep目标检测
                image2 = Image.fromarray(image_fist)
                boxs = yolo.detect_image(image2)
                features = encoder(image, boxs)
                detections = [
                    Detection(bbox, 1.0, feature)
                    for bbox, feature in zip(boxs, features)
                ]
                boxes = np.array([d.tlwh for d in detections])
                scores = np.array([d.confidence for d in detections])
                indices = preprocessing.non_max_suppression(
                    boxes, nms_max_overlap, scores)
                detections = [detections[i] for i in indices]
                if len(boxs) > max_boxs:
                    max_boxs = len(boxs)
                # print(max_boxs)

                # Call the tracker
                tracker.predict()
                tracker.update(detections)

                for track in tracker.tracks:

                    if max_boxs < track.track_id:
                        tracker.tracks.remove(track)
                        tracker._next_id = max_boxs + 1

                    if not track.is_confirmed() or track.time_since_update > 1:
                        continue

                    bbox = track.to_tlbr()
                    PointX = bbox[0] + ((bbox[2] - bbox[0]) / 2)
                    PointY = bbox[3]

                    if track.track_id not in person_track:
                        track2 = copy.deepcopy(track)
                        person_track[track.track_id] = track2

                    else:

                        track2 = copy.deepcopy(track)
                        bbox2 = person_track[track.track_id].to_tlbr()
                        PointX2 = bbox2[0] + ((bbox2[2] - bbox2[0]) / 2)
                        PointY2 = bbox2[3]
                        distance = math.sqrt(
                            pow(PointX - PointX2, 2) +
                            pow(PointY - PointY2, 2))
                        if distance < 120:
                            person_track[track.track_id] = track2

                        else:

                            # print('last',track.track_id)
                            dis = {}
                            for key in person_track:
                                bbox3 = person_track[key].to_tlbr()
                                PointX3 = bbox3[0] + (
                                    (bbox3[2] - bbox3[0]) / 2)
                                PointY3 = bbox3[3]

                                d = math.sqrt(
                                    pow(PointX3 - PointX, 2) +
                                    pow(PointY3 - PointY, 2))
                                dis[key] = d
                            dis = sorted(dis.items(),
                                         key=operator.itemgetter(1),
                                         reverse=False)

                            track2.track_id = dis[0][0]
                            person_track[dis[0][0]] = track2
                            tracker.tracks.remove(track)
                            tracker.tracks.append(person_track[track.track_id])

                    # 写入class

                    try:
                        box_title = face[track2.track_id - 1]
                    except Exception as e:
                        box_title = str(track2.track_id) + "_" + "unknow"
                    if box_title not in workers:
                        wid = box_title.split('_')[0]
                        localtime = time.asctime(time.localtime(time.time()))
                        workers[box_title] = wk.Worker()
                        workers[box_title].set(box_title, localtime,
                                               (int(PointX), int(PointY)))
                        cur2 = conn.cursor()  # 获取一个游标
                        sql2 = "UPDATE worker SET in_time='" + localtime + "' WHERE worker_id= '" + wid + "'"
                        cur2.execute(sql2)
                        cur2.close()  # 关闭游标

                    else:
                        localtime = time.asctime(time.localtime(time.time()))
                        yoloPoint = (int(PointX), int(PointY))
                        foot_dic = {}
                        wear_dic = {}

                        for f in foot:
                            fp = []
                            footCenter = ((f[0][0] + f[1][0]) / 2,
                                          (f[0][1] + f[1][1]) / 2)
                            foot_dis = int(
                                math.sqrt(
                                    pow(footCenter[0] - yoloPoint[0], 2) +
                                    pow(footCenter[1] - yoloPoint[1], 2)))
                            #print(foot_dis)
                            fp.append(f)
                            fp.append(footCenter)
                            foot_dic[foot_dis] = fp

                        #print(box_title, 'sss', foot_dic)
                        foot_dic = sorted(foot_dic.items(),
                                          key=operator.itemgetter(0),
                                          reverse=False)
                        workers[box_title].current_point = foot_dic[0][1][1]
                        workers[box_title].track_point.append(
                            workers[box_title].current_point)

                        #print(box_title,'sss',foot_dic[0][1][1])
                        mytrack = str(workers[box_title].track_point)
                        wid = box_title.split('_')[0]
                        #卡尔曼滤波预测
                        if wid not in KalmanNmae:
                            myKalman(wid)
                        if wid not in lmp:
                            setLMP(wid)
                        cpx, cpy = predict(workers[box_title].current_point[0],
                                           workers[box_title].current_point[1],
                                           wid)

                        if cpx[0] == 0.0 or cpy[0] == 0.0:
                            cpx[0] = workers[box_title].current_point[0]
                            cpy[0] = workers[box_title].current_point[1]
                        workers[box_title].next_point = (int(cpx), int(cpy))

                        workers[box_title].current_footR = foot_dic[0][1][0][0]
                        workers[box_title].current_footL = foot_dic[0][1][0][1]
                        cur3 = conn.cursor()  # 获取一个游标
                        sql = "UPDATE worker SET current_point= '" + str(
                            workers[box_title].current_point
                        ) + "' , current_footR = '" + str(
                            workers[box_title].current_footR
                        ) + "',current_footL = '" + str(
                            workers[box_title].current_footL
                        ) + "',track_point = '" + mytrack + "',next_point = '" + str(
                            workers[box_title].next_point
                        ) + "' WHERE worker_id= '" + wid + "'"
                        cur3.execute(sql)
                        cur3.close()
                        #写入安全措施情况
                        if len(wear) > 0:
                            for w in wear:
                                wear_dis = int(
                                    math.sqrt(
                                        pow(w[0] - yoloPoint[0], 2) +
                                        pow(w[1] - yoloPoint[1], 2)))
                                wear_dic[wear_dis] = w
                            wear_dic = sorted(wear_dic.items(),
                                              key=operator.itemgetter(0),
                                              reverse=False)

                            if wear_dic[0][0] < 120:
                                cur4 = conn.cursor()  # 获取一个游标

                                if wear[wear_dic[0][1]] == 1:
                                    if len(workers[box_title].wear['no helmet']
                                           ) == 0:
                                        workers[box_title].wear[
                                            'no helmet'].append(localtime)

                                        sql = "INSERT INTO wear SET worker_id = '" + wid + "', type = 'no_helmet',abnormal_time = '" + localtime + "'"
                                        cur4.execute(sql)
                                        cur4.close()  # 关闭游标

                                    else:
                                        if localtime not in workers[
                                                box_title].wear['no helmet']:

                                            workers[box_title].wear[
                                                'no helmet'].append(localtime)
                                            sql = "INSERT INTO wear SET worker_id = '" + wid + "', type = 'no_helmet',abnormal_time = '" + localtime + "'"
                                            cur4.execute(sql)
                                            cur4.close()  # 关闭游标

                                elif wear[wear_dic[0][1]] == 2:
                                    if len(workers[box_title].
                                           wear['no work cloths']) == 0:
                                        workers[box_title].wear[
                                            'no work cloths'].append(localtime)
                                        sql = "INSERT INTO wear SET worker_id = '" + wid + "', type = 'no work cloths',abnormal_time = '" + localtime + "'"
                                        cur4.execute(sql)
                                        cur4.close()  # 关闭游标
                                    else:
                                        if localtime not in workers[
                                                box_title].wear[
                                                    'no work cloths']:
                                            workers[box_title].wear[
                                                'no work cloths'].append(
                                                    localtime)
                                            sql = "INSERT INTO wear SET worker_id = '" + wid + "', type = 'no work cloths',abnormal_time = '" + localtime + "'"
                                            cur4.execute(sql)
                                            cur4.close()  # 关闭游标
                                elif wear[wear_dic[0][1]] == 3:
                                    if len(workers[box_title].
                                           wear['unsafe wear']) == 0:
                                        workers[box_title].wear[
                                            'unsafe wear'].append(localtime)
                                        sql = "INSERT INTO wear SET worker_id = '" + wid + "', type = 'unsafe wear',abnormal_time = '" + localtime + "'"
                                        cur4.execute(sql)
                                        cur4.close()  # 关闭游标
                                    else:
                                        if localtime not in workers[
                                                box_title].wear['unsafe wear']:
                                            workers[box_title].wear[
                                                'unsafe wear'].append(
                                                    localtime)
                                            sql = "INSERT INTO wear SET worker_id = '" + wid + "', type = 'unsafe wear',abnormal_time = '" + localtime + "'"
                                            cur4.execute(sql)
                                            cur4.close()  # 关闭游标

                        #写入越线情况

                        if len(workers[box_title].track_point) > 4:

                            for i in range(len(transboundaryline)):
                                p1 = (transboundaryline[i][0],
                                      transboundaryline[i][1])
                                p2 = (transboundaryline[i][2],
                                      transboundaryline[i][3])
                                p3 = workers[box_title].track_point[-2]
                                p4 = workers[box_title].track_point[-1]
                                a = t.IsIntersec(p1, p2, p3, p4)
                                if a == '有交点':

                                    cur5 = conn.cursor()  # 获取一个游标
                                    cur6 = conn.cursor()  # 获取一个游标
                                    cur5.execute(
                                        "select time from transboundary where worker_id = '"
                                        + wid + "' ")
                                    qurrytime = cur5.fetchone()
                                    cur5.close()  # 关闭游标
                                    if qurrytime == None:
                                        print('越线')
                                        sql = "INSERT INTO transboundary SET worker_id = '" + wid + "',time = '" + localtime + "'"
                                        cur6.execute(sql)
                                        cur6.close()  # 关闭游标
                                    else:
                                        temp1 = 0
                                        for qt in qurrytime:

                                            if qt == localtime:
                                                temp1 = 1
                                        if temp1 == 0:
                                            print('越线')
                                            sql = "INSERT INTO transboundary SET worker_id = '" + wid + "',time = '" + localtime + "'"
                                            cur6.execute(sql)
                                            cur6.close()  # 关闭游标
                        if len(workers[box_title].track_point) >= 20:
                            workers[box_title].previous_point = workers[
                                box_title].track_point[-5]
                    conn.commit()
                    try:
                        cv2.putText(image, face[track2.track_id - 1],
                                    (int(bbox[0]), int(bbox[1])), 0,
                                    5e-3 * 200, (0, 255, 0), 2)
                    except Exception as e:
                        cv2.putText(image, "unknow",
                                    (int(bbox[0]), int(bbox[1])), 0,
                                    5e-3 * 200, (0, 255, 0), 2)

                if args.video is not None:
                    image[27:img_corner.shape[0] +
                          27, :img_corner.shape[1]] = img_corner  # [3:-10, :]
                cv2.imshow(' ', image)
                if args.save_video is not None:
                    video_saver.write(image)
                cv2.waitKey(1)
            else:

                image = common.read_imgfile(args.image)
                size = [image.shape[0], image.shape[1]]
                if image is None:
                    logger.error('Image can not be read, path=%s' % args.image)
                    sys.exit(-1)
                h = int(654 * (size[0] / size[1]))
                img = np.array(cv2.resize(image, (654, h)))
                cv2.imshow('ini', img)
                img = img[np.newaxis, :]
                peaks, heatmap, vectormap = sess.run(
                    [tensor_peaks, hm_up, cpm_up],
                    feed_dict={
                        raw_img: img,
                        img_size: size
                    })
                cv2.imshow('in', vectormap[0, :, :, 0])
                bodys = PoseEstimator.estimate_paf(peaks[0], heatmap[0],
                                                   vectormap[0])
                image = TfPoseEstimator.draw_humans(image,
                                                    bodys,
                                                    imgcopy=False)
                cv2.imshow(' ', image)
                cv2.waitKey(0)
示例#9
0
class Ui_MainWindow(object):
    VIDEO_TYPE_OFFLINE = 0
    VIDEO_TYPE_REAL_TIME = 1

    STATUS_INIT = 0
    STATUS_PLAYING = 1
    STATUS_PAUSE = 2

    video_url = ""

    def __init__(self,
                 video_url="",
                 video_type=VIDEO_TYPE_OFFLINE,
                 auto_play=False):
        self.video_url = video_url
        self.video_type = video_type
        self.auto_play = auto_play
        self.status = self.STATUS_INIT
        self.yolo = YOLO()

        self.timer = VideoTimer()
        self.timer.timeSignal.signal[str].connect(self.show_video_images)

        self.playCapture = VideoCapture()
        if self.video_url != "":
            self.playCapture.open(self.video_url)
            fps = self.playCapture.get(CAP_PROP_FPS)
            self.timer.set_fps(fps)
            self.playCapture.release()
            if self.auto_play:
                self.switch_video()

    def reset(self):
        self.timer.stop()
        self.playCapture.release()
        self.status = Ui_MainWindow.STATUS_INIT

    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1086, 597)
        MainWindow.setStyleSheet("background-color:rgb(76, 126, 201)")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.frame = QtWidgets.QFrame(self.centralwidget)
        self.frame.setGeometry(QtCore.QRect(0, -30, 1131, 621))
        self.frame.setStyleSheet("background-color:rgb(76, 126, 201)")
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.label_7 = QtWidgets.QLabel(self.frame)
        self.label_7.setGeometry(QtCore.QRect(130, 360, 635, 23))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        self.label_7.setPalette(palette)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(10)
        self.label_7.setFont(font)
        self.label_7.setObjectName("label_7")
        self.label_14 = QtWidgets.QLabel(self.frame)
        self.label_14.setEnabled(True)
        self.label_14.setGeometry(QtCore.QRect(130, 495, 646, 24))
        self.label_14.setText("")
        self.label_14.setObjectName("label_14")
        self.label_11 = QtWidgets.QLabel(self.frame)
        self.label_11.setGeometry(QtCore.QRect(130, 204, 646, 24))
        self.label_11.setText("")
        self.label_11.setObjectName("label_11")
        self.label_10 = QtWidgets.QLabel(self.frame)
        self.label_10.setGeometry(QtCore.QRect(130, 173, 16, 17))
        self.label_10.setText("")
        self.label_10.setObjectName("label_10")
        self.label_5 = QtWidgets.QLabel(self.frame)
        self.label_5.setGeometry(QtCore.QRect(130, 329, 461, 23))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        self.label_5.setPalette(palette)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(10)
        self.label_5.setFont(font)
        self.label_5.setObjectName("label_5")
        self.label_6 = QtWidgets.QLabel(self.frame)
        self.label_6.setGeometry(QtCore.QRect(130, 391, 646, 23))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        self.label_6.setPalette(palette)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(10)
        self.label_6.setFont(font)
        self.label_6.setObjectName("label_6")
        self.label_13 = QtWidgets.QLabel(self.frame)
        self.label_13.setGeometry(QtCore.QRect(130, 432, 646, 24))
        self.label_13.setText("")
        self.label_13.setObjectName("label_13")
        self.label = QtWidgets.QLabel(self.frame)
        self.label.setGeometry(QtCore.QRect(130, 30, 389, 136))
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(28)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setStyleSheet("color:white")
        self.label.setObjectName("label")
        self.line = QtWidgets.QFrame(self.frame)
        self.line.setGeometry(QtCore.QRect(130, 422, 646, 16))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        self.line.setPalette(palette)
        self.line.setStyleSheet("color:white")
        self.line.setFrameShadow(QtWidgets.QFrame.Plain)
        self.line.setLineWidth(1)
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setObjectName("line")
        self.label_12 = QtWidgets.QLabel(self.frame)
        self.label_12.setGeometry(QtCore.QRect(130, 266, 646, 25))
        self.label_12.setText("")
        self.label_12.setObjectName("label_12")
        self.pushButton = QtWidgets.QPushButton(self.frame)
        self.pushButton.setGeometry(QtCore.QRect(840, 340, 211, 51))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ToolTipText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipText,
                         brush)
        self.pushButton.setPalette(palette)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.pushButton.setFont(font)
        self.pushButton.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.pushButton.setStyleSheet("background-color:rgb(60, 171, 255)\n"
                                      "")
        self.pushButton.setObjectName("pushButton")
        self.label_3 = QtWidgets.QLabel(self.frame)
        self.label_3.setGeometry(QtCore.QRect(130, 463, 71, 24))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        self.label_3.setPalette(palette)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(11)
        self.label_3.setFont(font)
        self.label_3.setObjectName("label_3")
        self.label_4 = QtWidgets.QLabel(self.frame)
        self.label_4.setGeometry(QtCore.QRect(130, 235, 507, 23))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        self.label_4.setPalette(palette)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(10)
        self.label_4.setFont(font)
        self.label_4.setObjectName("label_4")
        self.label_8 = QtWidgets.QLabel(self.frame)
        self.label_8.setGeometry(QtCore.QRect(130, 298, 289, 23))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        self.label_8.setPalette(palette)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(10)
        self.label_8.setFont(font)
        self.label_8.setObjectName("label_8")
        self.label_9 = QtWidgets.QLabel(self.frame)
        self.label_9.setGeometry(QtCore.QRect(130, 526, 196, 24))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        self.label_9.setPalette(palette)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(11)
        self.label_9.setFont(font)
        self.label_9.setObjectName("label_9")
        self.frame_2 = QtWidgets.QFrame(self.frame)
        self.frame_2.setGeometry(QtCore.QRect(20, 30, 1061, 581))
        self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_2.setObjectName("frame_2")
        self.label_2 = QtWidgets.QLabel(self.frame_2)
        self.label_2.setGeometry(QtCore.QRect(30, -20, 371, 121))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        self.label_2.setPalette(palette)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(28)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.line_2 = QtWidgets.QFrame(self.frame_2)
        self.line_2.setGeometry(QtCore.QRect(30, 70, 281, 16))
        self.line_2.setStyleSheet("color:white")
        self.line_2.setFrameShadow(QtWidgets.QFrame.Plain)
        self.line_2.setLineWidth(1)
        self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_2.setObjectName("line_2")
        self.label_15 = QtWidgets.QLabel(self.frame_2)
        self.label_15.setGeometry(QtCore.QRect(30, 90, 751, 21))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(76, 126, 201))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        self.label_15.setPalette(palette)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(11)
        self.label_15.setFont(font)
        self.label_15.setObjectName("label_15")
        self.pushButton_2 = QtWidgets.QPushButton(self.frame_2)
        self.pushButton_2.setGeometry(QtCore.QRect(800, 380, 151, 61))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        self.pushButton_2.setPalette(palette)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(12)
        self.pushButton_2.setFont(font)
        self.pushButton_2.setStyleSheet("background-color:rgb(60, 171, 255)")
        self.pushButton_2.setObjectName("pushButton_2")
        self.label_16 = QtWidgets.QLabel(self.frame_2)
        self.label_16.setGeometry(QtCore.QRect(80, 170, 611, 391))
        self.label_16.setStyleSheet("background-color:white")
        self.label_16.setText("")
        self.label_16.setObjectName("label_16")
        self.line_3 = QtWidgets.QFrame(self.frame_2)
        self.line_3.setGeometry(QtCore.QRect(20, 160, 20, 401))
        self.line_3.setStyleSheet("color:white")
        self.line_3.setFrameShadow(QtWidgets.QFrame.Plain)
        self.line_3.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_3.setObjectName("line_3")
        self.pushButton_3 = QtWidgets.QPushButton(self.frame_2)
        self.pushButton_3.setGeometry(QtCore.QRect(800, 480, 151, 61))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(60, 171, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        self.pushButton_3.setPalette(palette)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(12)
        self.pushButton_3.setFont(font)
        self.pushButton_3.setStyleSheet("background-color:rgb(60, 171, 255)")
        self.pushButton_3.setObjectName("pushButton_3")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1086, 26))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.frame_2.setVisible(False)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        self.pushButton.clicked.connect(self.pushButton_clicked)

    def pushButton_clicked(self):
        self.frame.setVisible(True)
        self.frame_2.setVisible(True)

    def show_video_images(self):
        if self.playCapture.isOpened():
            success, frame = self.playCapture.read()
            # fileName_choose, filetype = QFileDialog.getOpenFileName()
            # print(fileName_choose)
            # playCapture = VideoCapture()
            # self.playCapture.open(fileName_choose)
            # fps = playCapture.get(CAP_PROP_FPS)

            if success:
                frame = self.yolo.detect_image(PIL.Image.fromarray(frame))
                frame = cv2.cvtColor(numpy.asarray(frame), cv2.COLOR_RGB2BGR)
                print("aaaaaa")
                height, width = frame.shape[:2]
                if frame.ndim == 3:
                    rgb = cvtColor(frame, COLOR_BGR2RGB)
                else:
                    rgb = cvtColor(frame, COLOR_GRAY2BGR)

                temp_image = QImage(rgb.flatten(), width, height,
                                    QImage.Format_RGB888)
                temp_pixmap = QPixmap.fromImage(temp_image)

                self.label_16.setPixmap(temp_pixmap)
                self.label_16.setScaledContents(True)
                print("bbbbbbbbbb")
            else:
                print("read failed, no frame data")
                self.reset()
                return
        # success, frame = self.playCapture.read()
        # if not success and self.video_type is VideoBox.VIDEO_TYPE_OFFLINE:
        # print("play finished")  # 判断本地文件播放完毕
        # self.reset()
        # self.playButton.setIcon(self.style().standardIcon(QStyle.SP_MediaStop))

    def switch_video(self):
        fileName_choose, filetype = QFileDialog.getOpenFileName()
        print(fileName_choose)
        self.video_url = fileName_choose
        self.status = Ui_MainWindow.STATUS_INIT
        if self.video_url == "" or self.video_url is None:
            return
        if self.status is Ui_MainWindow.STATUS_INIT:
            self.playCapture.open(self.video_url)
            self.timer.start()
        elif self.status is Ui_MainWindow.STATUS_PLAYING:
            self.timer.stop()
            if self.video_type is Ui_MainWindow.VIDEO_TYPE_REAL_TIME:
                self.playCapture.release()
        elif self.status is Ui_MainWindow.STATUS_PAUSE:
            if self.video_type is Ui_MainWindow.VIDEO_TYPE_REAL_TIME:
                self.playCapture.open(self.video_url)
            self.timer.start()

        self.status = (Ui_MainWindow.STATUS_PLAYING,
                       Ui_MainWindow.STATUS_PAUSE,
                       Ui_MainWindow.STATUS_PLAYING)[self.status]

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label_7.setText(
            _translate(
                "MainWindow",
                "license owners,you will be able to access your downloads once you log in.Not"
            ))
        self.label_5.setText(
            _translate(
                "MainWindow",
                "It\'s true.We\'re fanatical about it.And we\'ve got your back."
            ))
        self.label_6.setText(
            _translate(
                "MainWindow",
                "If you have a question,use any of the below options to get in touch.Commercial"
            ))
        self.label.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p>Welcome to</p><p>Carditec website</p></body></html>"
            ))
        self.pushButton.setText(_translate("MainWindow", "START"))
        self.label_3.setText(_translate("MainWindow", "Email us"))
        self.label_4.setText(
            _translate(
                "MainWindow",
                "We mainly provides vehicle identification technology support."
            ))
        self.label_8.setText(
            _translate("MainWindow", "Not sure what to do next?Read this."))
        self.label_9.setText(_translate("MainWindow", "*****@*****.**"))
        self.label_2.setText(_translate("MainWindow", "LET\'S START"))
        self.label_15.setText(
            _translate(
                "MainWindow",
                "Import a picture or video,the website will analyze vehicle types and show the results."
            ))
        self.pushButton_2.setText(_translate("MainWindow", "UPLOAD"))
        self.pushButton_3.setText(_translate("MainWindow", "DOWNLOAD"))
        self.pushButton_2.clicked.connect(self.switch_video)
示例#10
0
def main():
    start = time.time()
    first = start
    #Definition of the parameters
    max_cosine_distance = 0.5#0.9 余弦距离的控制阈值
    nn_budget = None
    nms_max_overlap = 0.3 #非极大抑制的阈值

    counter = []

    #deep_sort
    model_filename = 'model_data/market1501.pb'
    encoder = gdet.create_box_encoder(model_filename,batch_size=1)

    find_objects = ['person', 'fire_extinguisher', 'fireplug', 'car', 'bicycle', 'motorcycle']
    yolo = YOLO()

    for cnt in range(1, 2):
        video_path = "./t1_video/t1_video_%05d" % cnt
        images = os.listdir(video_path)
        images.sort()
        print(images[0])
        trackers = []
        counters = []
        for idx in range(0, 6):
            metric = nn_matching.NearestNeighborDistanceMetric("cosine", max_cosine_distance, nn_budget)
            trackers.append(Tracker(metric))
            count = []
            counters.append(count)
        tracker_time = 0
        yolo_time = 0
        for image_path in images:
            # image_path = video_path + "/t1_video_%05d_%05d.jpg" % (1, fc)
            t1 = time.time()
            # print(video_path + "/" + image_path)
            frame = cv2.imread(video_path + "/" + image_path)
            image = Image.fromarray(frame[..., ::-1])  # bgr to rgb

            yolo_start = time.time()
            yolo_dict = yolo.detect_image(image)
            yolo_end = time.time()
            yolo_time += (yolo_end - yolo_start)

            for idx in range(0, 6):
                # print(idx)
                tracker = trackers[idx]
                counter = counters[idx]

                boxs = yolo_dict.get(find_objects[idx])
                if boxs == None:
                    continue

                features = encoder(frame, boxs)
                # score to 1.0 here).
                detections = [Detection(bbox, 1.0, feature) for bbox, feature in zip(boxs, features)]
                # Run non-maxima suppression.
                boxes = np.array([d.tlwh for d in detections])
                scores = np.array([d.confidence for d in detections])
                indices = preprocessing.non_max_suppression(boxes, nms_max_overlap, scores)
                detections = [detections[i] for i in indices]

                # Call the tracker
                t_start = time.time()
                tracker.predict()
                tracker.update(detections)
                t_end = time.time()
                tracker_time += (t_end - t_start)

                for track in tracker.tracks:
                    if not track.is_confirmed() or track.time_since_update > 1:
                        continue
                    #boxes.append([track[0], track[1], track[2], track[3]])

                    counter.append(int(track.track_id))
        #######################################
        num_person = len(set(counters[0]))
        num_fire_extinguisher = len(set(counters[1]))
        num_fireplug = len(set(counters[2]))
        num_car = len(set(counters[3]))
        num_bicycle = len(set(counters[4]))
        num_motocycle = len(set(counters[5]))
        ress.append(present_result(cnt, num_person,
                            num_fire_extinguisher,
							num_fireplug,
							num_car,
							num_bicycle,
							num_motocycle))

        t1_res_cai["track1_results"] = ress
        with open('t1_res_cai.json', 'w') as make_file:
            json.dump(t1_res_cai, make_file, ensure_ascii=False, indent=4)
		#######################################


        for idx in range(0, 6):
            print(len(set(counters[idx])), end=" ")
        end = time.time()
        print(str(':: total:%.2f yolo:%.2f tracker:%.2f' % ((end - start),yolo_time, tracker_time)))
        start = end
    last = time.time()
    print(str(':: %.2f' % (last - first)))
示例#11
0
images = data[0]
# labels = data[1] these are not labels. batch size

model_path = 'logs/000/ep009-loss30.814-val_loss30.951.h5'

yolo_model =  yolo_body(Input(shape=(None,None,3)), num_anchors//3, num_classes)
yolo_model.load_weights(model_path)

FLAGS = {
        "model_path": model_path,
        "anchors_path": anchors_path,
        "classes_path": classes_path,
        "score" : 0.3,
        "iou" : 0.45,
        "model_image_size" : (416, 416),
        "gpu_num" : 1,
    }

model = YOLO()

image_base_path = '/home/shuby.deshpande/workspace/keras-yolo3/data/5cc3a5ef4e436f43f7b5615f/images/*'
image_paths = glob.glob(image_base_path)
for image_path in range(len(image_paths)):
    image = Image.open(image_paths[image_path])
    pred = model.detect_image(image)
    image_name =  str(image_path)+'_pred.jpeg'
    print('-'*50)
    print('Predicting bbox for image:', image_path)
    print('-'*50)
    pred.save(image_name)
示例#12
0
    def process_video(self):
        self.progressLabel.setText("Loading Yolo Model")
        QtCore.QCoreApplication.processEvents()
        from collections import deque
        from yolo import YOLO
        from yolo3 import utils
        from PIL import Image
        import cv2

        frame_buffer = deque([], 3)

        bridge_buffer = []
        bridge_last = -1

        extended = False

        counter_ = 0
        frame_counter = 0

        yolo_model = YOLO()

        capture = cv2.VideoCapture(self.input_path)

        if not capture.isOpened():
            raise IOError("Couldn't open video")

        video_fps = capture.get(cv2.CAP_PROP_FPS)
        video_size = (int(capture.get(cv2.CAP_PROP_FRAME_WIDTH)),
                      int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
        max_frame_count = capture.get(cv2.CAP_PROP_FRAME_COUNT)

        out = cv2.VideoWriter(self.output_path,
                              cv2.VideoWriter_fourcc(*'DIVX'), video_fps,
                              video_size)

        self.progressLabel.setText("Detecting")
        while (capture.isOpened()):
            ret, frame = capture.read()

            frame_counter += 1

            if ret:
                image = Image.fromarray(frame)
                bboxes_pr = yolo_model.detect_image(image)
                frame_buffer.append([bboxes_pr, frame])

                if len(frame_buffer) >= frame_buffer.maxlen:
                    img_pred = frame_buffer[0][1].copy()

                    if counter_ > 0:
                        extended = False
                        counter_ = 0

                    if extended:
                        counter_ += 1

                        if not extended and len(frame_buffer[1][0]) <= 0:
                            if len(frame_buffer[0][0]) > 0 or len(
                                    frame_buffer[2][0]) > 0:
                                if len(frame_buffer[0][0]) > 0:
                                    frame_buffer[1][0] = frame_buffer[0][0]

                                else:
                                    frame_buffer[1][0] = frame_buffer[2][0]

                                extended = True

                    img_pred = utils.blur_img(frame_buffer[0][0], img_pred)

                    height, width, channel = img_pred.shape
                    bytesPerLine = 3 * width
                    qimg = QtGui.QImage(img_pred.data, width, height,
                                        bytesPerLine,
                                        QtGui.QImage.Format_BGR888)
                    self.frame.setPixmap(QtGui.QPixmap(qimg))
                    progress_value = int(frame_counter / max_frame_count * 100)
                    self.progressBar.setProperty("value", progress_value)
                    # Updates Picture + Progressbar
                    QtCore.QCoreApplication.processEvents()

                    bridge_buffer.append([frame_buffer[0][0], img_pred])

                    if len(bridge_buffer) >= 50:
                        if len(frame_buffer[0][0]) == len(frame_buffer[1][0]):
                            bridge_buffer = utils.fill_bridges(bridge_buffer)

                            for list in bridge_buffer:
                                out.write(list[1])
                            bridge_buffer = []
            else:
                bridge_buffer = utils.fill_bridges(bridge_buffer)

                for list in bridge_buffer:
                    out.write(list[1])
                bridge_buffer = []

                capture.release()
                out.release()
                # yolo_model.close_session()

                self.progressLabel.setText("Adding Audio to the Outputfile")
                temp_output = self.output_path.split("/")
                temp_output[-1] = temp_output[-1].split(".")[0] + "_.mp4"
                temp_output = "/".join(temp_output)
                os.system(
                    f'ffmpeg -i "{self.output_path}" -i "{self.input_path}" -map 0:v -map 1:a -c copy -shortest "{temp_output}"'
                )
                os.remove(self.output_path)
                os.rename(temp_output, self.output_path)

                self.progressLabel.setText("Finished")
                break
示例#13
0
        1、如果想要进行检测完的图片的保存,利用r_image.save("img.jpg")即可保存,直接在predict.py里进行修改即可。 
        2、如果想要获得预测框的坐标,可以进入yolo.detect_image函数,在绘图部分读取top,left,bottom,right这四个值。
        3、如果想要利用预测框截取下目标,可以进入yolo.detect_image函数,在绘图部分利用获取到的top,left,bottom,right这四个值
        在原图上利用矩阵的方式进行截取。
        4、如果想要在预测图上写额外的字,比如检测到的特定目标的数量,可以进入yolo.detect_image函数,在绘图部分对predicted_class进行判断,
        比如判断if predicted_class == 'car': 即可判断当前目标是否为车,然后记录数量即可。利用draw.text即可写字。
        '''
        while True:
            img = input('Input image filename:')
            try:
                image = Image.open(img)
            except:
                print('Open Error! Try again!')
                continue
            else:
                r_image = yolo.detect_image(image)
                r_image.show()

    elif mode == "video":
        capture = cv2.VideoCapture(video_path)
        if video_save_path != "":
            fourcc = cv2.VideoWriter_fourcc(*'XVID')
            size = (int(capture.get(cv2.CAP_PROP_FRAME_WIDTH)),
                    int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
            out = cv2.VideoWriter(video_save_path, fourcc, video_fps, size)

        ref, frame = capture.read()
        if not ref:
            raise ValueError("未能正确读取摄像头(视频),请注意是否正确安装摄像头(是否正确填写视频路径)。")

        fps = 0.0
示例#14
0
def detect_img():
    yolo = YOLO()
    image = Image.open('03.jpg')
    r_image = yolo.detect_image(image)
    yolo.close_session()
    r_image.show()
示例#15
0
from nets.yolo3 import yolo_body
from keras.layers import Input
from yolo import YOLO
from PIL import Image, ImageDraw

yolo = YOLO()
trfn = 0
carn = 0
lrx = 920
rrx = 880
carnums = 0
carlist = []
while True:
    img = input('Input image filename:')
    try:
        image = Image.open(img)
    except:
        print('Open Error! Try again!')
        continue
    else:
        r_image, i, m = yolo.detect_image(image, trfn, carn, lrx, rrx, carnums,
                                          carlist)
        draw = ImageDraw.Draw(r_image)
        draw.line((260, 850, 1500, 850), fill='red', width=5)
        trfn = i
        carn = m
        r_image.show()
示例#16
0
文件: 1023test.PY 项目: tces88725/-
# result如果之前存放的有文件,全部清除
for i in os.listdir(result_path):
    path_file = os.path.join(result_path,i)  
    if os.path.isfile(path_file):
        os.remove(path_file)

#创建一个记录检测结果的文件
txt_path =result_path + '/result.txt'
file = open(txt_path,'w')  


 
while True:
 
    image_array = grab_screen(region=(0, 0, 1280, 720))
    # 获取屏幕,(0, 0, 1280, 720)表示从屏幕坐标(0,0)即左上角,截取往右1280和往下720的画面
    array_to_image = Image.fromarray(image_array, mode='RGB') #将array转成图像,才能送入yolo进行预测
    img = yolo.detect_image(array_to_image)  #调用yolo文件里的函数进行检测
 
    img = np.asarray(img) #将图像转成array
 
    cv2.imshow('window',cv2.cvtColor(img, cv2.COLOR_BGR2RGB))#将截取的画面从另一窗口显示出来,对速度会有一点点影响,不过也就截取每帧多了大约0.01s的时间
    
    file.write('  score: '+str(yolo.detect_image.score)+' \nlocation: top: '+str(top)+'、 bottom: '+str(bottom)+'、 left: '+str(left)+'、 right: '+str(right)+'\n')
    
    
    
    if cv2.waitKey(25) & 0xFF == ord('q'):  #按q退出,记得输入切成英语再按q
        cv2.destroyAllWindows()
        break
示例#17
0
import cv2
from PIL import Image
from yolo import YOLO
import numpy as np
import os
import pandas

label_path = r'F:\dataset\kaggle\whale\bounding_boxes.csv'
image_path = r'F:\dataset\kaggle\whale\train'
file_list = os.listdir(image_path)
obj = YOLO()
for file in file_list:
    filename = os.path.join(image_path, file)
    img = Image.open(filename)
    result = obj.detect_image(img)
    cv2.imshow(file, np.asarray(result))
    cv2.waitKey(0)
    cv2.destroyAllWindows()

# df = pandas.read_csv(label_path)

# for data in df.values:
#     filename = os.path.join(image_path,data[0])
#     if os.path.exists(filename):
#         img = cv2.imread(filename)
#         cv2.rectangle(img,tuple(data[1:3]),tuple(data[3:]),(0,0,255))
#         cv2.imshow(data[0],img)
#         cv2.waitKey(0)
#         cv2.destroyAllWindows()

# obj.detect_image()
示例#18
0
            ##############

            try:
                image = Image.open(tmp_path)
            except Exception as e:
                print(e)
                continue
            th_w, th_h = image.size

            org_w = canvas["width"]

            # オリジナルサイズ
            r = org_w / th_w

            result = yolo.detect_image(image)
            # print(result)

            ##############

            for obj in result:

                tx = obj["x"]
                ty = obj["y"]
                tw = obj["w"]
                th = obj["h"]

                x = str(int(tx * r))
                y = str(int(ty * r))
                w = str(int(tw * r))
                h = str(int(th * r))
示例#19
0
#TODO: delete this file when done
import sys
sys.path.append("player_recognition")

import numpy as np

from yolo import YOLO
from PIL import Image
from mask import MaskRCNN

yolo = YOLO()
yolo_boxes = yolo.detect_image(
    Image.open("player_recognition/sports_images/liverpool-chelsea.jpeg"))

mask_rcnn = MaskRCNN()
mask_boxes = mask_rcnn.model.detect([
    np.asarray(
        Image.open("player_recognition/sports_images/liverpool-chelsea.jpeg"))
])
    video_size = (int(vid.get(cv2.CAP_PROP_FRAME_WIDTH)),
                  int(vid.get(cv2.CAP_PROP_FRAME_HEIGHT)))
    DETECT_EVERY_N_FRAMES = round(video_fps)  # detect every second
    out = cv2.VideoWriter(video_output_path, video_FourCC, video_fps,
                          video_size)

    yolo = YOLO()
    region_list = []
    illegal_list = []

    # vehicle detection for frame 0
    return_value, cur_img_cv = vid.read()
    cur_img_cv = cv2.cvtColor(cur_img_cv, cv2.COLOR_BGR2RGB)
    image = Image.fromarray(
        cur_img_cv)  # transfer OpenCV format to PIL.Image format
    image_canvas, out_boxes, out_scores, out_classes = yolo.detect_image(image)

    for i in range(len(out_boxes)):
        class_name = yolo.class_names[out_classes[i]]
        if class_name in VEHICLES:
            region = Region(out_boxes[i], class_name)
            region_list.append(region)

    idx = 1  # frame no.
    result = None

    while True:
        if DRAW_ON_DETECTION_RESULTS == False:
            image_canvas = image

        pre_img_cv = cv2.cvtColor(
示例#21
0
class SpineYolo(object):

    def __init__(self, _args):
        self.training_data_path = os.path.expanduser(_args.train_data_path)
        self.validation_data_path = os.path.expanduser(_args.val_data_path)
        self.classes_path = os.path.expanduser(_args.classes_path)
        self.anchors_path = os.path.expanduser(_args.anchors_path)
        self.model_path = os.path.expanduser(_args.model_path)
        self.log_dir = os.path.join('logs', '000')
        self.yolo_detector = None

    def detect_input_images(self):
        while True:
            img_path = input('Input image or image list filename:')
            if os.path.splitext(img_path)[1] == '.txt':
                self.detect_images_from_file_list(img_path)
                break
            try:
                image = Image.open(img_path)
            except:
                print('Open Error! Try again!')
                continue
            else:
                r_image = self.yolo_detector.detect_image(image)
                r_image.show()
        self.yolo_detector.close_session()

    def detect(self):
        self.yolo_detector = YOLO(**{"model_path": self.model_path})
        self.detect_input_images()

    def detect_images_from_file_list(self, img_path):
        with open(img_path) as f:
            lines = f.readlines()
        for line in lines:
            try:
                img_file = line.strip().split()[0]
                image = Image.open(img_file)
            except:
                print('Couldn''t load image file: {}'.format(img_file))
                continue
            r_image = self.yolo_detector.detect_image(image)
            r_image.show()

    def train_yolo(self, training_data_to_use=1):
        parsed_training_data = get_lines_from_annotation_file(self.training_data_path)
        parsed_validation_data = get_lines_from_annotation_file(self.validation_data_path)
        training_samples = round(len(parsed_training_data) * training_data_to_use)
        parsed_training_data = parsed_training_data[:training_samples]
        if training_data_to_use != 1:
            self.set_log_dir(os.path.join('logs', 'training_samples_{}'.format(training_samples)))
        train_spine_yolo(parsed_training_data, parsed_validation_data, self.log_dir, self.classes_path,
                         self.anchors_path, self.model_path)

    def set_log_dir(self, log_dir):
        self.log_dir = log_dir

    def set_training_data_path(self, path):
        self.training_data_path = path

    def set_validation_data_path(self, path):
        self.validation_data_path = path

    def set_model_path(self, path):
        self.model_path = path

    def prepare_image_data(self, images_path, is_labeled=False, train_test_split=0.8):
        spine_data_preparer = SpineImageDataPreparer()
        spine_data_preparer.set_initial_directory(images_path)
        spine_data_preparer.set_labeled_state(is_labeled)
        spine_data_preparer.set_train_test_split(train_test_split)
        spine_data_preparer.run()
示例#22
0
def read(stack) :
    print('Process to read: %s' % os.getpid())
    yolo = YOLO()
    # Definition of the parameters
    max_cosine_distance = 0.3
    nn_budget = None
    nms_max_overlap = 1.0
    # deep_sort
    model_filename = 'model_data/mars-small128.pb'
    encoder = gdet.create_box_encoder(model_filename, batch_size=1)

    metric = nn_matching.NearestNeighborDistanceMetric("cosine", max_cosine_distance, nn_budget)
    tracker = Tracker(metric)
    max_boxs = 0
    face = ['17208019']

    #目标上一帧的点
    history = {}
    #id和标签的字典
    person = {}
    #赋予新标签的id列表
    change = []
    while True:
        if len(stack) != 0:
            frame = stack.pop()
            t1 = time.time()
            frame_count = 0
            localtime = time.asctime(time.localtime(time.time()))
            utils.draw(frame,line.readline())
            # 获取警戒线
            transboundaryline = line.readline()
            utils.draw(frame, transboundaryline)
            img = Image.fromarray(frame)
            #img.save('frame.jpg')
            '''
            cv2.line(frame, (837, 393), (930, 300), (0, 255, 255), 3)
            transboundaryline = t.line_detect_possible_demo(frame)
            '''
            # image = Image.fromarray(frame)
            image = Image.fromarray(frame[..., ::-1])  # bgr to rgb
            boxs = yolo.detect_image(image)
            # print("box_num",len(boxs))
            features = encoder(frame, boxs)

            # score to 1.0 here).
            detections = [Detection(bbox, 1.0, feature) for bbox, feature in zip(boxs, features)]

            # Run non-maxima suppression.
            boxes = np.array([d.tlwh for d in detections])
            scores = np.array([d.confidence for d in detections])
            indices = preprocessing.non_max_suppression(boxes, nms_max_overlap, scores)
            detections = [detections[i] for i in indices]
            if len(boxs) > max_boxs:
                max_boxs = len(boxs)
            # Call the tracker
            tracker.predict()
            tracker.update(detections)
            #一帧信息
            info = {}
            target = []
            for track in tracker.tracks:
                #一帧中的目标
                per_info = {}
                if not track.is_confirmed() or track.time_since_update > 1:
                    continue
                if track.track_id not in person:
                    person[track.track_id] = str(track.track_id)
                bbox = track.to_tlbr()
                PointX = bbox[0] + ((bbox[2] - bbox[0]) / 2)
                PointY = bbox[3]
                dis = int(PointX) - 1200
                try:
                    if dis<15:
                        if track.track_id not in change:
                            person[track.track_id] = face.pop(0)
                            change.append(track.track_id)
                except:
                    print('非法入侵')
                #当前目标
                if track.track_id not in change:
                    per_info['worker_id'] = 'unknow'+str(track.track_id)
                else:
                    per_info['worker_id'] = person[track.track_id]
                #当前目标坐标
                yoloPoint = (int(PointX), int(PointY))
                per_info['current_point'] = yoloPoint

                # 卡尔曼滤波预测
                if per_info['worker_id'] not in utils.KalmanNmae:
                    utils.myKalman(per_info['worker_id'])
                if per_info['worker_id'] not in utils.lmp:
                    utils.setLMP(per_info['worker_id'])
                cpx, cpy = utils.predict(yoloPoint[0], yoloPoint[1], per_info['worker_id'])

                if cpx[0] == 0.0 or cpy[0] == 0.0:
                    cpx[0] = yoloPoint[0]
                    cpy[0] = yoloPoint[1]
                if frame_count>20:
                    per_info['next_point'] = (int(cpx), int(cpy))
                else:
                    per_info['next_point'] = yoloPoint

                # 写入越线情况
                if per_info['worker_id'] in history:
                    per_info['transboundary'] = 'no'
                    #print(transboundaryline)

                    line1 = [per_info['next_point'],history[per_info['worker_id']]]
                    a = line.IsIntersec2(transboundaryline,line1)

                    if a == '有交点':
                        print('越线提醒')

                        per_info['transboundary'] = 'yes'


                history[per_info['worker_id']] = per_info['current_point']

                frame_count = frame_count+1
                #print(per_info)
                #画目标框
                #cv2.rectangle(frame, (int(bbox[0]), int(bbox[1])), (int(bbox[2]), int(bbox[3])), (255, 255, 255), 2)
                cv2.putText(frame, per_info['worker_id'], (int(bbox[0]), int(bbox[1])), 0, 5e-3 * 200, (0, 255, 0), 2)
                target.append(per_info)
            info['time'] = localtime
            #info['frame'] = str(img.tolist()).encode('base64')
            info['frame'] = 'frame'
            info['target'] = target
            #写入josn
            info_json = json.dumps(info)
            info_queue.put(info_json)
            getInfo(info_queue)
            cv2.imshow("img", frame)
            key = cv2.waitKey(1) & 0xFF
            if key == ord('q'):
                break
示例#23
0
        cv2.rectangle(image, (x_minimo, y_minimo + int(y_min)),
                      (x_maximo, y_maximo + int(y_min)), (0, 0, 255), 1)
        dni1, dni2, cel1, cel2 = dni_rect_from_ce(c_x, c_y + y_min, cv2, image,
                                                  traslation_dict, {})

        try:
            # Getting DNI area
            dniGray = cv2.cvtColor(frame[dni1[1]:dni2[1], dni1[0]:dni2[0]],
                                   cv2.COLOR_BGR2GRAY)

            # Preprocessing dni area
            dniGrayTresh = deleting_horizontal_lines(cv2, dniGray.copy())

            # Getting the model output
            pil_dni = Image.fromarray(dniGrayTresh)
            dni_img, dni_boxes, dni_scores, dni_classes = yolo.detect_image(
                pil_dni)

            # Ordering boxes by axis x
            boxes, scores, classes, cxs, cys = ordering_cx(
                dni_boxes, dni_scores, dni_classes)

            # Filtering erronues boxes
            valid_ixs = filter_near_cxs(cxs, scores)
            valid_cys = np.take(cys, valid_ixs)

            prom = valid_cys.sum() / valid_cys.size
            desv = (((valid_cys - prom)**2).sum() / valid_cys.size)**(1 / 2)
            valid_ixs = filter_far_from_cys(valid_ixs, cys, desv, prom)

            b = []
            for i in valid_ixs:
示例#24
0
class SignDetector(object):
    def __init__(self):

        FLAGS = {
            "model_path": sys.path[1] + cf.sign_weight_h5_path,
            "anchors_path": sys.path[1] + cf.sign_anchor_path,
            "classes_path": sys.path[1] + cf.sign_class_name_path,
            "score": 0.9,
            "iou": 0.45,
            "model_image_size": (416, 416),
            "gpu_num": 1,
        }
        self.yolo = YOLO(FLAGS)

        return

    def signDetector(self, image):

        im_pil = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))

        out_boxes, out_scores, out_classes = self.yolo.detect_image(im_pil)

        has_sign = False
        box = None

        if len(out_boxes) > 0:
            rs = True

            # print('Found', len(out_boxes), 'boxes', out_boxes, out_scores, out_classes))

            c = np.argmax(out_scores)
            class_id = out_classes[c]
            predicted_class = self.yolo.class_names[class_id]
            top, left, bottom, right = out_boxes[c]
            score = out_scores[c]
            left = int(left)
            right = int(right)
            top = int(top)
            bottom = int(bottom)
            w = right - left
            h = bottom - top
            if w >= 40 and h >= 40:
                label = 'Sign {} - {} ({},{})'.format(predicted_class, score,
                                                      w, h)
                box = [
                    left + detect_sign_region['left'], top, w, h,
                    predicted_class, score, label
                ]
                cv2.rectangle(image, (left, top), (right, bottom), blue)

                return predicted_class, box

        return None, None

    def signRecognize(self):
        cf.k += 1
        # if cf.k >= 0 and cf.k % cf.sign_detect_step == 0:
        if True:
            # print('signRecognize', cf.k, cf.sign_detect_step, cf.signTrack)
            if cf.signTrack != -1 and abs(cf.signTrack - cf.k) >= 10:
                cf.sign = []
                cf.signTrack = -1
                print("clear")
                # cf.maxspeed = maxspeed

            img_detect_sign = cf.img_rgb_raw[
                detect_sign_region['top']:detect_sign_region['bottom'],
                detect_sign_region['left']:detect_sign_region['right']]

            cf.signSignal = None
            result, box = self.signDetector(img_detect_sign)
            if result != None:
                # cf.sign.append(result)
                # # cf.speed = 30
                # # cf.maxspeed = 30  # khi phat hien bien bao thi giam toc do
                # cf.signTrack = cf.k
                # print('Sign', cf.sign)
                # if self.acceptSign(result):
                if result:
                    if result == 'thang':
                        # print("THANG")
                        return "thang_certain", box
                    elif result == 'phai':
                        # print("PHAI")
                        return "phai_certain", box
                return result, box
        return None, None

    def acceptSign(self, value):
        if len(cf.sign) >= 2:
            for v in cf.sign:
                if v != value:
                    cf.sign = []
                    return False
            cf.sign = []
            cf.k = -100  # bo qua 100 frame tiep theo
            return True
        else:
            cf.k = cf.k - cf.sign_detect_step + 1  # xem xet 2 frame lien tiep
            return None
示例#25
0
                    help='num img 2 show',
                    default=1)
parser.add_argument('-r',
                    "--root",
                    type=str,
                    help='root dir filled with *.jpg',
                    default='VOCdevkit/VOC2007/JPEGImages')
parser.add_argument('-i', "--filename", type=str, help='filename', default='')

args = parser.parse_args()

yolo = YOLO(args.model_path, args.conf, args.cuda)

if args.num2show == 1:
    image = Image.open(os.path.join(args.root, args.filename))
    res, cls, score = yolo.detect_image(image)
    print(cls, score)
    # r_image.show()

else:
    print('结果将会保存到temp.png')
    files = os.listdir(args.root)
    idx = [
        int(len(os.listdir(args.root)) * random.random())
        for i in range(args.num2show)
    ]
    imgs = [Image.open(os.path.join(args.root, files[id])) for id in idx]
    ress, clss, scores = [], [], []
    print(len(imgs))
    for img in imgs:
        res, cls, score = yolo.detect_image(img)
def read_cam():
    # On versions of L4T previous to L4T 28.1, flip-method=2
    # Use the Jetson onboard camera
    yolo = YOLO()
    #cap = cv2.VideoCapture("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720,format=(string)I420, framerate=(fraction)30/1 ! nvvidconv flip-method=0 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink")
    cap = cv2.VideoCapture(0)
    if cap.isOpened():
        windowName = "CannyDemo"
        cv2.namedWindow(windowName, cv2.WINDOW_NORMAL)
        cv2.resizeWindow(windowName, 1280, 720)
        cv2.moveWindow(windowName, 0, 0)
        cv2.setWindowTitle(windowName, "Canny Edge Detection")
        showWindow = 3  # Show all stages
        showHelp = True
        font = cv2.FONT_HERSHEY_PLAIN
        helpText = "'Esc' to Quit, '1' for Camera Feed, '2' for Canny Detection, '3' for All Stages. '4' to hide help"
        edgeThreshold = 40
        showFullScreen = False
        while True:
            if cv2.getWindowProperty(
                    windowName,
                    0) < 0:  # Check to see if the user closed the window
                # This will fail if the user closed the window; Nasties get printed to the console
                break
            ret_val, frame = cap.read()
            cv2_im = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
            pil_im = Image.fromarray(cv2_im)
            pil_image, num_boxes = yolo.detect_image(pil_im)

            #if num_boxes > 0:
            #pil_image.save('detected_image_' + str(i) + '.jpg')

            open_cv_image = np.array(pil_image)
            # Convert RGB to BGR
            edges = open_cv_image[:, :, ::-1].copy()
            hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
            blur = cv2.GaussianBlur(hsv, (7, 7), 1.5)
            #edges=cv2.Canny(blur,0,edgeThreshold)

            if showWindow == 3:  # Need to show the 4 stages
                # Composite the 2x2 window
                # Feed from the camera is RGB, the others gray
                # To composite, convert gray images to color.
                # All images must be of the same type to display in a window
                """               
                frameRs=cv2.resize(frame, (640,360))
                hsvRs=cv2.resize(hsv,(640,360))
                vidBuf = np.concatenate((frameRs, cv2.cvtColor(hsvRs,cv2.COLOR_GRAY2BGR)), axis=1)
                blurRs=cv2.resize(blur,(640,360))
                edgesRs=cv2.resize(edges,(640,360))
                #vidBuf1 = np.concatenate( (cv2.cvtColor(blurRs,cv2.COLOR_GRAY2BGR),cv2.cvtColor(edgesRs,cv2.COLOR_GRAY2BGR)), axis=1)
                vidBuf1 = np.concatenate((cv2.cvtColor(blurRs,cv2.COLOR_GRAY2BGR),edgesRs), axis=1)
                vidBuf = np.concatenate( (vidBuf, vidBuf1), axis=0)
                """
                edgesRs = cv2.resize(edges, (640, 360))
                vidBuf = edgesRs

            if showWindow == 1:  # Show Camera Frame
                displayBuf = frame
            elif showWindow == 2:  # Show Canny Edge Detection
                displayBuf = edges
            elif showWindow == 3:  # Show All Stages
                displayBuf = vidBuf

            if showHelp == True:
                cv2.putText(displayBuf, helpText, (11, 20), font, 1.0,
                            (32, 32, 32), 4, cv2.LINE_AA)
                cv2.putText(displayBuf, helpText, (10, 20), font, 1.0,
                            (240, 240, 240), 1, cv2.LINE_AA)
            cv2.imshow(windowName, displayBuf)
            key = cv2.waitKey(10)
            if key == 27:  # Check for ESC key
                cv2.destroyAllWindows()
                break
            elif key == 49:  # 1 key, show frame
                cv2.setWindowTitle(windowName, "Camera Feed")
                showWindow = 1
            elif key == 50:  # 2 key, show Canny
                cv2.setWindowTitle(windowName, "Canny Edge Detection")
                showWindow = 2
            elif key == 51:  # 3 key, show Stages
                cv2.setWindowTitle(
                    windowName,
                    "Camera, Gray scale, Gaussian Blur, Canny Edge Detection")
                showWindow = 3
            elif key == 52:  # 4 key, toggle help
                showHelp = not showHelp
            elif key == 44:  # , lower canny edge threshold
                edgeThreshold = max(0, edgeThreshold - 1)
                print('Canny Edge Threshold Maximum: ', edgeThreshold)
            elif key == 46:  # , raise canny edge threshold
                edgeThreshold = edgeThreshold + 1
                print('Canny Edge Threshold Maximum: ', edgeThreshold)
            elif key == 74:  # Toggle fullscreen; This is the F3 key on this particular keyboard
                # Toggle full screen mode
                if showFullScreen == False:
                    cv2.setWindowProperty(windowName, cv2.WND_PROP_FULLSCREEN,
                                          cv2.WINDOW_FULLSCREEN)
                else:
                    cv2.setWindowProperty(windowName, cv2.WND_PROP_FULLSCREEN,
                                          cv2.WINDOW_NORMAL)
                showFullScreen = not showFullScreen
    else:
        print("camera open failed")
示例#27
0
def main(file_name, starting_value):

    yolo = YOLO()
    file_name = file_name
    starting_value = starting_value

    print("Starting in....")
    for i in list(range(5))[::-1]:
        print(i+1)
        time.sleep(1)

    training_data = []

    paused = False
    while(True):
        if not paused:

            image_array = grab_screen(region=(0, 30, 1280, 750))
            array_to_image = Image.fromarray(image_array, mode='RGB')
            r_image, left_top_x, left_top_y, right_bottom_x, right_bottom_y, predict_classes = yolo.detect_image(
                array_to_image)

            img = np.asarray(r_image)
            img = collision_detection(img, left_top_x, left_top_y, right_bottom_x, right_bottom_y, predict_classes)

            new_screen, original_image = process_img(img)

            screen = preprocess_screen(original_image)

            keys = key_check()
            output = keys_to_output(keys)
            training_data.append([screen, output])

            if cv2.waitKey(25) & 0xFF == ord('q'):
                cv2.destroyAllWindows()
                break

            if len(training_data) % 100 == 0:
                print(len(training_data))

                if len(training_data) == 500:
                    np.save(file_name, training_data)
                    print('SAVED')
                    training_data = []
                    starting_value += 1
                    file_name = 'F:/.../self-driving-in-GTA5/collect_data/training_data-{}.npy'.format(  # Change it to your path
                        starting_value)

        keys = key_check()
        if 'T' in keys:
            if paused:
                paused = False
                print('Unpaused!')
                time.sleep(1)
            else:
                print('Pausing!')
                paused = True
                time.sleep(1)
示例#28
0
class NebrusScreenDemo(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(NebrusScreenDemo, self).__init__(parent)

        #### Create Gui Elements ###########
        self.mainbox = QtGui.QWidget()
        self.screen_resolution = app.desktop().screenGeometry()
        kw = 0.4
        kh = 0.3

        #self.setFixedSize(screen_resolution.width(), int(screen_resolution.height() * 0.936)) # 0.636))
        self.setFixedSize(int(self.screen_resolution.width() * kh), int(self.screen_resolution.height() * kw))  # 0.636))
        self.setCentralWidget(self.mainbox)
        self.mainbox.setLayout(QtGui.QGridLayout())

        # QGridLayout#addWidget(): (QWidget * widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment = 0)

        # self.canvas = pg.GraphicsLayoutWidget()
        # self.mainbox.layout().addWidget(self.canvas, 0, 1, 1, 6) # last param = number of buttons + 1

        self.image_view = pg.ImageView()
        self.mainbox.layout().addWidget(self.image_view, 0, 0, 1, 1)

        self.image_width = int(self.screen_resolution.width() - self.screen_resolution.width() * kw)
        self.image_height = int(self.screen_resolution.height() - self.screen_resolution.height() * kh)

        # sct = mss()
        # # pdb.set_trace() ###
        # monitor = self.get_mss_monitor()
        # image = np.array(sct.grab(monitor))
        # image = np.flip(image[:, :, :3], 2)
        # image = np.rot90(image, axes=(-2, -1))
        # self.image_view.setImage(image, xvals=np.linspace(1., 3., image.shape[0]))

        # self.image_view.autoRange()

        # Grab frame
        self.frame_window = QtGui.QMainWindow()
        monitor = self.get_mss_monitor()
        self.frame_window.setFixedSize(monitor["width"], monitor["height"])
        self.frame_window.move(monitor["left"], monitor["top"])
        self.move(0, 0)
        self.frame_window.setWindowOpacity(0.5)
        self.frame_window.setAttribute(Qt.WA_NoSystemBackground, True)

        self.frame_window.show()

        self.sct = mss()
        print("Monitor: %s" % (str(self.get_mss_monitor())))
        self.yolo = YOLO(**vars(FLAGS))
        self.update()

    def detect_screen(self):
        sct = mss()
        # pdb.set_trace() ###
        monitor = {'top': int(self.screen_resolution.height() * 0.3), 'left': int(self.screen_resolution.width() * kw), 'width': int(self.screen_resolution.width() * self.screen_resolution.width() * kw), 'height': int(self.screen_resolution.height() * self.screen_resolution.height() * kh)}
        image = np.array(sct.grab(monitor))
        image = np.flip(image[:, :, :3], 2)
        frame = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        image = Image.fromarray(frame)
        image.show()

    def detect_img(self, yolo):
        while True:
            img = input('Input image filename:')
            try:
                image = Image.open(img)
            except:
                print('Open Error! Try again!')
                continue
            else:
                r_image = yolo.detect_image(image)
                r_image.show()
        yolo.close_session()

    def detect_video(self, yolo, video_path, output_path=""):
        import cv2
        vid = cv2.VideoCapture(video_path)
        if not vid.isOpened():
            raise IOError("Couldn't open webcam or video")
        video_FourCC = int(vid.get(cv2.CAP_PROP_FOURCC))
        video_fps = vid.get(cv2.CAP_PROP_FPS)
        video_size = (int(vid.get(cv2.CAP_PROP_FRAME_WIDTH)),
                      int(vid.get(cv2.CAP_PROP_FRAME_HEIGHT)))
        isOutput = True if output_path != "" else False
        if isOutput:
            print("!!! TYPE:", type(output_path), type(video_FourCC), type(video_fps), type(video_size))
            out = cv2.VideoWriter(output_path, video_FourCC, video_fps, video_size)
        accum_time = 0
        curr_fps = 0
        fps = "FPS: ??"
        prev_time = timer()
        while True:
            return_value, frame = vid.read()
            image = Image.fromarray(frame)
            image = yolo.detect_image(image)
            result = np.asarray(image)
            curr_time = timer()
            exec_time = curr_time - prev_time
            prev_time = curr_time
            accum_time = accum_time + exec_time
            curr_fps = curr_fps + 1
            if accum_time > 1:
                accum_time = accum_time - 1
                fps = "FPS: " + str(curr_fps)
                curr_fps = 0
            cv2.putText(result, text=fps, org=(3, 15), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
                        fontScale=0.50, color=(255, 0, 0), thickness=2)
            cv2.namedWindow("result", cv2.WINDOW_NORMAL)
            cv2.imshow("result", result)
            if isOutput:
                out.write(result)
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
        yolo.close_session()

    def get_mss_monitor(self):
        kw = 0.4
        kh = 0.3
        dpi = 1

        monitor = {'top': int(self.screen_resolution.height() * dpi * 0.3),
                   'left': int(self.screen_resolution.width() * dpi * kw),
                   'width': int(self.screen_resolution.width() * dpi - self.screen_resolution.width() * dpi * kw),
                   'height': int(self.screen_resolution.height() * dpi - self.screen_resolution.height() * dpi * kh)}

        return monitor

    def update(self):
        try:
            # pdb.set_trace() ###
            monitor = self.get_mss_monitor()

            image = np.array(self.sct.grab(monitor))

            #frame = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
            #image_ax = Image.fromarray(frame)

            #image = np.flip(image[:, :, :3], 2)
            #image = np.fliplr(image)
            #image = scipy.ndimage.rotate(image, 90)

            frame = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
            image_ax = Image.fromarray(frame)
#            image_ax = Image.fromarray(image)

            tf_image = self.yolo.detect_image(image_ax)

            tf_image = np.asarray(tf_image)
            tf_image = np.fliplr(tf_image)
            tf_image = scipy.ndimage.rotate(tf_image, 90)

            self.image_view.setImage(tf_image)

            # self.image_view.setImage(image)

            # self.image_view.autoRange()

            QtCore.QTimer.singleShot(50, self.update)
            # self.counter += 1
        except KeyboardInterrupt:
            print("Exiting gracefully...")
            # self.decode_thread.join()
            # self.filter_thread.join()
            # self.update_threaad.terminate()
            # self.multi_pulse_thread.terminate()
        except BaseException as e:
            print(e)
            print("update thread: %s" % (str(e)))
            raise e
            QtCore.QTimer.singleShot(1, self.update)

    def keyPressEvent(self, e):
        print(str(e.key()))
        if e.key() == Qt.Key_F5:
            self.close()
示例#29
0
#预测

from yolo import YOLO
from PIL import Image
import os
import cv2
import numpy as np
yolo = YOLO()

file_path = "img"
for file in os.listdir(file_path):
    filename = os.path.join(file_path, file)
    try:
        image = Image.open(filename)
    except:
        print('Open Error! Try again!')
        continue
    else:
        #获取图像和框位置
        r_image = yolo.detect_image(image)
        #输出预测的框
        #for value in r_image.values():
        #print(value)
        frame = np.array(r_image)
        frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
        cv2.imwrite("result/result_1/" + file, frame)
        #r_image.show()
        #r_image.close()

        #r_image.saveas(gcf,"img/")
示例#30
0
txt = "output/totalCount.txt"  # 将要输出保存的文件地址

if not os.path.exists('output/imageSeg'):
    os.makedirs('output/imageSeg')

for dir in diclass.keys():
    path_dir = 'output/imageSeg/' + dir
    if not os.path.exists(path_dir):
        os.makedirs(path_dir)

while (True):
    # 读取某一帧
    ref, frame = capture.read()

    # 进行检测
    frame, class_dict = yolo.detect_image(frame)

    with open(txt, "w") as f:
        for k in class_dict.keys():
            f.write(k + ': ' + str(class_dict[k]))  # 将字符串写入文件中
            f.write("\n")  # 换行

    videoWrite.write(frame)

    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    plt.figure(figsize=(10, 10))
    plt.imshow(frame)
    plt.axis('on')
    plt.show()

    c = cv2.waitKey(30) & 0xff