Skip to content

Instantly share code, notes, and snippets.

View mcarletti's full-sized avatar

Marco Carletti mcarletti

View GitHub Profile
@mcarletti
mcarletti / http_server_auth.py
Created January 9, 2024 11:00
Share a folder to the local network in Python. Features: credentials, timeout.
# With this script you can easily share a folder from your PC to the local network.
# The script creates an HTTP server protected by credentials. Basic auth only: encryption certificate not included.
# The server stops after a timeout is triggered (default: 1h).
#
# Example
# -------
# python http_server_auth.py --username u53r --password p4Sw0rd --directory ~/Public
#
# Anyone on the local network can access your Public folder in your home, typing your local address+port in a browser (eg. 157.27.93.172:8000).
#
@mcarletti
mcarletti / samsung_a3_camera_calib_front.yml
Created February 25, 2020 16:10
Samsung A3 front camera calibration using OpenCV (ChArUco board)
# Samsung A3
# Front camera: 8 MP, f/2.4, 31mm (standard), AF
width: 4128
height: 2322
focal: 3.6
rms: 1.6153361028439144
camera_mtx:
@mcarletti
mcarletti / build_opencv.sh
Last active February 8, 2024 15:43
Compile OpenCV from source
#!/bin/bash
# Tested on
# ------------------------------
# OS Ubuntu 18.04
# Platform x86_64, aarch64
# Python 3.6
if [ $# != 1 ]; then
echo -e "Usage:\n\t./build_opencv.sh VERSION\n\nExample:\n\t./build_opencv.sh 4.2.0"
def load_nv12_as_bgr(filename, shape, dtype=np.uint8):
with open(filename, "rb") as fp:
data = fp.read()
image = np.frombuffer(data, dtype=dtype).reshape(shape)
image = cv2.cvtColor(image, cv2.COLOR_YUV2BGR_NV12)
return image

How to Valgrind

Install

sudo apt update
sudo apt install valgrind

Write code

hello_valgrind.c

@mcarletti
mcarletti / auto_mount_instructions.md
Last active February 8, 2024 15:43
Instructions to mount at boot time an external disk on Ubuntu

Auto mount at boot time

Tested on Ubuntu 18.04.

Retrieve UUID

First of all, try with the command blkid (man: locate/print block device attributes) to show the UUID of the disk you want to mount. For example:

blkid /dev/nvme0n1
@mcarletti
mcarletti / grep_in_files.sh
Created November 20, 2019 11:13
Search for a pattern (string) in all files
#!/bin/bash
EXTENSION=$1
PATTERN=$2
grep --include="*.${EXTENSION}" -nRHI "${PATTERN}" *
@mcarletti
mcarletti / cvtRGB2YUV.m
Created November 11, 2019 14:00
RGB-YUV color conversion (Matlab code)
function [Y,U,V] = cvtRGB2YUV(R,G,B)
R = double(R);
G = double(G);
B = double(B);
Y = 0.257 * R + 0.504 * G + 0.098 * B + 16;
U = -0.148 * R - 0.291 * G + 0.439 * B + 128;
V = 0.439 * R - 0.368 * G - 0.071 * B + 128;
@mcarletti
mcarletti / cvutils.cpp
Last active February 8, 2024 15:43
Set of Qt / OpenCV snippets
/*
* Convert a cv::Mat frame to a QPixmap and show it in a Qt object.
*
* Parameters
* ----------
* frame : cv::Mat
* Input image in BGR format.
*/
void updateImageFrameToQLabel(cv::Mat& frame)
{
@mcarletti
mcarletti / create_wordcloud.py
Last active March 7, 2024 11:35
Parse main CVF conference titles and abstracts (eg, CVPR, ICCV)
import sys
import numpy as np
import matplotlib.pyplot as plt
from wordcloud import WordCloud
filename = sys.argv[1]
print(filename)
text = open(filename, "r").read()