Auto install opencv after installing Ubuntu

Here is the shell code

#!/bin/bash
sudo apt-get install -y build-essential
sudo apt-get install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
cd opencv
mkdir release
cd release
cmake -D WITH_IPP=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/duino/src/opencv/opencv_contrib/modules ..
make -j5
sudo make install

cd ~/
git clone https://github.com/duinodu/testopencvinstall.git
cd testopencvinstall
sudo chmod +x auto.sh
./auto.sh
cd build
./DisplayImage ../test.jpg
echo ""
echo "opencv install successfully"
echo ""
cd ~
rm -rf testopencvinstall

How to do

  • step1: copy this into a file named installOpencv.sh
  • step2:
sudo chmod +x installOpencv.sh
  • step3:
git clone https://github.com/Itseez/opencv.git
git clone https://github.com/Itseez/opencv_contrib.git
  • step4: check your file directory, it should be like this:
    —–installOpencv.sh
    —–opencv
    —–opencv_contrib

  • step5: edit installOpencv.sh, change OPENCV_EXTRA_MODULES_PATH to your own.

  • step6: ./installOpencv.sh

You may need to input password when sudo make install, because compiling opencv costs much time.

You may notice that there is a test demo for opencv. It is simple test of using opencv to show an image. After installation, this test demo will be deleted.

Version 2

#!/bin/bash
sudo apt-get install -y build-essential
sudo apt-get install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

git clone https://github.com/Itseez/opencv.git
git clone https://github.com/Itseez/opencv_contrib.git

cd opencv
mkdir release
cd release
cmake -D WITH_IPP=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/duino/src/opencv/opencv_contrib/modules ..
make -j5
sudo make install

cd ~/
git clone https://github.com/duinodu/testopencvinstall.git
cd testopencvinstall
sudo chmod +x auto.sh
./auto.sh
cd build
./DisplayImage ../test.jpg
echo ""
echo "opencv install successfully"
echo ""
cd ~
rm -rf testopencvinstall

In this shell, you still need to change OPENCV_EXTRA_MODULES_PATH to your own. It will git clone opencv src automatically.

Problem

  • “Unable to fetch http://….” You need to change your apt source in /etc/apt/sources.list. Different version of ubuntu uses different nickname, and the others are the same. For 16.04, it is xenial. Without essential packages correctly installed, it will get error when compiling opencv. It is important.
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值