OpenCV 이미지 프로세싱

OpenCV 설치

http://opencv.org공식 사이트와 https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv/에도 설치법이 나와 있어요.

이 글을 보셔도 되어요. 어차피 베껴왔어요.

우리가 할 것은 github에서 opencv 소스를 받아와서 직접 빌드하는 거예요.

사전 작업

sudo apt-get update
sudo apt-get upgrade

일단 패키지 업데이트를 하고요.

sudo apt-get install python3 build-essential cmake unzip pkg-config libjpeg-dev libpng-dev libtiff-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libgtk-3-dev libatlas-base-dev gfortran python3-dev

필요한 패키지를 다 받아요.

이제 소스를 홈 디렉토리에 받아보아요.

wget -O opencv.zip https://github.com/opencv/opencv/archive/3.4.1.zip -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.4.1.zip

압축을 풀어요.

unzip opencv.zip opencv_contrib.zip

VirtualEnv

이제 VirtualEnv 환경 설정을 해보아요. 이 글에 virtualenv의 유용함이 잘 나와 있어요.

wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
sudo pip install virtualenv virtualenvwrapper
sudo rm -rf ~/get-pip.py ~/.cache/pip

텍스트 에디터로 ~/.bashrc를 수정해요.

# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
source ~/.bashrc

끝났어요. 이제 가상 환경을 만들어요.

mkvirtualenv [가상 환경 이름] -p python3

가상 환경에 들어가요.

workon [가상 환경 이름]

터미널 앞에 가상 환경 이름이 붙는다면 잘 된 거예요.

빌드

$ workon [가상 환경 이름]
$ cd ~/opencv-3.4.1
$ mkdir build
$ cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_PYTHON_EXAMPLES=ON \
	-D INSTALL_C_EXAMPLES=OFF \
	-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.4.1/modules \
	-D PYTHON_EXECUTABLE=~/.virtualenvs/[가상 환경 이름]/bin/python \
	-D BUILD_EXAMPLES=ON ..

이제 좀 기다리세요. 중간에 에러 뜨는지 터미널 창 계속 지켜보세요. ~~~~.h: no such file or directory 오류가 뜨면 build 디렉토리를 삭제하고 다시 만들어 들어간 뒤 cmake를 -D ENABLE_PRECOMPILED_HEADERS=OFF 옵션을 추가하여 실행하세요.

이제 인내의 시간이 왔어요.

make -j4

j뒤에 붙는 숫자는 스레드예요. j4는 작업을 동시에 네 개까지 진행할 수 있다는 거예요. 숫자가 높을수록 빨라지기는 하는데 그만큼 메모리도 많이 먹어요. 램이 부족하면 컴퓨터가 뻗어요. 숫자를 안 붙이면 스레드 수에 제한이 없어지지만 시도해보지는 마세요. 제가 해봤다가 노트북이 뻗었어요. make 중간에 오류가 나면 build 폴더를 삭제하고 다시 만들어 들어가 cmake를 한 뒤 -j 옵션을 붙이지 말고 그냥 make만 입력하세요.

사후 작업

sudo make install
sudo ldconfig
cd /usr/local/lib/python3.6/site-packages/
sudo mv cv2.cpython-36m-x86_64-linux-gnu.so cv2.so
cd ~/.virtualenvs/[가상 환경 이름]/lib/python3.6/site-packages/
ln -s /usr/local/lib/python3.6/site-packages/cv2.so cv2.so

확인

$ workon [가상 환경 이름]
$ python
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.4.1'
>>> exit()

이제 소스코드 zip파일은 삭제해도 돼요.

댓글

댓글 본문
작성자
비밀번호
  1. http://www.yeezy-500.us.com
    http://www.redbottom-shoes.us.com
    http://www.cheap-airjordans.us.com
    http://www.filashoes.us.org
    http://www.nike-hyperdunk.us.com
    http://www.yeezyboost350v2.org.uk
    http://www.curry4.net
    http://www.yeezysshoes.us.com
    http://www.toryburchs.us
    http://www.chromeheartsoutletonline.com
    http://www.jordan11retro.us.com
    http://www.filashoes.org
    http://www.adidasstansmith.uk
    http://www.offwhitexjordan1.com
    http://www.air-max.us.com
    http://www.yeezy-boost.us.com
    http://www.yesyeezy.shop......tml
    http://www.jimmychoo-shoes.us.com
    http://www.nikeairmax2019.us.com
    http://www.hermes-handbags.us.com
    http://www.nikepolo.us
    http://www.outletlacoste.us.com
    http://www.fila-shoes.us.com
    http://www.goldengoosesneakers.us
    http://www.jordan13.us.com
    http://www.nikereact.org
    http://www.bapehoodie.us
    http://www.ferragamobelt.us
    http://www.adidasnmduk.com
    http://www.monclerjackets.us
    http://www.kyrieirving-shoes.us.com
    http://www.lacostepolo.us.com
    http://www.yesyeezy.shop......tml
    http://www.yeezy-shoes.us.org
    http://www.adidasyeezy.co.uk
    http://www.coachoutletstorefactory.com
    http://www.jordan4.us.com
    http://www.yeezy-boost350.us.com
    http://www.goyard.us.com
    http://www.hogan-outlet.us.com
    http://www.jordansshoes.us.org
    http://www.yslhandbags.net
    http://www.fitflops-saleclearance.us.com
    http://www.katespadehandbags-outlet.us.com
    http://www.yeezyboost350v2shoes.us.com
    http://www.adidas-tubular.us.com
    http://www.asics-shoes.us.org
    http://www.hermesbelts.com
    http://www.yesyeezy.shop......tml
    http://www.yeezyshoesuk.com
    http://www.nike-roshe.us.com
    http://www.nikejordans.us.com
    http://www.outletmichael-kors.us.com
    http://www.supremeclothing.us
    http://www.goyardbags.us
    http://www.adidas-crazyexplosive.us.com
    http://www.michael-kors-handbags.com.co
    http://www.adidasiniki.us
    http://www.yeezysshoes.org
    http://www.guccibelt.us.com
    http://www.kd11.us.com
    http://www.yesyeezy.shop
    http://www.hermesonlineshop.com
    http://www.longchamphandbags.co.uk
    http://www.lebron16.us
    http://www.hermes-birkin.us.com
    http://www.goldengoose.us.com
    http://www.yesyeezy.shop/supreme-x-nike-air-more-uptempo-varsity-redwhite-902290600-p-592.html
    http://www.kobesneakers.com
    http://www.coachoutletssale.com
    http://www.kd11.us
    http://www.nikeair-max.us.com
    http://www.hermeshandbags.us.org
    http://www.caterpillarboots.us.com
    http://www.airmax90.us.org
    http://www.coachoutlets.name
    http://www.offwhite.us.com
    http://www.yeezyboost-350v2.us.com
    http://www.adidassuperstar.us.com
    http://www.coachsonline.us.com
    http://www.yesyeezy.shop/adidas-yeezy-boost-350-v2-cream-white-cp9366-p-423.html
    http://www.jordan12.us.com
    http://www.golden-goose.us.com
    http://www.calvinkleinoutlet.us.com
    http://www.lebron16.us.com
    http://www.converseoutlet.us.com
    http://www.yesyeezy.shop/adidas-yeezy-boost-350-v2-beluga-solar-red-bb1826-p-422.html
    http://www.hardenshoes.us.com
    http://www.kobebasketballshoes.net
    http://www.goyardhandbags.org
    http://www.yeezy-boosts.us.com
    http://www.lebronjames-shoes.us.com
    http://www.nikebasketballshoes.us.com
    http://www.nike-shox.us.com
    http://www.balenciagashoes.us.com
    http://www.lebron15.net
    http://www.louboutinshoes.uk
    http://www.jordanshoes.org.uk
    http://www.yesyeezy.shop/balenciaga-17fw-triple-s-trainer-black-red-mens-w05m23972-p-613.html
    http://www.jordanssneakers.us.com
    http://www.balenciaga.us.com
    http://www.nikesneakers.us.com
    http://www.adidas-pureboost.us.com
    http://www.nike-airmax2017.us.com
    http://www.fakerolex.us.com
    http://www.nikeflyknit.us.com
    http://www.outletonline-michaelkors.us.org
    http://www.paulgeorgeshoes.us.com
    http://www.ultraboost.us.com
    http://www.adidasstansmith.us.com
    http://www.jordan-retro.us.com
    http://www.shoesjordan.us.com
    http://www.reebokoutlet.us.org
    http://www.russellwestbrookshoes.us.com
    http://www.yeezyboost-350.uk
    http://www.pandorabracelet.in.net
    http://www.airjordanretro.uk
    http://www.adidasyeezys.us.com
    http://www.outlettimberland.us.org
    http://www.kyrie4.org
    http://www.yesyeezy.shop/offwhite-air-jordan-1-retro-chicago-the-ten-aa3834101-p-837.html
    http://www.yesyeezy.shop/air-jordan-1-og-game-royal-blue-mens-555088403-p-682.html
    http://www.goldengooseoutlet.us
    http://www.valentinosshoes.us
    http://www.kyrie3.us.com
    http://www.nhljerseysshop.us.com
    http://www.nfljerseys.us.org
    http://www.coachoutletsfactory.com
    http://www.long-champ.us.com
    http://www.supremehoodie.us.com
    http://www.michael-kors-handbags.org.uk
    http://www.hermes-belt.us.com
    http://www.yeezy700.us.com
    http://www.nikefoamposite.us.com
    http://www.lebron16.net
    http://www.yesyeezy.shop/offwhite-x-nike-air-presto-black-aa3830002-p-291.html
    http://www.lacostepolosshirts.com
    http://www.yesyeezy.shop/adidas-yeezy-desert-rat-500-blush-db2908-p-425.html
    http://www.yeezysuk.com
    http://www.mbtshoesonline.com
    http://www.handbagsmichaelkors.com
    http://www.goyardhandbags.us.com
    http://www.adidasoutletonline.com
    http://www.chromehearts.com.co
    http://www.fila.us.org
    http://www.kevindurant-shoes.us.com
    http://www.vapormaxshoes.us
    http://www.michael--korsoutlet.us.org
    http://www.michaelkors-outletfactory.us.org
    http://www.chromehearts.name
    http://www.yesyeezy.shop/balenciaga-17fw-triple-s-black-pink-women-sneaker-483523w06e38080-p-618.html
    http://www.yeezyboost.in.net
    http://www.offwhiteclothing.us.com
    http://www.birkinbag.us.com
    http://www.hermesbelts.co.uk
    http://www.balenciagashoes.us.org
    http://www.bape-hoodie.us.com
    http://www.mlbjerseys.in.net
    http://www.vans-outlet.us.com
    http://www.jordan6.us.com
    http://www.michaeljordanshoes.us.com
    http://www.curry5.us.com
    http://www.polosralphlaurenuk.com
    http://www.curry4shoes.us.com
    http://www.adidasgazelle.us.com
    http://www.lacosteonlineshop.us.com
    http://www.goyard-handbags.us.com
    http://www.retro-jordans.us.com
    http://www.michael-korsoutlets.us
    http://www.goldengoose-outlet.us.com
    http://www.offwhitehoodie.us.com
    http://www.goldengoose-sneakers.com
    http://www.off-whiteshoes.us.com
    http://www.adidasyeezys.us
    http://www.kobe-shoes.us.com
    http://www.monclersoutlet.us.com
    http://www.ferragamobelt.us.org
    http://www.michaelkors-outletonlines.us.com
    http://www.nikecortez.us.com
    http://www.yeezy500.us
    http://www.adidasultraboost.us.org
    http://www.jordansforcheap.us.com
    http://www.canada-goose.in.net
    http://www.nikeairmax2018.us.com
    http://www.goldengoose-sneakers.us
    http://www.nikereact.us.com
    http://www.adidasnmds.us.com
    http://www.nikehuaracheshoes.us.com
    http://www.airmax270.us.com
    http://www.cheapnbajerseyswholesales.us.com
    http://www.nike-huarache.com
    http://www.adidasnmds.com
    http://www.yeezyboost.com.co
    http://www.nikeairforce1.us.com
    http://www.adidaseqts.com
    http://www.yeezy-shoes.org.uk
    http://www.yesyeezy.shop/nike-air-max-197-sean-wotherspoon-aj4219400-p-66.html
    http://www.adidasshoesonline.com
    http://www.kd-10.us
    http://www.longchampshandbags.us
    http://www.adidaszxflux.com
    http://www.monclerjacket.net
    http://www.rolex-replica.us.com
    wwwe
  2. Froggy
    Raspberry pi B3 에서 make -j4 할 때는 문제가 없었는데, 최신 기종 B3+에서는 하다가 계속 멈춰서 make 로 했더니 되더군요. 어떤 차이가 있어서 그런지 모르겠어요.
버전 관리
truelight
현재 버전
선택 버전
graphittie 자세히 보기