-
Notifications
You must be signed in to change notification settings - Fork 0
Added filter to points in Lines, adapted algorithms according to changes, standardized outputs to return frame and angle #6
Changes from 8 commits
dac3a13
6230403
5d89070
5ba6995
ddad21c
91207b7
6856d13
2a2f148
9bbe1e9
1c8ea44
789ca8e
0dcd6c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import operator | ||
import sys | ||
import math | ||
from algorithms.utils import Lines | ||
|
||
class MiniContoursAlgorithm: | ||
# applies hsv binarization to the image | ||
|
@@ -13,6 +14,8 @@ class MiniContoursAlgorithm: | |
def __init__(self, config): | ||
|
||
self.config = config | ||
self.WIDTH = config.frame_width | ||
self.HEIGHT = config.frame_length | ||
# smoothing kernel | ||
self.kernel = np.ones((5,5),np.float32)/25 | ||
self.morphologyKernel = np.ones((9,9),np.float32) | ||
|
@@ -79,7 +82,7 @@ def getCentroids(self, mask, num_strips): | |
return centroids | ||
|
||
|
||
def getCenterHoughLines(self, frame, num_strips=60, lines_max=30, threshold=4, min_rho=0, max_rho=1000, rho_step=1, min_theta=-math.pi/4, max_theta=math.pi/4, theta_step=math.pi/180): | ||
def getCenterHoughLines(self, frame, num_strips=60, lines_max=30, threshold=4, min_rho=0, max_rho=1000, rho_step=1, min_theta=-math.pi/4, max_theta=math.pi/4, theta_step=math.pi/180, show=False): | ||
# frame: BGR frame | ||
# num_strips: number of strips for centroid calculation | ||
# other parameters for HoughLinesPointSet | ||
|
@@ -187,12 +190,12 @@ def getCenterHoughLines(self, frame, num_strips=60, lines_max=30, threshold=4, m | |
cv2.line(frame, pt1, pt2, (0,0,255), 6, cv2.LINE_AA) | ||
|
||
|
||
cv2.imshow('frame', frame) | ||
cv2.imshow('mask', mask) | ||
cv2.imshow('c_mask', c_mask) | ||
cv2.imshow('points', points) | ||
# cv2.waitKey(1) | ||
|
||
if show: | ||
cv2.imshow('frame', frame) | ||
cv2.imshow('mask', mask) | ||
cv2.imshow('c_mask', c_mask) | ||
cv2.imshow('points', points) | ||
cv2.waitKey(1) | ||
Comment on lines
+193
to
+198
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See if we can remove unnecassary frame processes for algorithms |
||
|
||
return frame, lines, point_lines | ||
|
||
|
@@ -213,8 +216,14 @@ def processFrame(self, originalframe, num_strips=60, show=False): | |
max_theta=self.max_theta, | ||
theta_step=self.theta_step) | ||
|
||
# cv2.imshow('frame', frame) | ||
intersections = Lines.getIntersections(lines) | ||
xPoints = [point[0] for point in intersections] | ||
yPoints = [point[1] for point in intersections] | ||
vPoint = Lines.drawVanishingPoint(frame, xPoints, yPoints) | ||
|
||
return frame, point_lines | ||
|
||
|
||
# Calculating angle from vanishing point to (self.WIDTH // 2, 0) | ||
deltaWVanishPoint = vPoint[0] - (self.WIDTH // 2) | ||
deltaHVanishPoint = vPoint[1] | ||
angle = round(math.degrees(math.atan(deltaWVanishPoint/deltaHVanishPoint)), 2) | ||
|
||
return frame, angle |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import sys | ||
|
||
import numpy | ||
from cv2 import cv2 | ||
import cv2 as cv2 | ||
import numpy as np | ||
|
||
""" | ||
|
@@ -53,7 +53,8 @@ def getIntersections(lines, min_slope=1): | |
points: [x] | ||
""" | ||
intersections = [] | ||
points = [] | ||
# xPoints = [] | ||
# yPoints = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete? |
||
lines_left = [] | ||
lines_right = [] | ||
|
||
|
@@ -97,9 +98,11 @@ def getIntersections(lines, min_slope=1): | |
# the intersections array is an array of points coordinates (x, y) | ||
# the points array is an array of the x coordinates of the points | ||
intersections.append(intersect) | ||
points.append(intersect[0]) | ||
# xPoints.append(intersect[0]) | ||
# yPoints.append(intersect[1]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
|
||
return intersections, points | ||
# return intersections, xPoints, yPoints | ||
return intersections | ||
|
||
|
||
def assignCoordinateValues(line): | ||
|
@@ -185,20 +188,37 @@ def drawLinesOnFrame(lines, frame): | |
return frame | ||
|
||
|
||
def drawVanishingPoint(frame, points, use_median=True): | ||
def filterPoints(numArray): | ||
low = np.percentile(numArray, 20) | ||
high = np.percentile(numArray, 80) | ||
filtered = [] | ||
|
||
for num in numArray: | ||
if num >= low and num <= high: | ||
filtered.append(num) | ||
|
||
return filtered | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. documentation |
||
|
||
def drawVanishingPoint(frame, xPoints, yPoints, use_median=True): | ||
""" | ||
Function that draws the vanishing point onto a frame | ||
:param frame: the frame on which the point needs to be drawn | ||
:param points: a list of x co-ordinates from which the vanishing point will be calculated | ||
:param use_median: whether to use the mean or median intersection point, defaulting to True | ||
:return: (x, y), where x is the median/mean intersection point and y is a constant value | ||
""" | ||
if len(points) != 0: | ||
|
||
filteredX = filterPoints(xPoints) | ||
filteredY = filterPoints(yPoints) | ||
|
||
if len(filteredX) != 0: | ||
if use_median: | ||
IntersectingX = np.median(points) | ||
IntersectingX = np.median(filteredX) | ||
IntersectingY = np.median(filteredY) | ||
else: | ||
IntersectingX = np.mean(points) | ||
IntersectingX = np.mean(filteredX) | ||
IntersectingY = np.mean(filteredY) | ||
|
||
cv2.circle(frame, (int(IntersectingX), int(frame.shape[1] / 2)), 8, (255, 0, 0), -1) | ||
cv2.circle(frame, (int(IntersectingX), int(IntersectingY)), 8, (255, 0, 0), -1) | ||
|
||
return (int(IntersectingX), int(frame.shape[1] / 2)) | ||
return (int(IntersectingX), int(IntersectingY)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update documentation for this change and any other methods that are changed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python variable conventions, here and everywhere else.