# 基于树莓派与神经网络的智能小车

1

Demo视频

2

3

01. 预测赛道曲率：

02. 探测确定赛道中心：

from __future__ import division

import cv2

import numpy as np

# Input Image

# Convert to HSV color space

hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)

# Define range of white color in HSV

lower_white = np.array([0, 0, 212])

upper_white = np.array([131, 255, 255])

# Threshold the HSV image

# Remove noise

kernel_erode = np.ones((4,4), np.uint8)

kernel_dilate = np.ones((6,6),np.uint8)

# Find the different contours

im2, contours, hierarchy = cv2.findContours(dilated_mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

# Sort by area (keep only the biggest one)

contours = sorted(contours, key=cv2.contourArea, reverse=True)[:1]

if len(contours) > 0:

M = cv2.moments(contours[0])

# Centroid

cx = int(M['m10']/M['m00'])

cy = int(M['m01']/M['m00'])

print("Centroid of the biggest area: ({}, {})".format(cx, cy))

else:

print("No Centroid Found")

4

def preprocessImage(image, width, height):

"""

Preprocessing script to convert image into neural net input array

:param image: (cv2 RBG image)

:param width: (int)

:param height: (int)

:return: (numpy array)

"""

image = cv2.resize(image, (width, height), interpolation=cv2.INTER_LINEAR)

x = image.flatten() # create a big 1D-array

# Normalize

x = x / 255. # values in [0, 1]

x -= 0.5 # values in [-0.5, 0.5]

x *= 2 # values in [-1, 1]

return x

5

• 发表于:
• 原文链接：http://kuaibao.qq.com/s/20171220G0X7FD00?refer=cp_1026

2019-02-17

2019-02-17

2019-02-17

2019-02-17

2019-02-17

2019-02-17

2019-02-17