티스토리 뷰

간단한 자율주행 자동차를 만들기 위해 제작하였습니다.

 

목적: 어떤각도로 선을 따라가야 하는지 구하기 위함

제작년월: 2019년 9월 ~

공개일: 2019년 10월 23일

소프트웨어: Python 3.7.4

필요 모듈: Pillow, numpy

 

import PIL.Image as pilimg
import numpy as np
def scan(img1):
    one = pilimg.open(img1)
    pix = np.array(one)
    a = []
    for x in range(0, 854, 5):
        for y in range(0, 480, 5):
            if int(pix[y][x][0]) > 190 and int(pix[y][x][1]) < 130 and int(pix[y][x][2]) < 130 and not y == 480 and not x == 427:
                a.append((y - 480) / (x - 427))
    incli = (-1) * sum(a) / len(a)
    if incli < 0:
        result = 180 + abs(180 - (np.arctan2(incli, -1) * 180 / np.pi) * (-1))
    else:
        result = np.arctan2(incli, 1) * 180 / np.pi
    return abs(round(180 - result))

print(scan('a.bmp'))

convertdeg.zip
0.00MB

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함