道路車道檢測系統(tǒng):
自動駕駛汽車是現(xiàn)代世界的新趨勢之一。他們使用非常復(fù)雜的控制系統(tǒng)和工程技術(shù)來操縱車輛。道路車道檢測是車輛導(dǎo)航中的重要內(nèi)容之一。在這里,我描述了一個使用 Raspberry pi 3 和計算機(jī)視覺技術(shù)的簡單快速的車道檢測。為了快速計算,我只是避免使用線性回歸方法。這種方法在低噪聲環(huán)境下效果很好,但對于復(fù)雜的場景,需要先進(jìn)的統(tǒng)計和圖像處理技術(shù)。
硬件設(shè)置:
將相機(jī)與您的 Pi 連接
![pYYBAGJFFK6AZgaxAAIqyqFmCEc342.png](http://file.elecfans.com/web2/M00/3A/A6/pYYBAGJFFK6AZgaxAAIqyqFmCEc342.png)
攝像頭配置:
按照此鏈接進(jìn)行相機(jī)設(shè)置https://www.raspberrypi.org/documentation/configuration/camera.md
軟件設(shè)置:
為 python 安裝 OpenCV。按照這些說明安裝 OpenCV。這些說明是從https://raspberrypi.stackexchange.com復(fù)制的。
通用:
sudo apt-get update
sudo apt-get upgrade
sudo rpi-update
sudo reboot
sudo apt-get install build-essential git cmake pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libatlas-base-dev gfortran
cd ~
git clone
cd opencv
git checkout 3.1.0
cd ~
git clone
cd opencv_contrib
git checkout 3.1.0
如果您想將 OpenCV 與 python 2.7 一起使用:
sudo apt-get install python2.7-dev
wget
sudo python
pip install numpy
cd ~/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
make -j4
sudo make install
sudo ldconfig
如果您想在 Python 3 中使用 OpenCV:
sudo apt-get install python3-dev
wget
sudo python3
pip install numpy
cd ~/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
make -j4
sudo make install
sudo ldconfig
將以上配置完成大約需要 2 個小時。在此期間,我們可以了解一下 Hough-Transform,這項技術(shù)是大多數(shù)實用車道檢測算法背后的關(guān)鍵。
Python代碼:
from picamera.array import PiRGBArray
import RPi.GPIO as GPIO
from picamera import PiCamera
import time
import cv2
import numpy as np
import math
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
GPIO.setup(8, GPIO.OUT)
theta=0
minLineLength = 5
maxLineGap = 10
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 30
rawCapture = PiRGBArray(camera, size=(640, 480))
time.sleep(0.1)
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
image = frame.array
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
edged = cv2.Canny(blurred, 85, 85)
lines = cv2.HoughLinesP(edged,1,np.pi/180,10,minLineLength,maxLineGap)
if(lines !=None):
for x in range(0, len(lines)):
for x1,y1,x2,y2 in lines[x]:
cv2.line(image,(x1,y1),(x2,y2),(0,255,0),2)
theta=theta+math.atan2((y2-y1),(x2-x1))
#print(theta)GPIO pins were connected to arduino for servo steering control
threshold=6
if(theta>threshold):
GPIO.output(7,True)
GPIO.output(8,False)
print("left")
if(theta<-threshold):
GPIO.output(8,True)
GPIO.output(7,False)
print("right")
if(abs(theta) GPIO.output(8,False)
GPIO.output(7,False)
print "straight"
theta=0
cv2.imshow("Frame",image)
key = cv2.waitKey(1) & 0xFF
rawCapture.truncate(0)
if key == ord("q"):
break):
示例輸出結(jié)果:
![poYBAGJFFLaAXmKnAALa_TuPj7M511.png](http://file.elecfans.com/web2/M00/3A/A1/poYBAGJFFLaAXmKnAALa_TuPj7M511.png)
![poYBAGJFFLyAJXS9AALQwXurhb8734.png](http://file.elecfans.com/web2/M00/3A/A1/poYBAGJFFLyAJXS9AALQwXurhb8734.png)
![poYBAGJFFMOAD4NpAAKGtHhLwCA958.png](http://file.elecfans.com/web2/M00/3A/A1/poYBAGJFFMOAD4NpAAKGtHhLwCA958.png)
![pYYBAGJFFMmAS10bAASw9v_kubM454.png](http://file.elecfans.com/web2/M00/3A/A6/pYYBAGJFFMmAS10bAASw9v_kubM454.png)
GPIO 引腳連接到 Arduino mega 用于伺服電機(jī)控制。
#include
Servo myservo;
void setup() {
myservo.attach(10);//attach servo motor PWM(orange) wire to pin 10
pinMode(0, INPUT);//attach GPIO 7&8 pins to arduino pin 0&1
pinMode(1,INPUT);
void loop() {
if(digitalRead(0)==HIGH && digitalRead(1)==LOW)
{
myservo.write(118);
}
if(digitalRead(1)==HIGH && digitalRead(0)==LOW)
{
myservo.write(62);
}
if(digitalRead(1)==LOW && digitalRead(0)==LOW)
{
myservo.write(90);
}
}
-
自動駕駛汽車
+關(guān)注
關(guān)注
4文章
377瀏覽量
40903 -
樹莓派
+關(guān)注
關(guān)注
117文章
1710瀏覽量
105898
發(fā)布評論請先 登錄
相關(guān)推薦
基于樹莓派設(shè)計的RFID門禁系統(tǒng)
![基于<b class='flag-5'>樹莓</b><b class='flag-5'>派</b>設(shè)計的RFID門禁<b class='flag-5'>系統(tǒng)</b>](https://file.elecfans.com//web2/M00/3A/F4/pYYBAGJGoMaAGNefAAJdY33PvLk222.png)
樹莓派防占位系統(tǒng)
樹莓派設(shè)置基本流程(上)
樹莓派的種類_樹莓派安裝教程
樹莓派3wifi配置_樹莓派3開啟wifi熱點_樹莓派3的wifi使用教程
樹莓派3硬件配置_樹莓派3都能裝什么系統(tǒng)_樹莓派3系統(tǒng)安裝教程
樹莓派3系統(tǒng)安裝介紹_Noobs進(jìn)行樹莓派3系統(tǒng)安裝_Noobs進(jìn)行樹莓派3系統(tǒng)恢復(fù)
![<b class='flag-5'>樹莓</b><b class='flag-5'>派</b>3<b class='flag-5'>系統(tǒng)</b>安裝介紹_Noobs進(jìn)行<b class='flag-5'>樹莓</b><b class='flag-5'>派</b>3<b class='flag-5'>系統(tǒng)</b>安裝_Noobs進(jìn)行<b class='flag-5'>樹莓</b><b class='flag-5'>派</b>3<b class='flag-5'>系統(tǒng)</b>恢復(fù)](https://file1.elecfans.com//web2/M00/A7/0D/wKgZomUMQhCALR-vAAAUAVBLw8w729.jpg)
樹莓派3系統(tǒng)配置詳解_樹莓派3如何配置config.txt文件_樹莓派3如何設(shè)置分辨率
![<b class='flag-5'>樹莓</b><b class='flag-5'>派</b>3<b class='flag-5'>系統(tǒng)</b>配置詳解_<b class='flag-5'>樹莓</b><b class='flag-5'>派</b>3如何配置config.txt文件_<b class='flag-5'>樹莓</b><b class='flag-5'>派</b>3如何設(shè)置分辨率](https://file1.elecfans.com//web2/M00/A7/0D/wKgZomUMQhGACeB6AAAEvs90sZ0443.jpg)
樹莓派入門教程之新手使用樹莓派做系統(tǒng)的教程資料說明
![<b class='flag-5'>樹莓</b><b class='flag-5'>派</b>入門教程之新手使用<b class='flag-5'>樹莓</b><b class='flag-5'>派</b>做<b class='flag-5'>系統(tǒng)</b>的教程資料說明](https://file.elecfans.com/web1/M00/8B/3B/o4YBAFyUVumAVeycAAU67uK9YyU849.png)
樹莓派是什么樹莓派的簡單介紹
![<b class='flag-5'>樹莓</b><b class='flag-5'>派</b>是什么<b class='flag-5'>樹莓</b><b class='flag-5'>派</b>的簡單介紹](https://file.elecfans.com/web1/M00/91/DC/o4YBAFzbw0SAFINqAAIJSGdGQdQ187.png)
【樹莓派】樹莓派4B新手篇:安裝官網(wǎng)Raspbian Buster系統(tǒng)及基礎(chǔ)配置
![【<b class='flag-5'>樹莓</b><b class='flag-5'>派</b>】<b class='flag-5'>樹莓</b><b class='flag-5'>派</b>4B新手篇:安裝官網(wǎng)Raspbian Buster<b class='flag-5'>系統(tǒng)</b>及基礎(chǔ)配置](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
評論