예제 #1
0
def gen_output(output_dir):

    YELLOW = (0, 255, 255)
    RED = (0, 0, 255)

    bname = splitext(basename(img_path))[0]

    I = cv2.imread(img_path)

    detected_cars_labels = '%s/%s_cars.txt' % (output_dir, bname)

    Lcar = lread(detected_cars_labels)

    if Lcar:

        for i, lcar in enumerate(Lcar):

            draw_label(I, lcar, color=YELLOW, thickness=3)

            lp_label = '%s/%s_%dcar_lp.txt' % (output_dir, bname, i)
            lp_label_str = '%s/%s_%dcar_lp_str.txt' % (output_dir, bname, i)

            C = cv2.imread('%s/%s_%dcar.png' % (output_dir, bname, i))

            if isfile(lp_label):
                Llp = lread(lp_label)
                for j, llp in enumerate(Llp):
                    draw_label(I,
                               llp,
                               color=RED,
                               thickness=3,
                               lp=True,
                               lcar=lcar,
                               C=C)
                    if isfile(lp_label_str):
                        with open(lp_label_str, 'r') as f:
                            lp_str = f.read().strip()
                        cwh = np.array(C.shape[1::-1]).astype(float)
                        iwh = np.array(I.shape[1::-1]).astype(float)
                        tl = tuple(
                            np.add((llp.tl() * cwh).tolist(),
                                   (lcar.tl() * iwh).tolist()) / iwh)
                        br = tuple(
                            np.add((llp.br() * cwh).tolist(),
                                   (lcar.tl() * iwh).tolist()) / iwh)
                        temp_label = Label(0, tl=tl, br=br)
                        write2img(I, temp_label, lp_str)

    return I
예제 #2
0
def generate_outputs(input_dir, output_dir):
    img_files = image_files_from_folder(input_dir)

    for img_file in img_files:

        bname = splitext(basename(img_file))[0]

        I = cv2.imread(img_file)

        detected_cars_labels = '%s/%s_cars.txt' % (output_dir, bname)

        Lcar = lread(detected_cars_labels)

        sys.stdout.write('%s' % bname)

        if Lcar:

            for i, lcar in enumerate(Lcar):

                draw_label(I, lcar, color=YELLOW, thickness=3)

                lp_label = '%s/%s_%dcar_lp.txt' % (output_dir, bname, i)
                lp_label_str = '%s/%s_%dcar_lp_str.txt' % (output_dir, bname, i)

                if isfile(lp_label):

                    Llp_shapes = readShapes(lp_label)
                    pts = Llp_shapes[0].pts * lcar.wh().reshape(2, 1) + lcar.tl().reshape(2, 1)
                    ptspx = pts * np.array(I.shape[1::-1], dtype=float).reshape(2, 1)
                    draw_losangle(I, ptspx, RED, 3)

                    if isfile(lp_label_str):
                        with open(lp_label_str, 'r') as f:
                            lp_str = f.read().strip()
                        llp = Label(0, tl=pts.min(1), br=pts.max(1))
                        write2img(I, llp, lp_str)

                        sys.stdout.write(',%s' % lp_str)

        cv2.imwrite('%s/%s_output.png' % (output_dir, bname), I)
예제 #3
0
def draw_car(img, Lcars, Tcars, Ccars, IDcars, Llps, lp_strs):
    print ('Performing outputting car ...')
    
    YELLOW = (  0,255,255)
    RED    = (  0,  0,255)  
    WHITE  = (255,255,255)

    I = img

    if Lcars:
        for i,(lcar, tcar, ccar, idcar) in enumerate(zip(Lcars, Tcars, Ccars, IDcars)):
            draw_label(I,lcar,color=YELLOW,thickness=3)
            if (ccar is not np.nan):
                car_cat = str(tcar.decode("utf-8")) + " " + ccar + " " + str(idcar)
            else:
                car_cat = str(tcar.decode("utf-8")) + " " + str(idcar)
            draw_text(I,lcar,car_cat,color=YELLOW,thickness=1)
   
            lp_label = Llps[i]
            lp_label_str = lp_strs[i]

            if (lp_label is not np.nan):
                pts = lp_label.pts*lcar.wh().reshape(2,1) + lcar.tl().reshape(2,1)
                ptspx = pts*np.array(I.shape[1::-1],dtype=float).reshape(2,1)
                draw_losangle(I,ptspx,RED,3)

                if (lp_label_str is not np.nan):
                    lp_str = lp_label_str.strip()
                    llp = Label(0,tl=pts.min(1),br=pts.max(1))
                    write2img(I,llp,lp_str)
                    sys.stdout.write('%s\n' % lp_str)
            else:
                if (lp_label_str is not np.nan):
                    lp_str = lp_label_str.strip()
                    draw_text2(I,lcar,lp_str,color=WHITE,thickness=3)
                    sys.stdout.write('%s\n' % lp_str)

    return I
예제 #4
0
                for i, r in enumerate(R):

                    cx, cy, w, h = (np.array(r[2]) / np.concatenate(
                        (WH, WH))).tolist()
                    tl = np.array([cx - w / 2., cy - h / 2.])
                    br = np.array([cx + w / 2., cy + h / 2.])
                    label = Label(0, tl, br)
                    print(label.wh())
                    print(label.tl())
                    Icar = crop_region(Iorig,
                                       label)  # 截取车辆区域 Icar 车辆 label 车辆坐标信息
                    Icar = Icar.astype('uint8')

                    Lcars.append(label)
                    draw_label(Iorig, label, color=YELLOW, thickness=3)

                    # lp detector
                    print('Searching for license plates using WPOD-NET')

                    ratio = float(max(Icar.shape[:2])) / min(Icar.shape[:2])
                    side = int(ratio * 288.)
                    bound_dim = min(side + (side % (2**4)), 608)
                    print("\t\tBound dim: %d, ratio: %f" % (bound_dim, ratio))

                    Llp, LlpImgs, elapse = detect_lp(wpod_net, im2single(Icar),
                                                     bound_dim, 2**4,
                                                     (240, 80), lp_threshold)
                    print('\tld detection used %d s time' % elapse)

                    if len(LlpImgs):
예제 #5
0
    bname = splitext(basename(img_file))[0]

    I = cv2.imread(img_file)

    detected_cars_labels = '%s/%s_cars.txt' % (output_dir, bname)

    Lcar = lread(detected_cars_labels)

    sys.stdout.write('%s' % bname)

    if Lcar:

        for i, lcar in enumerate(Lcar):

            draw_label(I, lcar, color=YELLOW, thickness=3)

            lp_label = '%s/%s_%dcar_lp.txt' % (output_dir, bname, i)
            lp_label_str = '%s/%s_%dcar_lp_str.txt' % (output_dir, bname, i)

            imgs_path = glob('%s/%s_%dcar.png' % (input_dir, bname, i))

            C = cv2.imread('%s/%s_%dcar.png' % (output_dir, bname, i))

            if isfile(lp_label):
                Llp = lread(lp_label)
                for j, llp in enumerate(Llp):
                    draw_label(I,
                               llp,
                               color=RED,
                               thickness=3,
예제 #6
0
        bname = splitext(basename(img_file))[0]

        I = cv2.imread(img_file)

        detected_cars_labels = '%s/%s_cars.txt' % (output_dir, bname)

        Lcar = lread(detected_cars_labels)

        track_file.write(str(f_count))

        if Lcar:

            for i, lcar in enumerate(Lcar):

                draw_label(I, lcar, color=GREEN, thickness=3)

                lp_label = '%s/%s_%dcar_lp.txt' % (output_dir, bname, i)
                lp_label_str = '%s/%s_%dcar_lp_str.txt' % (output_dir, bname,
                                                           i)

                if isfile(lp_label):

                    Llp_shapes = readShapes(lp_label)
                    pts = Llp_shapes[0].pts * lcar.wh().reshape(
                        2, 1) + lcar.tl().reshape(2, 1)
                    ptspx = pts * np.array(I.shape[1::-1],
                                           dtype=float).reshape(2, 1)
                    draw_losangle(I, ptspx, RED, 3)

                    if isfile(lp_label_str):