Skip to content

ArijusGrotuzas/CVAlgorithms

Repository files navigation

CV Algorithms

A set of naive implementations of popular CV algorithms implemented in C++ using the OpenCV library. The examples below contain code snippets showcasing example use of algorithms.

Table of contents

Image thresholding

Original Binary
sudoku Binary
    // Convert the image to grayscale
    Mat gray(original.rows, original.cols, CV_8UC1, Scalar(0));
    CVAlg::grayscale(original, gray);

    //Binarize image
    Mat binary = CVAlg::threshold(gray, 125);

Image Transformations

Scaling

Original Scaled
butterfly Enlarged
    // Convert the image to grayscale
    Mat gray(original.rows, original.cols, CV_8UC1, Scalar(0));
    CVAlg::grayscale(original, gray);

    // Scale the image
    Mat scale = CVAlg::scaleMat(2.0, 2.0);
    Mat result = CVAlg::backwardMapping(gray, scale, 2, 2);

Rotation about Z axis

Original Rotated
chicky_512 Rotated
    // Convert the image to grayscale
    Mat gray(original.rows, original.cols, CV_8UC1, Scalar(0));
    CVAlg::grayscale(original, gray);

    // Rotate the image
    Mat rot = CVAlg::rotationMat(150.0);
    Mat trans = CVAlg::translateMat(500.0, 0.0);
    Mat combined = trans * rot;
    Mat result = CVAlg::backwardMapping(gray, combined, 2, 2);

Shearing

Original Sheared
fruits Sheared
    // Convert the image to grayscale
    Mat gray(original.rows, original.cols, CV_8UC1, Scalar(0));
    CVAlg::grayscale(original, gray);
    
    // Perform Shearing
    Mat shear = CVAlg::shearMat(0.0, 1.1);
    Mat sheared = CVAlg::backwardMapping(gray, shear, 1, 2.5);

    // Resize image
    Mat result;
    cv::resize(sheared, result, cv::Size(), 0.5, 0.5);

Gaussian Blurring

Original Blurred
messi5 Blurred
    // Convert the image to grayscale
    Mat gray(original.rows, original.cols, CV_8UC1, Scalar(0));
    CVAlg::grayscale(original, gray);
    
    // Blur the image
    Mat blurred = CVAlg::gausBlur(gray, 7, 2.0);

Sobel edge detection

Original Edges
board Edge
    // Convert the image to grayscale
    Mat gray(original.rows, original.cols, CV_8UC1, Scalar(0));
    CVAlg::grayscale(original, gray);

    // Extract edges
    Mat edges = CVAlg::sobelEdge(gray);

Features

Harris Corners Detector

Corners

    // Convert the image to grayscale
    Mat gray = CVAlg::grayscale(original);

    // Extract corners
    Mat corners = CVAlg::harrisCorners(gray, 7, 0.04);

    // Draw corners
    CVAlg::drawCorners(corners, original, 0.5, cv::Scalar(0, 0, 255), cv::MARKER_DIAMOND);

Shi-Tomasi Corners Detector

Corners

    // Convert the image to grayscale
    Mat gray = CVAlg::grayscale(original);

    // Extract corners
    Mat corners = CVAlg::shiTomasiCorners(gray, 5);

    // Draw corners
    CVAlg::drawCorners(corners, original, 0.65, cv::Scalar(0, 0, 255));