-
[OpenCV] OpenCV 윈도우 개발 환경 및 예제IT Tech/찍어먹는 IT 2020. 10. 2. 19:07
준비 - 필요한 파일을 다운로드
VS ( Visual Studio ) - https://visualstudio.microsoft.com/ko/
Visual Studio IDE, 코드 편집기, Azure DevOps 및 App Center - Visual Studio
Visual Studio dev tools & services make app development easy for any platform & language. Try our Mac & Windows code editor, IDE, or Azure DevOps for free.
visualstudio.microsoft.com
비주얼 코드 말고 비주얼 스튜디오로 하자
비주얼 코드 쓰기가 어렵다
왠만하면 다 있을 것 같긴함
OpenCV 4.4 - https://github.com/opencv/opencv
opencv/opencv
Open Source Computer Vision Library. Contribute to opencv/opencv development by creating an account on GitHub.
github.com
위 사이트에 접속해서 소스코드를 다운로드 받았다
git clone을 통해서 받아도 되고 ZIP 파일을 통해서 받아도 된다
OpenCV_contrib - https://github.com/opencv/opencv_contrib/
Releases · opencv/opencv_contrib
Repository for OpenCV's extra modules. Contribute to opencv/opencv_contrib development by creating an account on GitHub.
github.com
위 사이트로 가서 같이 소스코드를 다운로드 받아준다
OpenCV Extra Module 이라고 한다
CMake 3.18.3 - https://cmake.org/download/
Download | CMake
Current development distribution Each night binaries are created as part of the testing process. Other than passing all of the tests in CMake, this version of CMake should not be expected to work in a production environment. It is being produced so that us
cmake.org
여러 환경에서 제약사항없이 컴파일을 가능하게 해주는 착한 친구이지만, 난 맥이 아닌 윈도우에서 해보겠숴...
소스코드를 받지말고 Binary distributions 에서 윈도우용을 받아서 깔아주자
기타 : TBB, CUDA
TBB - https://github.com/oneapi-src/oneTBB
oneapi-src/oneTBB
Official Threading Building Blocks (TBB) GitHub repository. For Commercial Intel® TBB distribution, please click here: https://software.intel.com/en-us/tbb - oneapi-src/oneTBB
github.com
CUDA - https://developer.nvidia.com/cuda-download
CUDA Toolkit 11.1 Downloads
Join us online Oct. 5-9 for the GPU Technology Conference (GTC), featuring live and on-demand sessions, discounted NVIDIA Deep Learning Institute training, and the opportunity to connect with industry experts. Offerings this year include: GPU-Accelerated E
developer.nvidia.com
엔디비아를 사용하면 해주고 아니면 하지말자..
CMake 설정 및 빌드 시작
C 드라이브에 OpenCV_lib 라는 폴더를 만들어 그 안에서 관리하기로 했고 OpenCV_lib 안에는 폴더 두 개를 만들어주었다
- build : Cmake 에서 Genarate 한 파일들을 모아두는 곳
- source : 앞서 준비한 OpenCV 소스코드, OpenCV_contrib 두 저장소를 이 안에 넣어둔다
CMake를 실행해주면 창 하나가 뜨는데
- Where is your sourceCode : C:\OpenCV_lib\source\opencv-master\opencv-master ( CMakeLists 파일까지 )
- Where to build the binaries : C:\OpenCV_libs\build
Configure 버튼을 눌러준다.
Current Genarator 는 Visual Studio 16 2019로 해주었다
혼자서 막 잘하니까 기다리면 된다
빨간 부분이 생기는 것은 새로운 변경이 일어났거나 오류가 있는 부분이라고 하니 살펴보면 된다
여기서 OPENCV_EXTRA_MODUELS_PATH 는 OenCV_contrib의 경로로 해준다
가장 하단의 OPENCV_EXTRA_MODULES_PATH 확인 WITH에서 TBB ( Thread Buiding Block ) 와 CUDA가 체크 되어있는지 확인해준다
큰 데이터를 처리하지 않는 이상 Consistency 로 기본으로도 사용이 가능하다
TBB 관련 세팅 TBB 세팅 CUDA 세팅 마찬가지로 CUDA는 엔디비아를 사용할거면 해주자
Configuring done ! 설정이 다 되었으니 Generate를 눌러준다
Generating done ! 완료가 되면 build 폴더에 OpenCV 솔루션이 떨어져 있는데 실행을 해준다
ALL_BUILD 주목 ALL_BUILD가 활성화가 된 상태에서 64비트 기준으로 디버그, 릴리즈 두개 다 빌드해준다.
중간에 에러가 뜨면 보통 TBB가 include Directory에 빠져있다거나 해서 디버그, 릴리즈에 추가해주면서 한다
build\bin 에 보면 디버그, 릴리즈가 있으며 dll들이 있다
디버그에 떨어진 파일들은 [*][숫자][d].[확장자]
릴리즈에 떨어진 파일들은 [*][숫자].[확장자] 인 것을 확인할 수 있다
build\lib 에도 마찬가지로 lib 파일들이 존재하는 것을 볼 수 있다
opencv-master, opencv-contirb 의 헤더파일인 build\include 파일들이 필요한데 한 폴더에 모으기 힘드므로
INSTALL 프로젝트를 build Only 해서 릴리즈, 디버그 둘 다 빌드해준다
build\install 에서 확인이 되며 이것을 이용해서 프로젝트를 만들어준다
새 프로젝트를 만들고
프로젝트 속성에서 VC++ 디렉터리에서 포함 디렉터리에 C:\OpenCV_lib\install\include 를 추가하고
라이브러리 디렉터리에 C:\OpenCV_lib\build\install\x64\vc16\lib 도 추가했다
링커의 입력에서 기본으로 쓰게 되는 lib 파일들을 복사해서 새로 만든 프로젝트에 붙여넣기를 해주거나 환경설정을 통하여 만든 다음 해당 코드를 가지고 실행을 해보는 과정을 해보았다
#include <iostream> #include <stdio.h> #include <opencv2\opencv.hpp> #define _CRT_SECURE_NO_WARNING using namespace std; using namespace cv; int main() { VideoCapture capture(0); Mat frame; if (!capture.isOpened()) cout << "AVI file is not open." << endl; while (1) { capture >> frame; if (frame.empty()) break; Sobel(frame, frame, frame.depth(), 1, 0); imshow("w", frame); if (waitKey(10) > 0) break; } return 0; }
실행
잘 된다! 반응형'IT Tech > 찍어먹는 IT' 카테고리의 다른 글
[Laravel] 라라벨 8.x 설치 (0) 2020.11.10 [Docker] 도커(Docker) 란? (0) 2020.10.31 [ReactJS] Component Life Cycle method (0) 2020.09.29 [ReactJS] ReactJS App 만드는 방법 (0) 2020.09.27 시큐어 코딩 가이드 (0) 2020.09.27