0% found this document useful (0 votes)
14 views

Opencv Macos

This document provides steps to install OpenCV on Mac for use in Xcode projects: 1. Install Homebrew and use it to install OpenCV 2. Create a new Xcode command line tool C++ project 3. Add the OpenCV dynamic library files and header search paths to the project 4. Enable access to resources and camera by adding entries to the project's info.plist file 5. Provide code samples to test reading images from the resources folder and accessing the camera
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Opencv Macos

This document provides steps to install OpenCV on Mac for use in Xcode projects: 1. Install Homebrew and use it to install OpenCV 2. Create a new Xcode command line tool C++ project 3. Add the OpenCV dynamic library files and header search paths to the project 4. Enable access to resources and camera by adding entries to the project's info.plist file 5. Provide code samples to test reading images from the resources folder and accessing the camera
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

0% COMPLETE 0/19 Steps Hello,

! Previous Topic Mark Complete " albertoperdomo2!

$ OpenCV C++
Mac
!

Video Tutorial
OpenCV C++ < Installations – Windows and Mac < Mac IN PROGRESS

Installations – Windows and Mac


#
#
2 Topics
Step 1 – Install Homebrew
1 https://brew.sh/
Windows 2 Go to the website and copy the link and paste in the terminal to install.

Step 2 – Install Opencv


Mac

Code – Lessons 1 Go to terminal and type


2
# 8 Topics
#
3 brew install opencv
4

Code – Projects
# 4 Topics
# Step 3 – Create New Xcode Project
1 Open X code and create a "macOS" - "Command Line Tool" - "C++"
Download Resources 2

Step 4 – Add Dynamic Libraries


1 Right Click Project folder and "Add Files to ..."
2
3 Press forward slash "/" on keyboard to type the folder path
4
5 /usr/local/Cellar/opencv
6
7 open your version folder and go to lib and select all Dynamic Libraries
8

Step 5 – Add Header Search Path


1 Select your project folder and go to "Build settings"
2
3 Select All and Combined
4
5 Search for "Header Search Paths"
6
7 Double click and enter the path (make sure to change your version)
8
9 /usr/local/Cellar/opencv/4.5.0_5/include/opencv4
10
11 make it recursive

Step 6 – To enable Resources folder access


1 Edit Scheme
2
3 check "Use custom working director"
4
5 Select your project folder

Test Code

1 #include <opencv2/imgcodecs.hpp>
2 #include <opencv2/highgui.hpp>
3 #include <opencv2/imgproc.hpp>
4 #include <iostream>
5
6 using namespace cv;
7 using namespace std;
8
9
10 ///////////////// Images //////////////////////
11
12 int main() {
13
14 string path = "Resources/test.png";
15 Mat img = imread(path);
16 imshow("Image", img);
17 waitKey(0);
18 return 0;
19 }

Step 7 – To enable Camera Access


File - New - File
Select "Property List" in "Resources"

Add new
Item: NSCameraUsageDescription
Value: $(PRODUCT_NAME) camera use

Open Products folder and right click on the file with your project name and
show in finder.

Drag your info.plist file to this folder.

TEST CODE

1 #include <opencv2/imgcodecs.hpp>
2 #include <opencv2/highgui.hpp>
3 #include <opencv2/imgproc.hpp>
4 #include <iostream>
5
6 using namespace cv;
7 using namespace std;
8
9 ///////////////// Webcam //////////////////////
10
11 int main() {
12
13 VideoCapture cap(1);
14 Mat img;
15
16 while (true) {
17
18 cap.read(img);
19 imshow("Image", img);
20 waitKey(1);
21
22 }
23 return 0;
24 }

! Previous Topic Mark Complete "


Back to Lesson

You might also like