Opencv For Mac

  1. Opencv Machine Learning Projects

Answer questionsMainasuK

We can install opencv for Python for Mac OS X with home-brew. I’ve worked with OpenCV version 3 on Windows and Ubuntu in the past, and did a single install in OSx a couple of years ago. If you landed here, you are probably working on a Mac based system,. Before we can compile OpenCV on our system, we first need to install Xcode, Apple’s set of software development tools for the Mac Operating System. The easiest method to download Xcode is to open up the App Store application on your desktop, search for “Xcode” in the search bar, and then click the “Get” button. At this point, you should have OpenCV 4 and Python installed on your Mac. We can write a small test program that will print the OpenCV version, load an image from the disk, convert the image to gray and show the result. Start by downloading the next image: Save it as clouds.jpg. The Open Source Computer Vision Library has 2500 algorithms, extensive documentation and sample code for real-time computer vision. It works on Windows, Linux, Mac OS X, Android, iOS in your browser through JavaScript.

@komakai The same error when building x86_64 on the DTK. And If the --archs set as arm64,x86_64. The arm64 part works. I guess the CAROTENE breaks cross build on the DTK after several times trying. I disable it and turn off NEON too. Then the x86_64 cross build works.

Disable NEON:In ./platforms/ios/build_framework.py

I use that command to make the universal framework without error../opencv-macos-universal-binary/platforms/osx/build_framework.py --archs=x86_64,arm64 ./opencv-framework-universal --contrib ./opencv_contrib-4.4.0 --enable_nonfree --disable CAROTENE 2>&1 tee ./opencv-framework-universal/DTK-build-universal.log

Framework and build log upload to Dropbox.

Check archs:

Maybe could disable CAROTENE and NEON for x86_64 build only. Because they are ARM only.

And I make a universal build for my side-project ImageReader with the universal framework. The app natively running on the DTK and Intel mac without any issue. Only crash when using Rosetta and that's doesn't matter.

Thanks a lot and I'm glad to help if needs building tests.(I can test the DTK build and Intel Big Sur Mac build. But not at the same time. The two machines locate the different places. Both can not mobile. But ASAP :D)

background

Recent research on image recognition codes——OpenCVIn order to facilitate debugging, it is necessary toMacBuild a debug on itc++The debugging environment of the program. I’ve run through and share it with you.

Environmental Science

  • Mac OS 10.14.5
  • xcode-select v2354
  • Visual Studio code 1.35.1
  • OpenCV 3.4.5
  • Clang 1001.0.46.4
  • CMake 3.14.5

Statement of steps

  1. Compilation environment preparation
  2. Install OpenCV
  3. Install VScode plug-ins
  4. VScode project configuration
  5. OpenCV HelloWorld

Environmental preparation

Mac has its own C/C++ environment, so I won’t dwell on it.

Xcode Command Line ToolsIt is necessary to trigger the installer from the command line or download the installation.

Command to install xcode-select
Download xcode-select installation

Apple Developer Download

Select the download file and note the version number prompted here!
Command line installation is slow and has a high failure rate. It is recommended to download it.dmgFile Installation

CMake preparation

CompileOpenCVIt should be used in time.cmake。 The same can be done byhomebrewOr download and install.
CMake installed in download mode, cmake executable program in/Applications/CMake.app/Contents/bin/cmake.

If you usehomebrewMode InstallationopencvSo CMake is not necessary.

Pkg-config installation

Compiler references includeopencvLibraryc/c++The code needs a lot of parameters to tell include path, libs, etc.pkg-configCompilation parameters can be simplified.

Opencv Machine Learning Projects

Install OpenCV

There are two ways to install.

brew install

After installation, it is best to configure these environment variables. (General command line will prompt you)

It’s easy to install with homebrew, but it takes a long time to install (I spent a big day). Python-opencv will also be installed.

Compile and install

Click to download the source code. Here I chooseSources 3.4.5

After decompression, enter the directory

Created herereleaseThe catalogue will be placedcmakeThe result of an order.CMAKE_INSTALL_PREFIXThe configured directory stores the results generated by the make command.

If there is no error, the installation will be successful.

Normally, there will be no problem. It is not necessarily successful in a virtual environment.

Install opencv with reference to self-compilation

Write a C++ Hello World

First, try writing a C++ code that only refers to the standard library.

The results are as follows.
No problem, just keep trying to introduce it into the code.OpenCVLibrary.

Pkg-config environment configuration

Once installed, configure an environment variable.

After configuring, execute the command:

The display is roughly as follows, and the content of this section is as follows.opencv.pcInside configuration.

This environmental variable is designed to allow forpkg-configCan findopencv.pcThis file.

Write an OpenCV Demo

Okay, here’s the point. Most people get stuck here.

Write aOpenCV HellowWorldTo try, open an empty VScode project and create
filetest.cpp

Enter the command line environment

Vision

pkg-configThis command introduces a class library for compiling opencv test code.

You can see the following results. Congratulations on your success.

Refer to the link at the end: Compile the self-test program

The actual debugging code will knock a lot of commands when it is compiled and run continuously, so we try to hand these tasks over to VScode. First install some plug-ins for VScode

  • C/C++
  • C++ Intellisense
  • C++ Clang Command Adapter

Create one under the root directory.vocodeFolder, create three more files.

  • .vscode/launch.json
  • .vscode/tasks.json
  • .vscode/c_cpp_properties.json

file.vscode/tasks.json

file.vscode/launch.json

file.vscode/c_cpp_properties.json

Click on the VScode menu barDebug > Start DebuggingThe results are as follows:

In order to facilitate debugging, I willlaunch.jsonOfexternalConsoleSet totrueThat would bevscodeIn addition, a new terminal running program may be authorized and agreed.

Common problem

  1. Errors caused by incorrect configuration of pkg-config

Solution:

Run the command to add a path

  1. Dyld Packet Dependency Problem

Solution:

Run the command to add a path

If you encounter problems, please leave a message.

Links to the original text. No reprint support!