示例#1
0
def main():
    cap = None

    def get():
        return cv2.imdecode(np.asarray(bytearray(requests.get(url, stream=True).raw.read()), dtype="uint8"),
                            cv2.IMREAD_COLOR)

    try:  # Try to access remote camera.
        frame = get()
    except requests.exceptions.ConnectionError:  # Fallback to local camera instead.
        cap = cv2.VideoCapture(0)
        cap.set(cv2.CAP_PROP_BUFFERSIZE, 0)

        def get():
            return cap.read()[1]

        frame = get()

    ht = Lines(frame.shape[:2])

    while True:
        frame = get()

        trans = ht.transform(frame)

        cv2.imshow('Hmmm', trans)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    if cap:
        cap.release()

    cv2.destroyAllWindows()
示例#2
0
 def update_rays(self, x):
     self.rayCan.delete(self.id)
     self.lines.remove_lines()
     self.remove_bricks
     self.amount = x
     self.lines = Lines(self.amount, self.rayCan, self.walls, self.x,
                        self.y, self.rot)
     self.DrawCircle()
示例#3
0
 def rotate_right(self):
     self.rot += 2
     if self.rot > 180: self.rot = -180
     self.lines.remove_lines()
     self.lines = Lines(self.amount, self.rayCan, self.walls, self.x,
                        self.y, self.rot)
     self.lines.draw_lines(self.x, self.y)
     self.redraw_borders()
示例#4
0
 def rotate_left(self):
     self.rot -= 2
     if self.rot < -180: self.rot = 180
     self.lines.remove_lines()
     self.lines = Lines(self.amount, self.rayCan, self.walls, self.x,
                        self.y, self.rot)
     self.lines.draw_lines(self.x, self.y)
     self.redraw_borders()
示例#5
0
    def __init__(self, x, y, C, C2, W, walls):
        super().__init__()

        self.win = W
        self.rayCan = C
        self.wallCan = C2
        self.id = None
        self.x = x
        self.y = y
        self.r = 10  #radius of circle
        self.amount = 720  #default angle of rays
        self.walls = walls

        self.bricks = []
        self.distances = []

        self.rot = 0  #starting angle for FOV

        self.lines = Lines(self.amount, self.rayCan, self.walls, x, y,
                           self.rot)

        self.DrawCircle()
示例#6
0
def cve2lines(cvedirn, station_conv, llfn):

    railstation_fn = os.path.join(cvedirn, 'railstation_master.txt')

    # railstation -> 路線 - 駅名リスト
    # {(cve路線ID, cve路線名): ジョルダン駅名, ...}
    railstation_data = mk_railstation_data(railstation_fn, station_conv)

    # Lines instance
    lines = Lines()
    for lineID, linename, *stations_j in railstation_data:
        chk = lines.add_line(lineID, linename, stations_j)
        if type(chk) is int and chk < 0:
            print('railstation err: {0}: {1} {2}'.format(
                chk, lineID, linename))
            sys.exit()

    # 路線リスト
    lines_list = lines.line_list()
    with open(llfn, 'w', encoding='utf-8') as f:
        f.write(''.join(['\t'.join(l) + '\n' for l in lines_list]))

    return lines
示例#7
0
def createLines():
    for b in bs:
        l = Lines(b)
        lines.append(l)
示例#8
0
def scan(main_color, intermediates=None):
    main_gray = utility.shrink_img(main_color)  # 処理速度を上げるため縮小する
    main_gray = cv2.cvtColor(main_gray, cv2.COLOR_BGR2GRAY)
    size_color = main_color.shape[:2]
    size_gray = main_gray.shape

    length_threshold = 20
    distance_threshold = 1.4142
    # canny_th1 = 5.0
    # canny_th2 = 50.0
    canny_th1 = 1.0
    canny_th2 = 10
    canny_size = 3
    do_merge = False
    do_merge = False
    fld = cv2.ximgproc.createFastLineDetector(length_threshold,
                                              distance_threshold, canny_th1,
                                              canny_th2, canny_size, do_merge)
    line_pnts = fld.detect(main_gray)
    line_pnts = np.array(line_pnts).reshape((-1, 4))
    lines = Lines(line_pnts)
    print(f"Num of lines: {lines.num} => ", end="")
    lines.remove_central(size_gray)
    print(lines.num)

    equal = lines.equal()
    labels = partition.partition(lines.num, equal)
    labels_num = len(np.unique(labels))
    if intermediates is not None:
        intermediates['lines'] = utility.draw_lines(main_gray, lines, labels,
                                                    labels_num)
        cv2.imwrite("lines.jpeg", intermediates['lines'])

    segments = Segments(lines, labels, labels_num, size_gray)
    print(f"Num of segments: {segments.num} => ", end="")
    segments.remove_central(size_gray)
    print(segments.num)
    if intermediates is not None:
        intermediates['segments'] = utility.draw_segments(main_gray, segments)
        cv2.imwrite("segments.jpeg", intermediates['segments'])

    intersections = Intersections(segments, size_gray)
    print(f"Num of intersections: {intersections.num}")
    if intermediates is not None:
        intermediates['intersections'] = utility.draw_intersections(
            main_gray, intersections)
        cv2.imwrite("intersections.jpeg", intermediates['intersections'])

    df = ml_model.prepare_data(intersections, size_gray)
    scores = ml_model.get_score(df)
    indice = np.argsort(scores)[::-1]

    points_per_section = 3
    vertex_lt = []
    vertex_rt = []
    vertex_lb = []
    vertex_rb = []
    for idx in indice:
        if intersections.is_left[idx] and intersections.is_top[idx] and len(
                vertex_lt) < points_per_section:
            vertex_lt.append(idx)
        elif intersections.is_right[idx] and intersections.is_top[idx] and len(
                vertex_rt) < points_per_section:
            vertex_rt.append(idx)
        elif intersections.is_left[idx] and intersections.is_bottom[
                idx] and len(vertex_lb) < points_per_section:
            vertex_lb.append(idx)
        elif intersections.is_right[idx] and intersections.is_bottom[
                idx] and len(vertex_rb) < points_per_section:
            vertex_rb.append(idx)

        if len(vertex_lt) >= points_per_section and \
            len(vertex_rt) >= points_per_section and \
            len(vertex_lb) >= points_per_section and \
            len(vertex_rb) >= points_per_section:
            break

    if len(vertex_lt) == 0:
        print("no vertex at left top was found")
        return None
    if len(vertex_rt) == 0:
        print("no vertex at right top was found")
        return None
    if len(vertex_lb) == 0:
        print("no vertex at left bottom was found")
        return None
    if len(vertex_rb) == 0:
        print("no vertex at right bottom was found")
        return None

    idx_lt, idx_rt, idx_lb, idx_rb = utility.get_best_set(
        intersections, scores, vertex_lt, vertex_rt, vertex_lb, vertex_rb)

    # print(f"selected vertexes: ({idx_lt}, {idx_rt}, {idx_lb}, {idx_rb})")
    if intermediates is not None:
        intermediates['detected'] = utility.draw_detected(
            main_gray, intersections, idx_lt, idx_rt, idx_lb, idx_rb)

    src_points_gray = np.array([ \
        intersections.cross_pnt[idx_lt], \
        intersections.cross_pnt[idx_rt], \
        intersections.cross_pnt[idx_lb], \
        intersections.cross_pnt[idx_rb]
    ], dtype=np.float32)
    dst_points_gray = np.array([ \
        (0, 0),
        (size_gray[1], 0),
        (0, size_gray[0]),
        (size_gray[1], size_gray[0])
    ], dtype=np.float32)
    scale = np.array(size_color, dtype=np.float32) / np.array(size_gray,
                                                              dtype=np.float32)
    scale = scale[::-1]
    src_points_color = src_points_gray * scale
    dst_points_color = dst_points_gray * scale

    M_color = cv2.getPerspectiveTransform(src_points_color, dst_points_color)
    main_color = cv2.warpPerspective(main_color, M_color, size_color[::-1])
    return main_color
示例#9
0
import pygame
from random import randrange as rd
from lines import Lines


if __name__ == '__main__':
    SZ = 600
    FPS = 60

    pygame.init()
    win = pygame.display.set_mode((SZ, SZ))

    lines = Lines(SZ // 50, SZ // 50, 50, win)
    clock = pygame.time.Clock()

    while True:
        lines.show()
        for i in pygame.event.get():
            if i.type == pygame.QUIT:
                exit()
            if i.type == pygame.MOUSEBUTTONDOWN:
                x, y = pygame.mouse.get_pos()
                lines.click()
        clock.tick(FPS)

示例#10
0
# -*- coding: utf-8 -*-

# Copyright (C) 2013 Sylvain Boily <*****@*****.**>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from flask import Blueprint
from lines import Lines
import wtforms_json

bp_lines = Blueprint('lines', __name__, template_folder='templates/lines')

lines = Lines()
wtforms_json.init()
示例#11
0
文件: main.py 项目: ninest/mrt
import requests
from bs4 import BeautifulSoup
import json

from global_vars import LINES
from lines import Lines
from stations import Stations

data = []

for line in LINES:
    response = requests.get(
        f'https://api.openstreetmap.org/api/0.6/relation/{line["code"]}/full')
    if response.status_code == 200:

        soup = BeautifulSoup(response.content, "xml")
        print('got soup!')

        points = Lines(soup, line['color'], line['ref'])
        stations = Stations(soup)

        data.append({**points.return_points(), **stations.return_stations()})

# create file if not exists
f = open('src/data/lines.json', 'w')
with open('src/data/lines.json', 'w') as outfile:
    json.dump(data, outfile)

print('Output')
示例#12
0
 def __init__(self, name, x, y, color_name, map):
     self.name = name
     self.car = Car(x, y, COLORS[color_name], map)
     self.lines = Lines(COLORS[color_name])