close_btn
로그인, 회원가입후 더 많은 혜택을 누리세요 로그인 회원가입 닫기

리눅스에서 opencv 설치 (아나콘다 포함)

2016.08.09 21:17

희동 조회 수:3369 추천:2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1. 패키지 목록을 받아오고

 

$ sudo apt-get update 

 

 

2. 컴파일시 필요한 패키지들 설치

 

$ sudo apt-get install build-essential checkinstall cmake git pkg-config yasm libtiff4-dev libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev  libv4l-dev python-dev python-numpy libtbb-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils libopenexr-dev python-tk  libeigen3-dev libx264-dev 

 

 

$ sudo apt-add-repository ppa:mc3man/trusty-media

$ sudo apt-get update

$ sudo apt-get install ffmpeg gstreamer0.10-ffmpeg

 

 

3. OpenCV 소스코드 다운로드

$ mkdir tmp

$ cd tmp

$ git clone https://github.com/opencv/opencv.git

 

 

 

 

Building OpenCV from Source Using CMake, Using the Command Line

  1. Create a temporary directory, which we denote as <cmake_binary_dir>, where you want to put the generated Makefiles, project files as well the object files and output binaries.

  2. Enter the <cmake_binary_dir> and type

    cmake [<some optional parameters>] <path to the OpenCV source directory>
    

    For example

    cd ~/opencv
    mkdir release
    cd release
    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
    
  3. Enter the created temporary directory (<cmake_binary_dir>) and proceed with:

    make
    sudo make install
    

 

 

6. opencv  버전 확인 및 예제 컴파일

 

$ pkg-config --modversion opencv

3.1.0

 

 

 

아래 소스코드를 main.cpp라는 이름으로 작성

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "opencv2/opencv.hpp"  
#include <iostream>  
  
using namespace cv;  
using namespace std;  
  
  
  
int main(intchar**)  
{  
    //웹캡으로 부터 데이터 읽어오기 위해 준비  
    VideoCapture cap1(0);  
    if (!cap1.isOpened())  
    {  
        printf("첫번째 카메라를 열수 없습니다. \n");  
    }  
  
  
    Mat frame1;  
    namedWindow("camera1"1);  
   
  
    for (;;)  
    {  
  
        //웹캡으로부터 한 프레임을 읽어옴  
        cap1 >> frame1;  
  
        imshow("camera1", frame1);  
  
        //  
        if (waitKey(20>= 0break;  
    }  
  
  
    return 0;  
}  
 

cs

 

 

 

컴파일 후.. 실행시켜봄..

g++ -o main main.cpp `pkg-config opencv --cflags --libs`

./main

 

http://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html

 

 

[아나콘다에 설치]

For openCV:
conda install -c menpo opencv3=3.1.0