Learn from website:
https://sites.google.com/site/yonasstephenfyp2013/updates/tutorialinstallingopencvonmacosxmountainlion
Download opencv-4.0.1 compressed file and extract it, then go into it and build project.

mkdir opencv_build
cd opencv_build
cmake -G "Unix Makefiles" ../

Generate Makefile successfully:

-- Found JNI: /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/JavaVM.framework
-- Found VTK 8.1.1 (/usr/local/lib/cmake/vtk-8.1/UseVTK.cmake)
-- Looking for dlerror in dl
-- Looking for dlerror in dl - found
-- ADE: Download: v0.1.1d.zip
-- OpenCV Python: during development append to PYTHONPATH: /Users/weiyang/Downloads/opencv-4.0.1/opencv_build/python_loader
-- Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': /Users/weiyang/Downloads/opencv-4.0.1/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
-- opencv_dnn: filter out ocl4dnn source code
-- Performing Test HAVE_OBJCXX_FOBJC_EXCEPTIONS
-- Performing Test HAVE_OBJCXX_FOBJC_EXCEPTIONS - Success
-- Performing Test HAVE_CXX_WNO_OVERLOADED_VIRTUAL
-- Performing Test HAVE_CXX_WNO_OVERLOADED_VIRTUAL - Success
-- Performing Test HAVE_CXX_WNO_UNUSED_PRIVATE_FIELD
-- Performing Test HAVE_CXX_WNO_UNUSED_PRIVATE_FIELD - Success
--
-- General configuration for OpenCV 4.0.1 =====================================
//...
-- Install to: /usr/local
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/weiyang/Downloads/opencv-4.0.1/opencv_build

make

...
[100%] Linking CXX executable ../../bin/opencv_test_video
[100%] Built target opencv_test_video
[100%] Building CXX object modules/calib3d/CMakeFiles/opencv_test_calib3d.dir/test/test_undistort_badarg.cpp.o
[100%] Building CXX object modules/calib3d/CMakeFiles/opencv_test_calib3d.dir/test/test_undistort_points.cpp.o
[100%] Linking CXX executable ../../bin/opencv_perf_stitching
[100%] Built target opencv_perf_stitching
[100%] Linking CXX executable ../../bin/opencv_test_calib3d
[100%] Built target opencv_test_calib3d
[100%] Linking CXX executable ../../bin/opencv_perf_video
[100%] Built target opencv_perf_video
[100%] Linking CXX shared module ../../lib/cv2.so
[100%] Built target opencv_python2
[100%] Linking CXX shared module ../../lib/python3/cv2.cpython-36m-darwin.so
[100%] Built target opencv_python3

sudo make install

Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/include/opencv4/opencv2/cvconfig.h
-- Installing: /usr/local/include/opencv4/opencv2/opencv_modules.hpp
-- Installing: /usr/local/lib/cmake/opencv4/OpenCVModules.cmake
...
-- Installing: /usr/local/bin/setup_vars_opencv4.sh
-- Installing: /usr/local/share/opencv4/valgrind.supp
...
...
-- Installing: /usr/local/share/opencv4/lbpcascades/lbpcascade_silverware.xml
-- Installing: /usr/local/bin/opencv_annotation
-- Installing: /usr/local/bin/opencv_visualisation
-- Installing: /usr/local/bin/opencv_interactive-calibration
-- Installing: /usr/local/bin/opencv_version


My first project about OpenCV:
Use CMake to build project.
Refer to the tutorial:https://docs.opencv.org/2.4/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html
CMakeLists.txt

macro(use_cxx11)
  if (CMAKE_VERSION VERSION_LESS "3.1")
    if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
      set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
    endif ()
  else ()
    set (CMAKE_CXX_STANDARD 11)
  endif ()
endmacro(use_cxx11)

cmake_minimum_required(VERSION 2.8)
project( imageIOByOpenCV )
use_cxx11()
find_package( OpenCV REQUIRED )
add_executable( ${PROJECT_NAME} "main.cpp" )
target_link_libraries( ${PROJECT_NAME} ${OpenCV_LIBS} )

cpp code:

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, char** argv )
{
    Mat image;
    image = imread( "/Users/weiyang/Desktop/Untitled.png", 1 );

    if ( !image.data )
    {
        printf("No image data \n");
        return -1;
    }
    namedWindow("Display Image", WINDOW_AUTOSIZE );
    imshow("Display Image", image);

    waitKey(0);

    return 0;
}

Build and run successfully。
Close the window when we enter any character.

If we want to have a more advanced window based on Qt to show an image, we have to turn on the Qt option in CMake entries when building the whole project.


0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Content Summary
: Input your strings, the tool can get a brief summary of the content for you.

X
0
Would love your thoughts, please comment.x
()
x