如何在Ubuntu 12.04中安装opencv并用Python运行它?

如何在Ubuntu 12.04中安装opencv并用Python运行它?

我想在 raspberry-pi 上进行图像处理。

为此,首先我想在 Ubuntu 中进行此操作。

当我运行命令时sudo apt-get install libopencv-dev,我得到了以下输出:

naveen@ubuntu:~$ sudo apt-get install libopencv-dev

[sudo] password for naveen: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
 gir1.2-ubuntuoneui-3.0 firefox-locale-en language-pack-kde-en cabextract
 kde-l10n-engb libjpeg62 libubuntuoneui-3.0-1 thunderbird-globalmenu
 language-pack-en-base language-pack-kde-en-base language-pack-en
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
 debhelper dh-apparmor gettext html2text intltool-debian libatk1.0-dev
 libavcodec-dev libavformat-dev libavutil-dev libcairo-script-interpreter2
 libcairo2-dev libdc1394-22-dev libexpat1-dev libfontconfig1-dev
 libfreetype6-dev libgdk-pixbuf2.0-dev libgettextpo0 libglib2.0-dev
 libgtk2.0-dev libice-dev libilmbase-dev libmail-sendmail-perl
 libopencv-calib3d-dev libopencv-calib3d2.3 libopencv-contrib-dev
 libopencv-contrib2.3 libopencv-core-dev libopencv-core2.3
 libopencv-features2d-dev libopencv-features2d2.3 libopencv-flann-dev
 libopencv-flann2.3 libopencv-gpu-dev libopencv-gpu2.3 libopencv-highgui-dev
 libopencv-highgui2.3 libopencv-imgproc-dev libopencv-imgproc2.3
 libopencv-legacy-dev libopencv-legacy2.3 libopencv-ml-dev libopencv-ml2.3
 libopencv-objdetect-dev libopencv-objdetect2.3 libopencv-video-dev
 libopencv-video2.3 libopenexr-dev libpango1.0-dev libpcre3-dev libpcrecpp0
 libpixman-1-dev libpng12-dev libpthread-stubs0 libpthread-stubs0-dev
 libraw1394-dev libsm-dev libswscale-dev libsys-hostname-long-perl
 libunistring0 libx11-dev libx11-doc libxau-dev libxcb-render0-dev
 libxcb-shm0-dev libxcb1-dev libxcomposite-dev libxcursor-dev libxdamage-dev
 libxdmcp-dev libxext-dev libxfixes-dev libxft-dev libxi-dev libxinerama-dev
 libxrandr-dev libxrender-dev po-debconf x11proto-composite-dev
 x11proto-core-dev x11proto-damage-dev x11proto-fixes-dev x11proto-input-dev
 x11proto-kb-dev x11proto-randr-dev x11proto-render-dev x11proto-xext-dev
 x11proto-xinerama-dev xorg-sgml-doctools xtrans-dev
 Suggested packages:
  dh-make gettext-doc libfaad-dev libgsm1-dev libogg-dev libschroedinger-dev
  libspeex-dev libtheora-dev libvorbis-dev libcairo2-doc libglib2.0-doc
  libgtk2.0-doc libpango1.0-doc libraw1394-doc libxcb-doc libmail-box-perl
 Recommended packages:
   libraw1394-tools
 The following NEW packages will be installed:
   debhelper dh-apparmor gettext html2text intltool-debian libatk1.0-dev
   libavcodec-dev libavformat-dev libavutil-dev libcairo-script-interpreter2
   libcairo2-dev libdc1394-22-dev libexpat1-dev libfontconfig1-dev
   libfreetype6-dev libgdk-pixbuf2.0-dev libgettextpo0 libglib2.0-dev
   libgtk2.0-dev libice-dev libilmbase-dev libmail-sendmail-perl
   libopencv-calib3d-dev libopencv-calib3d2.3 libopencv-contrib-dev
   libopencv-contrib2.3 libopencv-core-dev libopencv-core2.3 libopencv-dev
   libopencv-features2d-dev libopencv-features2d2.3 libopencv-flann-dev
   libopencv-flann2.3 libopencv-gpu-dev libopencv-gpu2.3 libopencv-highgui-dev
   libopencv-highgui2.3 libopencv-imgproc-dev libopencv-imgproc2.3
   libopencv-legacy-dev libopencv-legacy2.3 libopencv-ml-dev libopencv-ml2.3
   libopencv-objdetect-dev libopencv-objdetect2.3 libopencv-video-dev
   libopencv-video2.3 libopenexr-dev libpango1.0-dev libpcre3-dev libpcrecpp0
   libpixman-1-dev libpng12-dev libpthread-stubs0 libpthread-stubs0-dev
   libraw1394-dev libsm-dev libswscale-dev libsys-hostname-long-perl
   libunistring0 libx11-dev libx11-doc libxau-dev libxcb-render0-dev
   libxcb-shm0-dev libxcb1-dev libxcomposite-dev libxcursor-dev libxdamage-dev
   libxdmcp-dev libxext-dev libxfixes-dev libxft-dev libxi-dev libxinerama-dev
   libxrandr-dev libxrender-dev po-debconf x11proto-composite-dev
   x11proto-core-dev x11proto-damage-dev x11proto-fixes-dev x11proto-input-dev
   x11proto-kb-dev x11proto-randr-dev x11proto-render-dev x11proto-xext-dev
   x11proto-xinerama-dev xorg-sgml-doctools xtrans-dev
   0 upgraded, 90 newly installed, 0 to remove and 0 not upgraded.
   Need to get 300 kB/32.4 MB of archives.
   After this operation, 135 MB of additional disk space will be used.
 Do you want to continue [Y/n]? y
   Err http://archive.ubuntu.com/ubuntu/ precise-updates/main x11proto-core-dev all 7.0.22-1ubuntu0.1
   Connection failed [IP: 91.189.91.13 80]
   Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/x/x11proto-core/x11proto-core-dev_7.0.22-1ubuntu0.1_all.deb  Connection failed [IP: 91.189.91.13 80]
   E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

我能做些什么来解决这个错误?

答案1

许多人在安装 OpenCV 时遇到问题。有一个简单的 .sh 脚本文件,从互联网上获取所有依赖文件并编译源代码,最后在您的系统上安装 opencv。

从以下网址下载最新的 opencv.sh这里

我假设您已经告诉我您已经在下载目录中下载了脚本,然后执行以下操作:

打开终端。

cd ~/Downloads  
chmod +x opencv.sh
./opencv.sh

查看Ubuntu 文档了解更多信息

相关内容