OpenCV - qtec/build-qt5022-core GitHub Wiki

Introduction

From the official OpenCV page:

OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in the commercial products.

The library has more than 2500 optimized algorithms, which includes a comprehensive set of both classic and state-of-the-art computer vision and machine learning algorithms. These algorithms can be used to detect and recognize faces, identify objects, classify human actions in videos, track camera movements, track moving objects, extract 3D models of objects, produce 3D point clouds from stereo cameras, stitch images together to produce a high resolution image of an entire scene, find similar images from an image database, remove red eyes from images taken using flash, follow eye movements, recognize scenery and establish markers to overlay it with augmented reality, etc.

It has C++, C, Python, Java and MATLAB interfaces and supports Windows, Linux, Android and Mac OS. OpenCV leans mostly towards real-time vision applications and takes advantage of MMX and SSE instructions when available. A full-featured CUDA and OpenCL interfaces are being actively developed right now. There are over 500 algorithms and about 10 times as many functions that compose or support those algorithms. OpenCV is written natively in C++ and has a templated interface that works seamlessly with STL containers.

Official Links

Official OpenCV page

Usage

The cameras come with the OpenCV packages pre-installed (v3.1).

Python

The easiest way to use OpenCV is through the Python interface.

Start by either:

  • Loading a saved image using cv2.imread():
import cv2
img = cv2.imread('test_img.jpg')
  • Or reading an image from the Video4Linux interface using the python v4l2wrapper function wrapper.capture():
import v4l2
from v4l2wrapper import create_device_wrapper
wrapper = create_device_wrapper()
img = wrapper.capture()

Now you can apply any desired mage processing functions, for example thresholding (note that thresholding requires greyscale images as input):

ret,thresh = cv2.threshold(img,127,255,cv2.THRESH_BINARY)

Note: remember to import the necessary packages if you have not done so already:

import cv2

Finally the result can be seen using cv2.imshow():

cv2.imshow('thresholded image', thresh )
cv2.waitKey(0)
cv2.destroyAllWindows()

C++

It is also possible to use OpenCV from the C++ interface.

Start by either:

  • Loading a saved image using cv::imread():
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>

cv::Mat img = cv::imread("test_img.jpg", cv::IMREAD_UNCHANGED );

Now you can apply any desired mage processing functions, for example thresholding (note that thresholding requires greyscale images as input):

Note: remember to include the necessary headers if you have not done so already:

#include "opencv2/imgproc/imgproc.hpp"
cv::Mat thres;
cv::threshold( img, thres, 127, 255, cv::THRESH_BINARY );

Finally the result can be seen using cv::imshow(): Note: remember to include the necessary headers if you have not done so already:

#include "opencv2/highgui/highgui.hpp"
cv::namedWindow( "thresholded image", cv::WINDOW_AUTOSIZE );
cv::imshow( "thresholded image", thres);
cv::waitKey(0);
⚠️ **GitHub.com Fallback** ⚠️