/
camera.py
35 lines (24 loc) · 901 Bytes
/
camera.py
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
31
32
33
34
import numpy as np
import cv2
from imutils.video.pivideostream import PiVideoStream
from jankimg.birdseye import *
class Camera(object):
def __init__(self, calib_img, resolution, framerate):
self.stream = PiVideoStream(resolution=resolution, framerate=framerate)
calib = undistort(cv2.imread(calib_img))
self.transform = birdseye_transform(calib)
def start(self):
self.stream.start()
def stop(self):
self.stream.stop()
def get_line(self):
frame = self.stream.read()
test = undistort(frame)
bird = birdseye(test, transform=self.transform)
u = u_channel(bird)
filtered = sobel(u)
thresh = threshold(filtered)
lines, line_coeff = detect_lines(thresh)
# print("line:", p)
# print("curvature: {}, slope: {}, offset: {}".format(*line_coeff))
return line_coeff