python용 opencv를 어렵게 설치하고 샘플을 수행했을 때 오류가 나오면 정말 허탈하죠.

이중 아래와 같은 오류는 빈번하게 발생합니다.


python 실행 시 import cv2에서 아래와 같은 오류가 발생할 때


ImportError: /usr/local/lib/libopencv_freetype.so.3.2: undefined symbol: hb_shape


해당 오류에 대한 trackback은 아래와 같으며


trackback URL → https://github.com/opencv/opencv_contrib/issues/919


위 글의 중간 쯤에 "Kumataro"란 유저가 해결방법을 남겼습니다. ( Kumataro commented on Dec 27, 2016 • edited )

아래는 Kumataro 해결법에 대한 연결경로입니다. 아래로 직접 가셔도 되요.

연결 URL → https://github.com/Kumataro/opencv_contrib/commit/cf8c1aad2771c325b8ffffd71f31fcdc84166b68


지금 쓰고 있는 글도 위를 토대로 제가 당한 문제를 해결하고 나서 작성한 것입니다.


□ 해결방법

참고) 저의 환경은 python 2.7 - opencv 3.2.0 입니다. opencv 설치 문제이므로 python은 2.7이든 3.X든 동일한 문제가 납니다.


아래 파일을 오픈합니다.

~/opencv/opencv_contrib-3.2.0/modules/freetype/CMakeLists.txt


해당 파일의 22번째 줄을 주석처리하고 아래 파란색 명령을 추가합니다.

즉,  freetype2_LIBRARIES와 harfbuzz_LIBRARIES이 제대로된 경로를 못찾아주어서 발생하는 오류입니다.


if( FREETYPE_FOUND AND HARFBUZZ_FOUND )

#  ocv_define_module(freetype opencv_core opencv_imgproc PRIVATE_REQUIRED ${freetype2_LIBRARIES} ${harfbuzz_LIBRARIES} WRAP python)

   ocv_define_module(freetype opencv_core opencv_imgproc PRIVATE_REQUIRED ${FREETYPE_LIBRARIES} ${HARFBUZZ_LIBRARIES} WRAP python)

   ocv_include_directories( ${FREETYPE_INCLUDE_DIRS} ${HARFBUZZ_INCLUDE_DIRS}     

)


이후, ~/opencv/opencv-3.2.0/build 디렉토리에서 

cmake -D CMAKE_BUILD_TYPE=RELEASE \

-D CMAKE_INSTALL_PREFIX=/usr/local \

-D WITH_TBB=OFF \

-D WITH_IPP=OFF \

-D WITH_1394=OFF \

-D BUILD_WITH_DEBUG_INFO=OFF \

-D BUILD_DOCS=OFF \

-D INSTALL_C_EXAMPLES=ON \

-D INSTALL_PYTHON_EXAMPLES=ON \

-D BUILD_EXAMPLES=OFF \

-D BUILD_TESTS=OFF \

-D BUILD_PERF_TESTS=OFF \

-D ENABLE_NEON=ON \

-D WITH_QT=ON \

-D WITH_OPENGL=ON \

-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.2.0/modules \

-D WITH_V4L=ON  \

-D WITH_FFMPEG=ON \

-D WITH_XINE=ON \

-D BUILD_NEW_PYTHON_SUPPORT=ON \

../ 

를 다시 수행시켜 주세요. 문제가 있던 opencv를 uninstall하실 필요는 없습니다.

대부분 이미 설정이 완료되어 있으므로 금방 끝납니다. 


-- Configuring done
-- Generating done
-- Build files have been written to: /home/webnautes/opencv/opencv-3.2.0/build


이와 같은 문구를 빠르게 보게 될 겁니다.


이제 다시 컴파일을 합니다.

 ~/opencv/opencv-3.2.0/build$ time make -j12


제 컴퓨터는 CPU 코어수가 12개라 -j12입니다. 컴파일 전에 본인의 CPU 코어수를 확인해야할 필요가 있죠.

다음과 같은 명령으로 쉽게 확인이 가능합니다.

 cat /proc/cpuinfo | grep processor | wc -l 


컴파일도 대부분 이미 완료되었으므로 빠르게 끝납니다.

이제 마지막 재설치 작업만 남았군요. 별건 없고 아래 명령으로 끝~

 ~/opencv/opencv-3.2.0/build$ sudo make install


문제가 된 python 소스를 실행 시켜보시면 잘 실행 될 것입니다.

그래도 해결이 안된다면... 건투를 빕니다. 당신은 꼭 해결방법을 찾을 것입니다. 그때 다시 오셔서 지식을 나눠주세요. 


반응형

Anaconda3 Python3  환경에서 OpenCV3 설치할 때 참고하면 좋은 사이트입니다.


본문 내용 중 


Python3 OpenCV3 설치 - Anaconda3

Python 3.5 설치 후, OpenCV3 를 설치하는 과정이 쉽지만은 않습니다.


기본적으로 설치 파일에는 Python 3 버전을 지원하지 않기 때문에 입니다. 소스를 다운받아 컴파일 해야하는데 여러가지 환경문제로 컴파일도 쉽지 않습니다.

그래서, 여기서는 좀 더 쉽게 Anaconda를 이용하여 설치해 봅니다.


검색일자   2017.06.18

원문 URL   http://wandlab.blogspot.kr/2016/11/python3-opencv3-anaconda3.html

반응형


파이썬에서 Import 방법은 두 가지가 있습니다.


import 모듈

→ 해당 모듈 전체를 가져온다.

    사용하려면 항상 '모듈명.메소드' 와 같이 모듈명을 앞에 붙여주어야 한다.


from 모듈 import 메소드 / 변수

→ 해당 모듈 내에 있는 특정 메소드나 모듈 내 정의된 변수를 가져온다.

    가져온 메소드나 변수를 앞에 모듈명을 붙이지 않고 그대로 사용할 수 있다.

    다만, 이름이 같은 변수나 메소드가 존재할 경우 대체된다.

    

    from 모듈 import * 이라고 하면 import 모듈과 동일하다. (사용 시 모듈명 붙이는 것 빼고)


아래는 두 방식에 대해 잘 설명된 사이트입니다. 단, 파이썬 2.7 버전을 중심으로 설명하고 있습니다.


□ 원본 URL → https://wikidocs.net/77



반응형

 

□ Jupyter notebook 명령키 일람

 

Command Mode (press Esc to enable) Edit Mode (press Enter to enable)
Enter   enter edit mode Tab   code completion or indent
Shift-Enter   run cell, select below Shift-Tab   tooltip
Ctrl-Enter   run cell Ctrl-]   indent
Alt-Enter   run cell, insert below Ctrl-[   dedent
Y   to code Ctrl-A   select all
M   to markdown Ctrl-Z   undo
R   to raw Ctrl-Shift-Z   redo
1  to heading 1 Ctrl-Y   redo
2  to heading 2 Ctrl-Home   go to cell start
3  to heading 3 Ctrl-Up   go to cell start
4  to heading 4 Ctrl-End   go to cell end
5  to heading 5 Ctrl-Down   go to cell end
6  to heading 6 Ctrl-Left   go one word left
Up   select cell above Ctrl-Right   go one word right
K   select cell above Ctrl-Backspace   delete word before
Down   select cell below Ctrl-Delete   delete word after
J   select cell below Esc   command mode
A   insert cell above Ctrl-M   command mode
B   insert cell below Shift-Enter   run cell, select below
X   cut selected cell Ctrl-Enter   run cell
C   copy selected cell Alt-Enter   run cell, insert below
Shift-V   paste cell above Ctrl-Shift-Subtract   split cell
V   paste cell below Ctrl-Shift--   split cell
Z   undo last cell deletion Ctrl-S   Save and Checkpoint
D,D   delete selected cell Up   move cursor up or previous cell
Shift-M   merge cell below Down   move cursor down or next cell
S   Save and Checkpoint Shift   ignore
Ctrl-S   Save and Checkpoint
L   toggle line numbers
O   toggle output
Shift-O   toggle output scrolling
Esc   close pager
Q   close pager
H   show keyboard shortcut help
I,I   interrupt kernel
0,0   restart kernel
Space   scroll down
Shift-Space   scroll up
Shift   ignore

 

□ 기타 명령 모음

  - ipynb 파일 → py 파일 변환

    콘솔창에서 아래 명령 수행


    jupyter nbconvert --to script [파일명].ipynb



반응형

+ Recent posts