600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > Raspberry Pi 基础设置与 opencv

Raspberry Pi 基础设置与 opencv

时间:2020-11-18 05:56:25

相关推荐

Raspberry Pi 基础设置与 opencv

【1】我为什么爱树莓派 / Why I love Raspberry Pi

话说现在的电脑都已经很便宜了,随便买一台上网本都比树莓派的性能要强得多,而且用来开发软件也更容易(编译快,运行快,等等),为什么要“自虐”般地使用树莓派这样一个貌似“不健全”的卡片式电脑呢?

或者换另一个问题,明明都已经有了很多很流行的嵌入式平台,例如Arduino这样的东西,而且Arduino还很便宜,为什么要用树莓派这样的东西来实现一些它可以实现的功能?

我只想从我个人的角度来谈谈这些问题。

先从一个故事说起吧。很久以前,我想自己做一个桌面软件与嵌入式软件结合的系统——例如,一个搭载嵌入式系统的手持设备,需要与Windows上的软件交互——但我个人能力有限,无法自己开发嵌入式程序,因此,我一直想学一些嵌入式系统开发知识,由于工作原因,计划一直搁置。我一直觉得,如果能在嵌入式系统上直接用C++,调用STL库来写程序,那该多好啊,那样我就可以利用自己已经掌握的一部分知识来实现自己的愿望了。



终于,树莓派出现了。装上了Arch Linux ARM的树莓派就像是一个完整的桌面电脑,我可以在上面跟x86计算机一样,没有多少差别地编写程序了!而树莓派同时又具有超便宜的价格、超低的功耗、超小的体积,这些完美地结合在一起,圆了我可以一个人“做点什么”的梦。

所以我爱树莓派爱得深。尽管我不如那些大神一般牛,我不能用它设计出一个令人惊叹的系统,但是我也从上面找到了自己的快乐。

------------------------------------------------------------------华丽丽的分割线-----------------------------------------------------------------------------------------

安装准备:

你还需要以下这些东西:

▪ 一张SD记忆卡

▪ 一个SD读卡器,用于将系统映像写入到SD卡中

▪ 供电来源。我们用的是一个旧的安卓手机充电器,你需要一个5V的micro USB接口充电器为它供电

▪ 如果你是用的普通显示器而不是高清电视,你需要一条HDMI连接线与HDMI-DVI转换器。如果你的显示器支持HDMI或者你打算使用电视机进行连接,那么你就可以省去转换器了

▪ USB接口的键盘和鼠标

▪ 一条以太网线

可选设备:

• 用于保护Raspberry Pi的盒子

• 除了键盘和鼠标之外,如果你打算要连接更多的USB设备,那么你需要一个USB Hub集线器。

我们在本文中使用的东西:

▪ 一个Model B Raspberry Pi

▪ 一张16GB Class 10 SanDisk Ultra SDHC记忆卡(传输率标为300MB/s)

▪ 一个原本用于HTC Inspire的旧充电器

▪ 罗技K260无线键鼠套装(两件只用一个接收器,因此只占用一个USB口)

▪ 一条RJ-45网线

测试环境:Raspbian Wheezy release on original Model B.(部分连接Arduino内容可参考/node/36884)

login: pi raspberry

SSH 登录,用secure crt 连接,登录成功~~~~

默认是pi raspberry

1.sudo apt-get update (否则与opencv相关的libx11-dev下载不下来)

sudo apt-get installsynaptic

sudo synaptic

VNC远程

sudo apt-get install tightvncserver

sudo vncserver :1 -geometry 1200x700 -depth 24 -pixelformat rgb565 //800x600

key: *****1

开机自启动慎用,参考附录10及导致的诡异错误12.

tightvnc win7下远程,头一次忘写端口了,被PI积极的拒绝了。5901记住啊~

Enter command: startx to start the GUI & click LXTerminal, enter:

lsusb(a list of USB devices is displayed, one of those lines listed the LifeCam)

camorama(command to start camorama, or commandcheeseto start cheese)

sudo apt-get install camorama,cheese

----------------------------

在synaptic搜索opencv , 下载libopencv-dev即可。

或者 sudo apt-get installlibopencv-devpython-opencv(可选)

----------------------------

参考:1./andygrove/rasp_pi_camera_opencv

2.

[Lentin] didn’t feel like installing OpenCV from its source, a process that takes the better part of a day. Instead, he installed it using thesynaptic package manager. After connecting a webcam, [Lentin] ssh’d into his Raspi and installed a face detection example script that comes with OpenCV.

It should be noted that [Lentin]‘s install of OpenCV isn’t exactly fast, but for a lot of projects being able to update a face tracker five times a second is more than enough. Once the Raspberry Pi camera module is released the speed of face detection on a Raspi should increase dramatically, though, leading to even more useful computer vision builds with the Raspberry Pi.

3.How to easily install OpenCV on Raspberry Pi

//03/how-to-easily-install-opencv-on.html

Hi all

Building opencv source code in Raspberry Pi will take about 6-7 hours. Here is the link to install opencv from source Raspberry Pi+ OpenCV(注:参照官方网站linux环境中的安装方法)

Easy method to install opencv

1)Connect to Raspberry Pi using ssh. Fig shows an example of connecting Rpi using ssh

2)Install synaptic package manager from command line of raspberry pi

3)Install tight-vnc server from command line

4)Start a vnc server in Rpi for viewing the screen and detection window from opencv

Enter the command to start a vnc-server on Rpi

vncserver :1 -geometry 1200x700 -depth 24 -pixelformat rgb565

#New ‘X’ desktop is raspberrypi:1

5)Start vnc client from PC

eg:vncviewer 192.168.1.3:5901 eg:vncviewer rpi_ip:5901

6)Start synaptic from root terminal like this

7)Install opencv from synaptic like this

8)Download the source code from below

Download

9)Copy files from PC to Rpi usingscpcommand

scp -r facedetect.py face.xml pi@192.168.1.3:"/home/pi"

10)Run python file using following command

python facedetect.py --cascade=face.xml 0

Output --------

Video:

4.摄像头 Logitech C270,插上就可以用。

如今的主流操作系统(如Windows XP SP2 and later, Linux 2.4.6 and later, MacOS 10.5 and later)都已提供UVC设备驱动,因此符合UVC规格的硬件设备在不需要安装任何的驱动程序下即可在主机中正常使用。使用UVC技术的包括摄像头、数码相机、类比影像转换器、电视棒及静态影像相机等设备。

最新的UVC版本为UVC 1.1,由USB Implementers Forum定义包括基本协议及负载格式。

网络摄像头是第一个支持UVC而且也是数量最多的UVC设备,目前,操作系统只要是 Windows XP SP2 之后的版本都可以支持 UVC,当然 Vista 就更不用说了。Linux系统自2.4以后的内核都支持了大量的设备驱动,其中支持UVC设备。

使用 UVC 的好处 USB 在 Video这块也成为一项标准了之后,硬件在各个程序之间彼此运行会更加顺利,而且也省略了驱动程序安装这一环节。

5. 测试opencv和摄像头

I recommend using C or C++ rather than python because it makes a HUGE difference in speed.

You can test your opencv installation and webcam by downloading and running the script below:

http://stevenhickson-/svn/trunk/AUI/Imaging/test

You may have to make this program executable by running:

chmod +x test

The source code and makefile can be found here:

http://stevenhickson-./svn/trunk/AUI/Imaging/

6. 不同xbmc的对比:

RaspBMC vs OpenELEC vs XBian: The Final XBMC Raspberry Pi Shootout

/raspbmc-vs-openelec-vs-xbian-the-final-xbmc-raspberry-pi-shootout/

最终选用: RaspBMC

安装方法:

wget /svn/raspbmc/testing/installers/python/install.py

chmod +x install.py

sudo python install.py

但上述过程安装后启动不了了。。。慎用,再研究~~~

You will then be greeted with a screen similar to the one below. You are now using the installer. Simply follow the instructions and you should be fine.

/wiki/user/os-x-linux-installation/

7.关机---------------------------------------------------------------------------------------------------------------------------------------------

raspberry pi关机很必要,在替换SD卡时常常强行断掉电源,不少人都遭遇了断电后SD卡系统无法启动的问题,这是因为tmp缓存系统也在SD卡上,可能造成文件损坏导致的,最好是使用sudo shutdown -h now或sudo poweroff之类的命令关机后再断电。关机后板子上还有一个红灯亮着,这是通电提示,下面三个绿色黄色LED才是工作指示灯。raspberry pi不支持WOL,没有power on 按钮,这就对开机造成了障碍,所以关机后要开机必须断电后再通电,通电自动启动,所以插线板支持开关就再好不过了

8.超频------------------------------------------------------------------------------------

另外还有超频问题,只需要配置config.txt文件即可,当然一定不要启用force_turbo=1,可能损坏保修资格,使用超频到900的Medium方案最合适,温度不高,速度提升也明显,不同的系统使用相同的超频频率配置运行一次raspi-config来超一次就行了,这样config.txt中的超频设置就自动建立好了,不同的系统不同的频率,就要如上面一样,建立多个config.txt,不同的系统启动不同的超频频率,这个不是很推荐改来改去,我认为对硬件本身伤害很深,使用一个固定的都流畅运行的频率即可。

以上的修改还可以在windows中进行,/boot分区默认是FAT格式,windows可以识别的,所以修改非常方便。高手可以自己配置更复杂的boot方式,比如不同的内核kernel.img,但bootcode.bin和loader.bin似乎不要改,否则就启动不了了。

9. 看门狗--------------------------------------

你还在担心树莓派死机吗?给他装个看门狗吧!/blog//01/2173

什么是看门狗程序?

看门狗程序就是一个健康监控程序,每间隔一定时间(默认10秒)检查一次是否在设定的健康工作范围内,如果超过即启动硬件复位程序,让设备重新启动,恢复健康。

树莓派支持硬件自动复位?

是的,开源的BCM2708芯片让树莓派拥有了硬件看门狗芯片功能,加上linux内核编译好了的bcm2708_wdog模块,树莓派通过watchdog程序实现硬件看门狗功能,达到自动复位功能。

看门狗能做些什么?

比如CPU占用过高假死一定时间,系统严重报错无法响应,CPU温度过高…各种状态均可

接下来一步一步指导如何实现看门狗功能

首先让硬件的看门狗模块运行起来

就我所知从-05以后的内核都默认支持这个模块,如果报错,使用我的精简版系统,我测试过没问题

接下来安装看门狗守护进程,他的功能就是每间隔一定时间向看门狗硬件模块发送一个状态,如果失败,则触发硬件看门狗让树莓派重启

在开始运行watchdog之前,先配置一下这个程序

还可以设置如温度到了多少度就重启,如 取消掉

temperature-device =

max-temperature = 120

前的注释#号,改为

temperature-device =/sys/class/thermal/thermal_zone0/temp

max-temperature = 75000

(温度一般不超过85度就不会损坏芯片,/sys/class/thermal/thermal_zone0/temp记录的是实时的温度,单位为千分之一摄氏度,所以75000就是75℃)

还可以设置内存耗尽就重启,如min-memory =1 前的注释#号去掉

还可以设置监控的间隔,如 interval = 1 前的注释#号去掉,该1为任意数字,单位是秒,默认是10秒一次健康检查

更多设置查阅watchdog文档

接下来我们让watchdog程序运行起来

让我们来测试一下死机后会不会自动重启吧

运行这一串字符会让系统内核立马崩溃,等等看,是不是10秒后他就自动重启了。

利用看门狗程序,结合raspberry pi 的CPU硬件看门狗模块,实现了raspberry pi永不死机。

---------------------------------------------------------------------------------------------------------------------------------------------------

10.开机自启动,慎用!!!

安装VNC需要使用命令行。如果需要远程操作安装VNC,就必须通过SSH登录到命令行界面。请

安装

树莓派命令行:

sudo apt-get install tightvncserver 开机自动启动

安装好之后请一定先使用此命令设置一个VNC密码: vncpasswd 复制代码 (先输入操作密码两次,然后会询问是否设置一个查看(view-only)密码,按自己喜欢,一般没必要。)

设置开机启动,需要在/etc/init.d/中创建一个文件。例如tightvncserver:

(注:启动脚本的名称,有和程序名一致的习惯)sudo nano /etc/init.d/tightvncserver

参考:/linux/tightvnc

内容如下:(putty窗口中按右键=粘贴)

#!/bin/sh

### BEGIN INIT INFO

# Provides: tightvncserver

# Required-Start: $local_fs

# Required-Stop: $local_fs

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# Short-Description: Start/stop tightvncserver

### END INIT INFO

# More details see:

#/linux/tightvnc

### Customize this entry

# Set the USER variable to the name of the user to start tightvncserver under

export USER='pi'

### End customization required

eval cd ~$USER

case "$1" in

start)

# define resolution, console number or other parameters

su $USER -c '/usr/bin/tightvncserver -geometry 1366x760 :1'

echo "Starting TightVNC server for $USER "

;;

stop)

# the same console number with above

su $USER -c '/usr/bin/tightvncserver -kill :1'

echo "Tightvncserver stopped"

;;

*)

echo "Usage: /etc/init.d/tightvncserver {start|stop}"

exit 1

;;

esac

exit 0

有可能导致:/phpBB3/viewtopic.php?f=27&t=13568

注:少数玩家默认用户不是pi的请自行更改USER变量

按Ctrl+X,回答Y(存盘)退出nano编辑器。

然后给tightvncserver文件加执行权限,并更新开机启动列表。sudo chmod 755 /etc/init.d/tightvncserver

sudo update-rc.d tightvncserver defaults附:手工启动与参数

以下用处不大,没兴趣请略过。

使用此命令手工启动VNC服务器程序: tightvncserver -geometry 800x600 :1 复制代码 如果首次启动,并且未曾使用vncpasswd命令设置密码,程序会要求设置一个。

开机启动很方便。如果没理由,真的不推荐手工启动。

命令行参数说明:

一、:1,指定控制台的号码。

启动多个控制台,可以提供互不影响的多个桌面环境。(大多数人不用多用户操作所以没意义)

可以不加此参数,tightvncserver会自动寻找从1开始的下一个空闲控制台。

加上此参数,会强制使用指定的控制台,如果此控制台已经启动则报错。加此参数可有效防止无意多次启动程序(会启动多个控制台)白白浪费系统资源。

特殊的0号控制台

0号控制台就是连接真实显示器真正输出图像的那个桌面。

对于VNC客户端,不输入端口号登录,默认就登录到0号控制台,方便。

但是因为0号是真正的桌面,所以和开机启动桌面环境,或者自己用startx命令,都存在啰嗦的冲突。

到头来是个麻烦。因此自动启动的配置教程中,一律使用1号控制台。

二、-geometry 800x600,分辨率。可以不加。

终止VNC控制台: tightvncserver -kill :1 复制代码 查看正在运行的控制台列表: ps ax | grep Xtightvnc | grep -v grep 复制代码

------------------------------------------------

11.

rdesktop 会自动调整到你设置的分辨率。

本文中的所有译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接

我们的翻译工作遵照CC 协议,如果我们的工作有侵犯到您的权益,请及时联系我们

----------------------------------------------

12. 诡异错误:/phpBB3/viewtopic.php?f=28&t=28521

I have the same problem. Upon the initial boot, I selected and set several options, including booting up directly into the GUI. Now, when the system starts up, I get the usual Linux wall-o-text, and then it goes to a GUI login screen. There is a small graphic in the center of the screen with a picture of a terminal and the words "raspberrypi" under it. There is a login window, and a drop down menu with options for "Default Xsession", "LXDE", and "Openbox". I no longer have an opportunity to get to a command line when I boot up. I am also using the Hungrypi distro.

Hi all,

For all those who cannot ssh or cannot get a shell upfronttry typingctrl+alt+F1(or F2 or F3). when doing this the shell opened for me and i could login with user "pi" and password "raspberry" if not changed.

Got this from here:viewtopic.php?f=65&t=30621&p=266444&hilit=default+xsession#p266444(finally my french is paying off)

when logged on you can probably start the GUI by typing "startx", worked for me at least.

紧接着有一个问题:

timeout in locking authority file /home/pi/.Xauthority ”

One possible source of this problem can be file ownership. You could try running following command:

sudo chown -R pi:pi /home/pi

This should change ownership of all files in pi directory (and all directories inside of it) back to the user pi and group pi.

xauth application has a commandline option-bwhich is intended to clean stale locks if they exists so you could also try running (when logged in as user pi):

xauth -b

.Xauthority file is not needed when X session is not running so you could safely remove it and it will be recreated next time X is started. But the message does not seem to suggest the file is corrupted so I don't think this can solve your issue.

13.---------------------------------------------------------------------------------------

Ubuntu 系统 Update-rc.d 命令

Ubuntu或者Debian系统中update-rc.d命令,是用来更新系统启动项的脚本。这些脚本的链接位于/etc/rcN.d/目录,对应脚本位于/etc/init.d/目录。在了解update-rc.d命令之前,你需要知道的是有关Linux 系统主要启动步骤,以及Ubuntu中运行级别的知识。

一、Linux 系统主要启动步骤

读取 MBR 的信息,启动 Boot Manager。 加载系统内核,启动 init 进程, init 进程是 Linux 的根进程,所有的系统进程都是它的子进程。 init 进程读取 /etc/inittab 文件中的信息,并进入预设的运行级别。通常情况下 /etc/rcS.d/ 目录下的启动脚本首先被执行,然后是/etc/rcN.d/ 目录。 根据 /etc/rcS.d/ 文件夹中对应的脚本启动 Xwindow 服务器 xorg,Xwindow 为 Linux 下的图形用户界面系统。 启动登录管理器,等待用户登录。

二、运行级别

Ubuntu中的运行级别

0(关闭系统) 1(单用户模式,只允许root用户对系统进行维护。) 2 到 5(多用户模式,其中3为字符界面,5为图形界面。) 6(重启系统)

切换运行级别

启动项管理工具

三、update-rc.d命令详解

从所有的运行级别中删除指定启动项

按指定顺序、在指定运行级别中启动或关闭

解析:表示在2、3、4、5这五个运行级别中,由小到大,第20个开始运行apachectl;在 0 1 6这3个运行级别中,第20个关闭apachectl。这是合并起来的写法,注意它有2个点号,效果等于下面方法:

A启动后B才能启动,B关闭后A才关闭

启动和关闭顺序为90,级别默认

原文地址 :/blog/ubuntu-update-rc-d.html

本站遵循 :知识共享署名-非商业性使用-相同方式共享 3.0 版权协议

版权声明 : 原创文章转载时,请务必以超链接形式标明文章原始出处

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。