Skip to content

Instantly share code, notes, and snippets.

View leonmavr's full-sized avatar
🎯
Focusing

Leo Mav leonmavr

🎯
Focusing
View GitHub Profile
@leonmavr
leonmavr / tree_glp.c
Last active September 17, 2015 02:51
tree_glp is a function to get the last added parent in a balanced ordered heap
/*
takes the root of the tree, a new node
where the last parent will be written to,
a counter passed as 0, and max = inf
The recursions can be unwrapped in the
following pseudocode, based on Depth
First Search
visited = {}
@leonmavr
leonmavr / count_spaces.c
Created October 25, 2015 04:32
Count spaces in a file line
int count_spaces (FILE* f) {
int spaces = 0;
char chIn;
for ( chIn = '\0'; chIn != '\n'; spaces += ( chIn = fgetc(f) ) == ' ' );
return spaces;
}
cap = cv2.VideoCapture('datasets/gesture/test_02.mp4')
ret, old_frame = cap.read()
frame1 = old_frame
cropper = MouseRoi(frame1)
cropper.crop()
cropper.qimshow(cropper.get_cropped())
(c1,r1), (c0,r0) = cropper.clicks_xy
mask_roi = np.zeros(cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY).shape, np.uint8)
#!/usr/bin/env python
###
# Original: https://github.com/shantnu/Webcam-Face-Detect
import cv2
import sys
faceCascade = cv2.CascadeClassifier("../cascade/hand.xml")
video_capture = cv2.VideoCapture(0)
@leonmavr
leonmavr / CMakeLists.txt
Created March 9, 2021 14:46
CMake template for OpenCV project
# Based on: https://stackoverflow.com/a/36625937
cmake_minimum_required(VERSION 3.10)
project(opencvTest)
set(CMAKE_CXX_STANDARD 17)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(opencvTest opencv_test.cpp)
@leonmavr
leonmavr / webcam.py
Created May 6, 2021 19:14
Read from webcam in OpenCV - Python
import cv2
cap = cv2.VideoCapture(0)
# Check if the webcam is opened correctly
if not cap.isOpened():
raise IOError("Cannot open webcam")
while True:
valid, frame = cap.read()
@leonmavr
leonmavr / clouds.pde
Created September 8, 2021 21:17
Algorithm to draw clouds (Processing/Java)
float gaussian(float x, float std, float ampl) {
return ampl * 1/(std*sqrt(TWO_PI)) * exp(-1/2.0 * x/std * x/std);
}
float gaussianNonNrm(float x, float std, float ampl) {
//println(x);
return 1/(std*sqrt(TWO_PI)) * exp(-1/2.0 * x/std * x/std);
}
@leonmavr
leonmavr / gist:06f582e410d4d28e5f0dd93d989311cd
Created January 15, 2022 12:43
Python - this script's path and folder
this_script_path = os.path.abspath(__file__)
this_script_folder = os.path.dirname(this_script_path)
@leonmavr
leonmavr / hog.py
Last active April 10, 2022 14:57
Histogram of Oriented Gradients (HOG) implementation draft
import numpy as np
from cv2 import cv2
from typing import List, Union
import doctest
def update_histogram(grad_magn: float,
grad_angle: float,
angle_bins: List,
votes: Union[List, None] = None) -> List[float]:
"""update_histogram. Updates histogram of magnitudes (aka 'votes') vs
@leonmavr
leonmavr / main.cpp
Created October 13, 2022 22:27 — forked from omaraflak/main.cpp
Image convolution in C++ + Gaussian blur
#include <iostream>
#include <vector>
#include <assert.h>
#include <cmath>
#include <png++/png.hpp>
using namespace std;
typedef vector<double> Array;
typedef vector<Array> Matrix;