Skip to content

Instantly share code, notes, and snippets.

View Xonxt's full-sized avatar

Nikita Kovalenko Xonxt

View GitHub Profile
@Xonxt
Xonxt / flatmap.py
Last active January 30, 2023 15:11
Python map-reduce
def flat_map(iterable: list, map_function=None):
"""Applies a `map_function` to every element of the `iterable` input list
and then flattens all the results into a new list
Args:
iterable (list): An input list
map_function (callable, optional): A function that is applied to every element of the input list. Defaults to None.
Returns:
list: A new list
@Xonxt
Xonxt / mpi_opencv_image_processing.cpp
Last active April 12, 2023 18:25
This is an example of using the MPI interface to parallelise basic image processing. An image is loaded with OpenCV and then distributed between several processes using MPI_Scatter. A simple example of image-partition processing is given. The image parts are then gathered into one final image using MPI_Gather.
#include <iostream>
#include "mpi.h"
#include "opencv2/opencv.hpp"
int main(int argc, char** argv)
{
// the input image
cv::Mat image;
@Xonxt
Xonxt / opencv_text_rendering.py
Last active October 6, 2020 20:44
A function, that allows more flexibility when rendering text with OpenCV in Python. You can add text outline, draw a list of strings with just one call, and even align the text block horizontally or vertically relative to an anchor point.
import numpy as np
import cv2
from enum import Enum
class Align(Enum):
LEFT = 0
CENTER = 1
RIGHT = 2
class Valign(Enum):
@Xonxt
Xonxt / main.cpp
Last active February 24, 2023 02:03
Sending a cv::Mat from C++ to a Python script
/*
This requires adding the "include" directory of your Python installation to the include diretories
of your project, e.g., in Visual Studio you'd add `C:\Program Files\Python36\include`.
You also need to add the 'include' directory of your NumPy package, e.g.
`C:\Program Files\PythonXX\Lib\site-packages\numpy\core\include`.
Additionally, you need to link your "python3#.lib" library, e.g. `C:\Program Files\Python3X\libs\python3X.lib`.
*/
// python bindings