Пример #1
0
def map_time_step(img_path,
                  rpm=19.6,
                  field=14,
                  diameter=70,
                  suffix=".bmp",
                  save_path=None):

    img_list = sorted(gb.glob(img_path + r"/*" + suffix), key=os.path.getmtime)
    pvoc = PascalVocXmlParser()

    # Get the linear velocity of the rotating cloth
    perimeter = np.pi * diameter
    min_velo = rpm * perimeter
    speed = min_velo / 60.0

    for i in range(1, len(img_list), 1):
        img_file = img_list[i]
        print(img_file)
        ann_file = get_ann_file(img_file)
        if os.path.isfile(ann_file):
            boxes = pvoc.get_boxes(ann_file)
        else:
            boxes = []

        pre_img_file = img_list[i - 1]
        pre_ann_file = get_ann_file(pre_img_file)
        if os.path.isfile(pre_ann_file):
            pre_boxes = pvoc.get_boxes(pre_ann_file)
        else:
            pre_boxes = []

        img = cv2.imread(img_file, cv2.IMREAD_COLOR)
        img_h, img_w = img.shape[:2]
        intv = get_time_interval(img_file, pre_img_file)
        nboxes = map_next_boxes(pre_boxes, speed, intv, field, (img_h, img_w))

        #print(boxes)
        #print(nboxes)
        img = draw_boxes(img, boxes, color=(0, 0, 255))
        img = draw_boxes(img, nboxes, color=(255, 0, 0))

        if save_path is not None:
            _, filename = os.path.split(img_file)
            cv2.imwrite(os.path.join(save_path, filename), img)
        else:
            cv2.imshow("image", img)
            cv2.waitKey(0)
Пример #2
0
import os, sys
import numpy as np
import glob as gb
import xml.etree.ElementTree as ET
from sklearn.cluster import KMeans
from matplotlib import pyplot as plt
from PascalVocParser import PascalVocXmlParser

pvoc = PascalVocXmlParser()


def show_histogram(path):
    dataset = encode_dataset(path)
    widths = dataset[:, 0]
    heights = dataset[:, 1]
    plt.subplot(1, 2, 1), plt.hist(widths), plt.title("Width Distribution")
    plt.subplot(1, 2, 2), plt.hist(heights), plt.title("Heights Distribution")
    plt.show()


def cluster_anchors(path, k=6, label=None):
    dataset = encode_dataset(path, label=label)
    km = KMeans(n_clusters=k, random_state=9).fit(dataset)
    ac = np.array(km.cluster_centers_, dtype=np.int32)

    return ac


def encode_dataset(path, label=None):
    dataset = []  # dataset that x_length larger than x_thres
    for xml_file in gb.glob(path + r"/*.xml"):
Пример #3
0
 def __init__(self, params):
     self.pvoc = PascalVocXmlParser()
     self.updateParams(params)