This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
img = cv2.imread("car.png") | |
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
ret, gray = cv2.threshold(gray, 250,255,0) | |
# applying different thresholding techniques on the input image | |
# all pixels value above 120 will be set to 255 | |
ret, thresh2 = cv2.threshold(img, 120, 255, cv2.THRESH_BINARY_INV) | |
gray = cv2.cvtColor(thresh2, cv2.COLOR_BGR2GRAY) | |
contours, _ = cv2.findContours(gray, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Detections contains bounding boxes using object detection model | |
boxcount = 0 | |
depths = [] | |
bboxMidXs = [] | |
bboxMidYs = [] | |
# This is computed to reflect real distance during initial camera calibration | |
scalingFactor = 1000 | |
# Depth scaling factor is based on one-time cam calibration | |
for detection in detections: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sensor Fusion happens at Node 2 | |
def on_message(client, userdata, msg): | |
word = msg.payload.decode() | |
# objAttributes contains label, | |
# theta min and max separated by | | |
objAttributes = word.split('|') | |
now = time.localtime() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code builds the shape context descriptor, which is the core of our alphanumeral comparison | |
# https://github.com/AdroitAnandAI/Multilingual-Text-Inversion-Detection-of-Scanned-Images | |
# points represents the edge shape | |
t_points = len(points) | |
# getting euclidian distance | |
r_array = cdist(points, points) | |
# for rotation invariant feature | |
am = r_array.argmax() | |
max_points = [am / t_points, am % t_points] | |
# normalizing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# loop over the set of tracked points | |
for i in range(1, len(pts)): | |
# if either of the tracked points are None, ignore them | |
if pts[i - 1] is None or pts[i] is None: | |
continue | |
# otherwise, compute the thickness of the line and draw the connecting lines | |
thickness = int(np.sqrt(args["buffer"] / float(i + 1)) * 2.5) | |
cv2.line(frame, pts[i - 1], pts[i], (0, 0, 255), thickness) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for detection in detections: | |
if detection.score > threshold: | |
class_id = int(detection.id)-1 | |
# Potential Objects: person, bicycle, car, bus, | |
# truck, traffic light, street sign, stop sign | |
if class_id not in [0, 1, 2, 3, 5, 7, 9, 11, 12]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getObjectDistance (angle_min, angle_max): | |
minDist = 0 | |
lidar = RPLidar(None, PORT_NAME) | |
try: | |
for scan in lidar_scans(lidar): | |
for (_, angle, distance) in scan: | |
scan_data[min([359, floor(angle)])] = distance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code to fit the inverse sigmoid curve to tail end of signal | |
def sigmoid(x, L ,x0, k, b): | |
y = L / (1 + np.exp(k*(x-x0)))+b | |
return (y) | |
def isCurveSigmoid(pixelCounts, count): | |
try: | |
xIndex = len(pixelCounts) | |
p0 = [max(pixelCounts), np.median(xIndex),1,min(pixelCounts)] # this is an mandatory initial guess | |
popt, pcov = curve_fit(sigmoid, list(range(xIndex)), pixelCounts, p0, method='lm', maxfev=5000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# At the MQTT Transmission side | |
data2Transmit = np.array([x, y, theta]) | |
# Map which is saved as a bytearray is appended at the end | |
if scan_count % 30 == 0: | |
client.publish("safetycam/topic/slamviz", \\ | |
data2Transmit.tobytes() + mapbytes) | |
# At the MQTT receiving side |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Optimized implementation of Graph SLAM. | |
## slam takes in 6 arguments and returns mu, | |
## mu is the entire path traversed by a robot (all x,y poses) *and* all landmarks locations | |
def slam(data, N, num_landmarks, world_size, motion_noise, measurement_noise): | |
coefficients = [1, -1, -1, 1] | |
# initialize the constraints | |
initial_omega_1, initial_xi_1, initial_omega_2, initial_xi_2 = \\ |
NewerOlder