diff --git a/Install-OpenCV-4-on-Ubuntu-from-source/CMakeLists.txt b/Install-OpenCV-4-on-Ubuntu-from-source/CMakeLists.txt new file mode 100755 index 000000000..12b17d7fa --- /dev/null +++ b/Install-OpenCV-4-on-Ubuntu-from-source/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 2.8.12) + +PROJECT(Project) + +SET(OpenCV_DIR /path/to/opencv/config) +find_package(OpenCV REQUIRED) + +include_directories(${OpenCV_INCLUDE_DIRS}) + +MACRO(add_example name) + ADD_EXECUTABLE(${name} ${name}.cpp) + TARGET_LINK_LIBRARIES(${name} ${OpenCV_LIBS}) +ENDMACRO() + +add_example(sampleCode) diff --git a/Install-OpenCV-4-on-Ubuntu-from-source/README.md b/Install-OpenCV-4-on-Ubuntu-from-source/README.md new file mode 100755 index 000000000..5bb16901f --- /dev/null +++ b/Install-OpenCV-4-on-Ubuntu-from-source/README.md @@ -0,0 +1,30 @@ +# Code for Install OpenCV 4 on Ubuntu from source + +This repository contains the sample code for [Install OpenCV 4 on Ubuntu from source](https://learnopencv.com/install-opencv-4-on-ubuntu-18-04/) + +## Run Code: + +### C++ +``` +mkdir build +cd build +cmake .. +cmake --build . --config Release +cd .. +./build/sampleCode +``` + +### Python +``` +python sampleCode.py +``` + +# AI Courses by OpenCV + +Want to become an expert in AI? [AI Courses by OpenCV](https://opencv.org/courses/) is a great place to start. + + +

+ +

+
diff --git a/Install-OpenCV-4-on-Ubuntu-from-source/boy.jpg b/Install-OpenCV-4-on-Ubuntu-from-source/boy.jpg new file mode 100644 index 000000000..67ef6802c Binary files /dev/null and b/Install-OpenCV-4-on-Ubuntu-from-source/boy.jpg differ diff --git a/Install-OpenCV-4-on-Ubuntu-from-source/sampleCode.cpp b/Install-OpenCV-4-on-Ubuntu-from-source/sampleCode.cpp new file mode 100755 index 000000000..a52d413fe --- /dev/null +++ b/Install-OpenCV-4-on-Ubuntu-from-source/sampleCode.cpp @@ -0,0 +1,26 @@ +#include +#include + +using namespace std; +using namespace cv; + +int main(int argc, char **argv) +{ + // Print OpenCV Version + cout << CV_VERSION << endl; + + // Read image + Mat image = imread("boy.jpg", 1); + + // Convert image to grayscale + cvtColor(image, image, COLOR_BGR2GRAY); + + // Display image + imshow("Display", image); + waitKey(0); + + // Save grayscale image + imwrite("boyGray.jpg",image); + + return 0; +} diff --git a/Install-OpenCV-4-on-Ubuntu-from-source/sampleCode.py b/Install-OpenCV-4-on-Ubuntu-from-source/sampleCode.py new file mode 100755 index 000000000..75b81216e --- /dev/null +++ b/Install-OpenCV-4-on-Ubuntu-from-source/sampleCode.py @@ -0,0 +1,17 @@ +import cv2 as cv + +# Print OpenCV Version +print(cv.__version__) + +# Read image +image = cv.imread("boy.jpg", 1) + +# Convert image to grayscale +image = cv.cvtColor(image, cv.COLOR_BGR2GRAY) + +# Display image +cv.imshow("Display", image) +cv.waitKey(0) + +# Save grayscale image +cv.imwrite("boyGray.jpg",image) diff --git a/README.md b/README.md index 7c33dc275..8033066e8 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ Want to become an expert in AI? [AI Courses by OpenCV](https://opencv.org/course |[Install OpenCV 4 on Windows (C++ and Python)](https://www.learnopencv.com/install-opencv-4-on-windows/) | [Code](https://github.com/spmallick/learnopencv/tree/master/InstallScripts/Windows-4) | |[Hand Keypoint Detection using Deep Learning and OpenCV](https://www.learnopencv.com/hand-keypoint-detection-using-deep-learning-and-opencv/) | [Code](https://github.com/spmallick/learnopencv/tree/master/HandPose)| |[Deep learning based Object Detection and Instance Segmentation using Mask R-CNN in OpenCV (Python / C++)](https://www.learnopencv.com/deep-learning-based-object-detection-and-instance-segmentation-using-mask-r-cnn-in-opencv-python-c/) | [Code](https://github.com/spmallick/learnopencv/tree/master/Mask-RCNN) | -|[Install OpenCV 4 on Ubuntu 18.04 (C++ and Python)](https://www.learnopencv.com/install-opencv-4-on-ubuntu-18-04/) | [Code](https://github.com/spmallick/learnopencv/blob/master/InstallScripts/installOpenCV-4-on-Ubuntu-18-04.sh) | +|[Install OpenCV 4 on Ubuntu (C++ and Python)](https://www.learnopencv.com/install-opencv-4-on-ubuntu-18-04/) | [Code](https://github.com/spmallick/learnopencv/blob/master/Install-OpenCV-4-on-Ubuntu-from-source) | |[Install OpenCV 4 on Ubuntu 16.04 (C++ and Python)](https://www.learnopencv.com/install-opencv-4-on-ubuntu-16-04/) | [Code](https://github.com/spmallick/learnopencv/blob/master/InstallScripts/installOpenCV-4-on-Ubuntu-16-04.sh) | |[Multi-Person Pose Estimation in OpenCV using OpenPose](https://www.learnopencv.com/multi-person-pose-estimation-in-opencv-using-openpose/) | [Code](https://github.com/spmallick/learnopencv/tree/master/OpenPose-Multi-Person) | |[Heatmap for Logo Detection using OpenCV (Python)](https://www.learnopencv.com/heatmap-for-logo-detection-using-opencv-python/) | [Code](https://github.com/spmallick/learnopencv/tree/master/heatmap)|