Install opencv4 in ubuntu 16
I knew this question has answers.Eventhough I tried different websites to install after performing installation to ensure the opencv version and library path,I compiled pkg-config... and pkg cflags... command,but console display as,
////Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found////
I need simple and easy steps with clear to install opencv4 in c++ IF anyone know guide me to install this one.
c++ opencv
New contributor
add a comment |
I knew this question has answers.Eventhough I tried different websites to install after performing installation to ensure the opencv version and library path,I compiled pkg-config... and pkg cflags... command,but console display as,
////Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found////
I need simple and easy steps with clear to install opencv4 in c++ IF anyone know guide me to install this one.
c++ opencv
New contributor
add a comment |
I knew this question has answers.Eventhough I tried different websites to install after performing installation to ensure the opencv version and library path,I compiled pkg-config... and pkg cflags... command,but console display as,
////Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found////
I need simple and easy steps with clear to install opencv4 in c++ IF anyone know guide me to install this one.
c++ opencv
New contributor
I knew this question has answers.Eventhough I tried different websites to install after performing installation to ensure the opencv version and library path,I compiled pkg-config... and pkg cflags... command,but console display as,
////Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found////
I need simple and easy steps with clear to install opencv4 in c++ IF anyone know guide me to install this one.
c++ opencv
c++ opencv
New contributor
New contributor
New contributor
asked 2 hours ago
karthika skarthika s
1
1
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Installing OpenCV4 on Ubuntu can be achieved in two ways:
- Through pre-built binaries which are already available in Ubuntu repositories
- By compiling it from the source
Section - I: Installing through pre-built Binaries
- You need to install the python-opencv package using the command:
$ sudo apt-get install python-opencv
- Open Python IDLE (or IPython) and execute the following codes in Python terminal:
import cv2 as cv
print(cv.__version__)
Note: - In here, you might not get the latest version. With respect to Python API, the latest version will always contain much better support and latest bug fixes.
So, if you wish to get the latest source codes, compile the source. Let's head over to the next section.
Section - II: Compiling from Source
- Installing Required Dependencies: We would use CMake to configure the installation, GCC for compilation, and lastly both the Python-devel and Numpy for building Python bindings etc. Here are the commands:
sudo apt-get install cmake
sudo apt-get install python-devel numpy
sudo apt-get install gcc gcc-c++
We also require GTK support for GUI features, Camera support (libv4l), Media Support (ffmpeg, gstreamer) etc. Execute the commands as follows:
sudo apt-get install gtk2-devel
sudo apt-get install libv4l-devel
sudo apt-get install ffmpeg-devel
sudo apt-get install gstreamer-plugins-base-devel
- Installing Optional Dependencies: It's not a mandate to install these dependencies. It totally depends on your requirements. In case you wish to install, execute these commands:
sudo apt-get install libpng-devel
sudo apt-get install libjpeg-turbo-devel
sudo apt-get install jasper-devel
sudo apt-get install openexr-devel
sudo apt-get install libtiff-devel
sudo apt-get install libwebp-devel
- Download OpenCV from the Github repository. Install Git using the commands:
$ sudo apt-get install git
$ git clone https://github.com/opencv/opencv.git
You will get a new folder - opencv in your current directory. Cloning might take some time, so have patience. Once done, open a new terminal window and navigate to the latest downloaded "opencv" folder. Create a new build folder and navigate to it:
$ mkdir build
$ cd build
- Configuration & Installation: Having all dependencies, we can finally install OpenCV. The installation has to be configured with CMake as it specifies which modules are to be installed, installation path, which additional libraries to be used, whether documentation and examples to be compiled etc. Most of this work is done automatically with well-configured default parameters.
You can use the following command to configure OpenCV library build (executed from build folder):
$ cmake ../
Note: OpenCV defaults assume "Release" build type and installation path is "/usr/local".
While the execution process is ON, you might notice these lines in your CMake output indicating that Python is properly found:
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 2.7.6)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.6)
-- numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.8.2)
-- packages path: lib/python2.7/dist-packages
--
-- Python 3:
-- Interpreter: /usr/bin/python3.4 (ver 3.4.3)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (ver 3.4.3)
-- numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.8.2)
-- packages path: lib/python3.4/dist-packages
Once done, you need to build the files using make command and install it using make install command:
$ make
# sudo make install
Your OpenCV is installed. You can find all your files in the "/usr/local/" folder. Open a terminal and try import "cv2":
import cv2 as cv
print(cv.__version__)
Section - III: Creating a C++ program
- Execute the following commands:
$ mkdir cpp_test
$ cd cpp_test
$ touch main.cpp
The above commands will create a folder called "cpp_test" and will also create a "main.cpp file" inside it.
Now place any .jpeg
image inside the cpp_test
folder.So Now your cpp_test folder will contain two files:
- Your Sample.jpeg file
Main.cpp file
- Now open your "Main.cpp" file and type the below given C++ program:
- Once done, you need to compile your code using the following command:
g++ main.cpp -o output
pkg-config --cflags --libs opencv
Note: Do include the ` given in the above command. Its a part of it.
- Post compilation, run your C++ program using the command:
$ ./output
Thank you for your answer. It is more useful.I need in c++
– karthika s
1 hour ago
Hello @karthikas I have edited my answer. It now includes the C++ code too for you to execute and test OpenCV with C++.
– Manu Mathur
56 mins ago
which step is common for c++ i want to use in c++ environment.
– karthika s
46 mins ago
Once you have installed OpenCV (either using Section - I or Section - II). You need to proceed with Section-III of the answer. That particular section helps you create a new C++ program and also compiles and executes it.
– Manu Mathur
31 mins ago
I want cmake format.I cant understand.
– karthika s
2 mins ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
karthika s is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1123955%2finstall-opencv4-in-ubuntu-16%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Installing OpenCV4 on Ubuntu can be achieved in two ways:
- Through pre-built binaries which are already available in Ubuntu repositories
- By compiling it from the source
Section - I: Installing through pre-built Binaries
- You need to install the python-opencv package using the command:
$ sudo apt-get install python-opencv
- Open Python IDLE (or IPython) and execute the following codes in Python terminal:
import cv2 as cv
print(cv.__version__)
Note: - In here, you might not get the latest version. With respect to Python API, the latest version will always contain much better support and latest bug fixes.
So, if you wish to get the latest source codes, compile the source. Let's head over to the next section.
Section - II: Compiling from Source
- Installing Required Dependencies: We would use CMake to configure the installation, GCC for compilation, and lastly both the Python-devel and Numpy for building Python bindings etc. Here are the commands:
sudo apt-get install cmake
sudo apt-get install python-devel numpy
sudo apt-get install gcc gcc-c++
We also require GTK support for GUI features, Camera support (libv4l), Media Support (ffmpeg, gstreamer) etc. Execute the commands as follows:
sudo apt-get install gtk2-devel
sudo apt-get install libv4l-devel
sudo apt-get install ffmpeg-devel
sudo apt-get install gstreamer-plugins-base-devel
- Installing Optional Dependencies: It's not a mandate to install these dependencies. It totally depends on your requirements. In case you wish to install, execute these commands:
sudo apt-get install libpng-devel
sudo apt-get install libjpeg-turbo-devel
sudo apt-get install jasper-devel
sudo apt-get install openexr-devel
sudo apt-get install libtiff-devel
sudo apt-get install libwebp-devel
- Download OpenCV from the Github repository. Install Git using the commands:
$ sudo apt-get install git
$ git clone https://github.com/opencv/opencv.git
You will get a new folder - opencv in your current directory. Cloning might take some time, so have patience. Once done, open a new terminal window and navigate to the latest downloaded "opencv" folder. Create a new build folder and navigate to it:
$ mkdir build
$ cd build
- Configuration & Installation: Having all dependencies, we can finally install OpenCV. The installation has to be configured with CMake as it specifies which modules are to be installed, installation path, which additional libraries to be used, whether documentation and examples to be compiled etc. Most of this work is done automatically with well-configured default parameters.
You can use the following command to configure OpenCV library build (executed from build folder):
$ cmake ../
Note: OpenCV defaults assume "Release" build type and installation path is "/usr/local".
While the execution process is ON, you might notice these lines in your CMake output indicating that Python is properly found:
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 2.7.6)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.6)
-- numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.8.2)
-- packages path: lib/python2.7/dist-packages
--
-- Python 3:
-- Interpreter: /usr/bin/python3.4 (ver 3.4.3)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (ver 3.4.3)
-- numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.8.2)
-- packages path: lib/python3.4/dist-packages
Once done, you need to build the files using make command and install it using make install command:
$ make
# sudo make install
Your OpenCV is installed. You can find all your files in the "/usr/local/" folder. Open a terminal and try import "cv2":
import cv2 as cv
print(cv.__version__)
Section - III: Creating a C++ program
- Execute the following commands:
$ mkdir cpp_test
$ cd cpp_test
$ touch main.cpp
The above commands will create a folder called "cpp_test" and will also create a "main.cpp file" inside it.
Now place any .jpeg
image inside the cpp_test
folder.So Now your cpp_test folder will contain two files:
- Your Sample.jpeg file
Main.cpp file
- Now open your "Main.cpp" file and type the below given C++ program:
- Once done, you need to compile your code using the following command:
g++ main.cpp -o output
pkg-config --cflags --libs opencv
Note: Do include the ` given in the above command. Its a part of it.
- Post compilation, run your C++ program using the command:
$ ./output
Thank you for your answer. It is more useful.I need in c++
– karthika s
1 hour ago
Hello @karthikas I have edited my answer. It now includes the C++ code too for you to execute and test OpenCV with C++.
– Manu Mathur
56 mins ago
which step is common for c++ i want to use in c++ environment.
– karthika s
46 mins ago
Once you have installed OpenCV (either using Section - I or Section - II). You need to proceed with Section-III of the answer. That particular section helps you create a new C++ program and also compiles and executes it.
– Manu Mathur
31 mins ago
I want cmake format.I cant understand.
– karthika s
2 mins ago
add a comment |
Installing OpenCV4 on Ubuntu can be achieved in two ways:
- Through pre-built binaries which are already available in Ubuntu repositories
- By compiling it from the source
Section - I: Installing through pre-built Binaries
- You need to install the python-opencv package using the command:
$ sudo apt-get install python-opencv
- Open Python IDLE (or IPython) and execute the following codes in Python terminal:
import cv2 as cv
print(cv.__version__)
Note: - In here, you might not get the latest version. With respect to Python API, the latest version will always contain much better support and latest bug fixes.
So, if you wish to get the latest source codes, compile the source. Let's head over to the next section.
Section - II: Compiling from Source
- Installing Required Dependencies: We would use CMake to configure the installation, GCC for compilation, and lastly both the Python-devel and Numpy for building Python bindings etc. Here are the commands:
sudo apt-get install cmake
sudo apt-get install python-devel numpy
sudo apt-get install gcc gcc-c++
We also require GTK support for GUI features, Camera support (libv4l), Media Support (ffmpeg, gstreamer) etc. Execute the commands as follows:
sudo apt-get install gtk2-devel
sudo apt-get install libv4l-devel
sudo apt-get install ffmpeg-devel
sudo apt-get install gstreamer-plugins-base-devel
- Installing Optional Dependencies: It's not a mandate to install these dependencies. It totally depends on your requirements. In case you wish to install, execute these commands:
sudo apt-get install libpng-devel
sudo apt-get install libjpeg-turbo-devel
sudo apt-get install jasper-devel
sudo apt-get install openexr-devel
sudo apt-get install libtiff-devel
sudo apt-get install libwebp-devel
- Download OpenCV from the Github repository. Install Git using the commands:
$ sudo apt-get install git
$ git clone https://github.com/opencv/opencv.git
You will get a new folder - opencv in your current directory. Cloning might take some time, so have patience. Once done, open a new terminal window and navigate to the latest downloaded "opencv" folder. Create a new build folder and navigate to it:
$ mkdir build
$ cd build
- Configuration & Installation: Having all dependencies, we can finally install OpenCV. The installation has to be configured with CMake as it specifies which modules are to be installed, installation path, which additional libraries to be used, whether documentation and examples to be compiled etc. Most of this work is done automatically with well-configured default parameters.
You can use the following command to configure OpenCV library build (executed from build folder):
$ cmake ../
Note: OpenCV defaults assume "Release" build type and installation path is "/usr/local".
While the execution process is ON, you might notice these lines in your CMake output indicating that Python is properly found:
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 2.7.6)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.6)
-- numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.8.2)
-- packages path: lib/python2.7/dist-packages
--
-- Python 3:
-- Interpreter: /usr/bin/python3.4 (ver 3.4.3)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (ver 3.4.3)
-- numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.8.2)
-- packages path: lib/python3.4/dist-packages
Once done, you need to build the files using make command and install it using make install command:
$ make
# sudo make install
Your OpenCV is installed. You can find all your files in the "/usr/local/" folder. Open a terminal and try import "cv2":
import cv2 as cv
print(cv.__version__)
Section - III: Creating a C++ program
- Execute the following commands:
$ mkdir cpp_test
$ cd cpp_test
$ touch main.cpp
The above commands will create a folder called "cpp_test" and will also create a "main.cpp file" inside it.
Now place any .jpeg
image inside the cpp_test
folder.So Now your cpp_test folder will contain two files:
- Your Sample.jpeg file
Main.cpp file
- Now open your "Main.cpp" file and type the below given C++ program:
- Once done, you need to compile your code using the following command:
g++ main.cpp -o output
pkg-config --cflags --libs opencv
Note: Do include the ` given in the above command. Its a part of it.
- Post compilation, run your C++ program using the command:
$ ./output
Thank you for your answer. It is more useful.I need in c++
– karthika s
1 hour ago
Hello @karthikas I have edited my answer. It now includes the C++ code too for you to execute and test OpenCV with C++.
– Manu Mathur
56 mins ago
which step is common for c++ i want to use in c++ environment.
– karthika s
46 mins ago
Once you have installed OpenCV (either using Section - I or Section - II). You need to proceed with Section-III of the answer. That particular section helps you create a new C++ program and also compiles and executes it.
– Manu Mathur
31 mins ago
I want cmake format.I cant understand.
– karthika s
2 mins ago
add a comment |
Installing OpenCV4 on Ubuntu can be achieved in two ways:
- Through pre-built binaries which are already available in Ubuntu repositories
- By compiling it from the source
Section - I: Installing through pre-built Binaries
- You need to install the python-opencv package using the command:
$ sudo apt-get install python-opencv
- Open Python IDLE (or IPython) and execute the following codes in Python terminal:
import cv2 as cv
print(cv.__version__)
Note: - In here, you might not get the latest version. With respect to Python API, the latest version will always contain much better support and latest bug fixes.
So, if you wish to get the latest source codes, compile the source. Let's head over to the next section.
Section - II: Compiling from Source
- Installing Required Dependencies: We would use CMake to configure the installation, GCC for compilation, and lastly both the Python-devel and Numpy for building Python bindings etc. Here are the commands:
sudo apt-get install cmake
sudo apt-get install python-devel numpy
sudo apt-get install gcc gcc-c++
We also require GTK support for GUI features, Camera support (libv4l), Media Support (ffmpeg, gstreamer) etc. Execute the commands as follows:
sudo apt-get install gtk2-devel
sudo apt-get install libv4l-devel
sudo apt-get install ffmpeg-devel
sudo apt-get install gstreamer-plugins-base-devel
- Installing Optional Dependencies: It's not a mandate to install these dependencies. It totally depends on your requirements. In case you wish to install, execute these commands:
sudo apt-get install libpng-devel
sudo apt-get install libjpeg-turbo-devel
sudo apt-get install jasper-devel
sudo apt-get install openexr-devel
sudo apt-get install libtiff-devel
sudo apt-get install libwebp-devel
- Download OpenCV from the Github repository. Install Git using the commands:
$ sudo apt-get install git
$ git clone https://github.com/opencv/opencv.git
You will get a new folder - opencv in your current directory. Cloning might take some time, so have patience. Once done, open a new terminal window and navigate to the latest downloaded "opencv" folder. Create a new build folder and navigate to it:
$ mkdir build
$ cd build
- Configuration & Installation: Having all dependencies, we can finally install OpenCV. The installation has to be configured with CMake as it specifies which modules are to be installed, installation path, which additional libraries to be used, whether documentation and examples to be compiled etc. Most of this work is done automatically with well-configured default parameters.
You can use the following command to configure OpenCV library build (executed from build folder):
$ cmake ../
Note: OpenCV defaults assume "Release" build type and installation path is "/usr/local".
While the execution process is ON, you might notice these lines in your CMake output indicating that Python is properly found:
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 2.7.6)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.6)
-- numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.8.2)
-- packages path: lib/python2.7/dist-packages
--
-- Python 3:
-- Interpreter: /usr/bin/python3.4 (ver 3.4.3)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (ver 3.4.3)
-- numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.8.2)
-- packages path: lib/python3.4/dist-packages
Once done, you need to build the files using make command and install it using make install command:
$ make
# sudo make install
Your OpenCV is installed. You can find all your files in the "/usr/local/" folder. Open a terminal and try import "cv2":
import cv2 as cv
print(cv.__version__)
Section - III: Creating a C++ program
- Execute the following commands:
$ mkdir cpp_test
$ cd cpp_test
$ touch main.cpp
The above commands will create a folder called "cpp_test" and will also create a "main.cpp file" inside it.
Now place any .jpeg
image inside the cpp_test
folder.So Now your cpp_test folder will contain two files:
- Your Sample.jpeg file
Main.cpp file
- Now open your "Main.cpp" file and type the below given C++ program:
- Once done, you need to compile your code using the following command:
g++ main.cpp -o output
pkg-config --cflags --libs opencv
Note: Do include the ` given in the above command. Its a part of it.
- Post compilation, run your C++ program using the command:
$ ./output
Installing OpenCV4 on Ubuntu can be achieved in two ways:
- Through pre-built binaries which are already available in Ubuntu repositories
- By compiling it from the source
Section - I: Installing through pre-built Binaries
- You need to install the python-opencv package using the command:
$ sudo apt-get install python-opencv
- Open Python IDLE (or IPython) and execute the following codes in Python terminal:
import cv2 as cv
print(cv.__version__)
Note: - In here, you might not get the latest version. With respect to Python API, the latest version will always contain much better support and latest bug fixes.
So, if you wish to get the latest source codes, compile the source. Let's head over to the next section.
Section - II: Compiling from Source
- Installing Required Dependencies: We would use CMake to configure the installation, GCC for compilation, and lastly both the Python-devel and Numpy for building Python bindings etc. Here are the commands:
sudo apt-get install cmake
sudo apt-get install python-devel numpy
sudo apt-get install gcc gcc-c++
We also require GTK support for GUI features, Camera support (libv4l), Media Support (ffmpeg, gstreamer) etc. Execute the commands as follows:
sudo apt-get install gtk2-devel
sudo apt-get install libv4l-devel
sudo apt-get install ffmpeg-devel
sudo apt-get install gstreamer-plugins-base-devel
- Installing Optional Dependencies: It's not a mandate to install these dependencies. It totally depends on your requirements. In case you wish to install, execute these commands:
sudo apt-get install libpng-devel
sudo apt-get install libjpeg-turbo-devel
sudo apt-get install jasper-devel
sudo apt-get install openexr-devel
sudo apt-get install libtiff-devel
sudo apt-get install libwebp-devel
- Download OpenCV from the Github repository. Install Git using the commands:
$ sudo apt-get install git
$ git clone https://github.com/opencv/opencv.git
You will get a new folder - opencv in your current directory. Cloning might take some time, so have patience. Once done, open a new terminal window and navigate to the latest downloaded "opencv" folder. Create a new build folder and navigate to it:
$ mkdir build
$ cd build
- Configuration & Installation: Having all dependencies, we can finally install OpenCV. The installation has to be configured with CMake as it specifies which modules are to be installed, installation path, which additional libraries to be used, whether documentation and examples to be compiled etc. Most of this work is done automatically with well-configured default parameters.
You can use the following command to configure OpenCV library build (executed from build folder):
$ cmake ../
Note: OpenCV defaults assume "Release" build type and installation path is "/usr/local".
While the execution process is ON, you might notice these lines in your CMake output indicating that Python is properly found:
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 2.7.6)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.6)
-- numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.8.2)
-- packages path: lib/python2.7/dist-packages
--
-- Python 3:
-- Interpreter: /usr/bin/python3.4 (ver 3.4.3)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (ver 3.4.3)
-- numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.8.2)
-- packages path: lib/python3.4/dist-packages
Once done, you need to build the files using make command and install it using make install command:
$ make
# sudo make install
Your OpenCV is installed. You can find all your files in the "/usr/local/" folder. Open a terminal and try import "cv2":
import cv2 as cv
print(cv.__version__)
Section - III: Creating a C++ program
- Execute the following commands:
$ mkdir cpp_test
$ cd cpp_test
$ touch main.cpp
The above commands will create a folder called "cpp_test" and will also create a "main.cpp file" inside it.
Now place any .jpeg
image inside the cpp_test
folder.So Now your cpp_test folder will contain two files:
- Your Sample.jpeg file
Main.cpp file
- Now open your "Main.cpp" file and type the below given C++ program:
- Once done, you need to compile your code using the following command:
g++ main.cpp -o output
pkg-config --cflags --libs opencv
Note: Do include the ` given in the above command. Its a part of it.
- Post compilation, run your C++ program using the command:
$ ./output
edited 1 hour ago
answered 1 hour ago
Manu MathurManu Mathur
39629
39629
Thank you for your answer. It is more useful.I need in c++
– karthika s
1 hour ago
Hello @karthikas I have edited my answer. It now includes the C++ code too for you to execute and test OpenCV with C++.
– Manu Mathur
56 mins ago
which step is common for c++ i want to use in c++ environment.
– karthika s
46 mins ago
Once you have installed OpenCV (either using Section - I or Section - II). You need to proceed with Section-III of the answer. That particular section helps you create a new C++ program and also compiles and executes it.
– Manu Mathur
31 mins ago
I want cmake format.I cant understand.
– karthika s
2 mins ago
add a comment |
Thank you for your answer. It is more useful.I need in c++
– karthika s
1 hour ago
Hello @karthikas I have edited my answer. It now includes the C++ code too for you to execute and test OpenCV with C++.
– Manu Mathur
56 mins ago
which step is common for c++ i want to use in c++ environment.
– karthika s
46 mins ago
Once you have installed OpenCV (either using Section - I or Section - II). You need to proceed with Section-III of the answer. That particular section helps you create a new C++ program and also compiles and executes it.
– Manu Mathur
31 mins ago
I want cmake format.I cant understand.
– karthika s
2 mins ago
Thank you for your answer. It is more useful.I need in c++
– karthika s
1 hour ago
Thank you for your answer. It is more useful.I need in c++
– karthika s
1 hour ago
Hello @karthikas I have edited my answer. It now includes the C++ code too for you to execute and test OpenCV with C++.
– Manu Mathur
56 mins ago
Hello @karthikas I have edited my answer. It now includes the C++ code too for you to execute and test OpenCV with C++.
– Manu Mathur
56 mins ago
which step is common for c++ i want to use in c++ environment.
– karthika s
46 mins ago
which step is common for c++ i want to use in c++ environment.
– karthika s
46 mins ago
Once you have installed OpenCV (either using Section - I or Section - II). You need to proceed with Section-III of the answer. That particular section helps you create a new C++ program and also compiles and executes it.
– Manu Mathur
31 mins ago
Once you have installed OpenCV (either using Section - I or Section - II). You need to proceed with Section-III of the answer. That particular section helps you create a new C++ program and also compiles and executes it.
– Manu Mathur
31 mins ago
I want cmake format.I cant understand.
– karthika s
2 mins ago
I want cmake format.I cant understand.
– karthika s
2 mins ago
add a comment |
karthika s is a new contributor. Be nice, and check out our Code of Conduct.
karthika s is a new contributor. Be nice, and check out our Code of Conduct.
karthika s is a new contributor. Be nice, and check out our Code of Conduct.
karthika s is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1123955%2finstall-opencv4-in-ubuntu-16%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown