Skip to content

Instantly share code, notes, and snippets.

@yohhoy
yohhoy / redgray.py
Last active November 14, 2015 12:53
Red-Gray image filter (a.k.a. "Apple-nize" filter)
#!/usr/bin/env python3
import cv2
import numpy as np
import sys
def hsv_mask(hsv, h_center, h_range, s_low, v_low):
h_low = (h_center - h_range) % 180
h_high = (h_center + h_range) % 180
h, s, v = cv2.split(hsv)
@yohhoy
yohhoy / fmt_ntpts.cpp
Created November 18, 2015 06:41
NTP Timestamp Format(64bit) to ISO 8601(extended format) + fraction
std::string fmt_ntpts(uint64_t ts)
{
// 1970/1/1(UNIT time epoch) - 1900/1/1(NTP timestamp epoch)
const uint32_t offset = (24u * 60 * 60) * 25567;
time_t t = (ts >> 32) - offset;
double d = (ts & 0xffffffff) / (double)(1ULL << 32);
char buf[256];
size_t n = std::strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", std::gmtime(&t));
std::sprintf(buf + n, "%f", d);
buf[n] = ' '; // force erase '0'
@yohhoy
yohhoy / ff2cv.cpp
Last active December 14, 2024 12:44
Read video frame with FFmpeg and convert to OpenCV image
/*
* Read video frame with FFmpeg and convert to OpenCV image
*
* Copyright (c) 2016 yohhoy
*/
#include <iostream>
#include <vector>
// FFmpeg
extern "C" {
#include <libavformat/avformat.h>
@yohhoy
yohhoy / cv2ff.cpp
Created February 17, 2016 15:41
Convert from OpenCV image and write movie with FFmpeg
/*
* Convert from OpenCV image and write movie with FFmpeg
*
* Copyright (c) 2016 yohhoy
*/
#include <iostream>
#include <vector>
// FFmpeg
extern "C" {
#include <libavformat/avformat.h>
@yohhoy
yohhoy / po3ooronize.py
Last active May 11, 2020 08:43
C++ source text converter for PO3OOrO.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
C++ source text converter for PO3OOrO.
Copyright (C) 2016 yohhoy.
PO3OORO: Enhancing the C++ Basic Character Set with Standard Character Mappings
https://isocpp.org/files/papers/PO3OOrO.pdf
Special thanks to http://emojipedia.org/
@yohhoy
yohhoy / jpegdot.py
Created April 16, 2016 08:32
"Pixel art saved with JPEG format" image filter
#!/usr/bin/env python3
import cv2
import numpy as np
import sys
def convert(infile, outfile):
src = cv2.imread(infile)
params = [int(cv2.IMWRITE_JPEG_QUALITY), 10]
_, jpeg = cv2.imencode('.jpg', src, params)
img = cv2.imdecode(jpeg, 1)
#!/bin/bash
# "hh:mm:ss" to seconds
function hms2sec() {
hh=$(( 10#`echo $1 | cut -c 1-2` ))
mm=$(( 10#`echo $1 | cut -c 4-5` ))
ss=$(( 10#`echo $1 | cut -c 7-8` ))
echo $(( $hh * 3600 + $mm * 60 + $ss ))
}
@yohhoy
yohhoy / isobmff.md
Last active December 12, 2023 14:27
ISO Base Media File Format

AAC

ISO/IEC 14496-3, 1.6.2.1 AudioSpecificConfig

AudioSpecificConfig() {
	audioObjectType = GetAudioObjectType();
	samplingFrequencyIndex; // 4 bslbf
	if (samplingFrequencyIndex == 0xf) {
		samplingFrequency; // 24 uimsbf
	}
@yohhoy
yohhoy / lwbs.hpp
Created September 27, 2016 09:58
lightweight bitstream parsing library
/*
* lwbs.hpp - lightweight bitstream parsing library
*
* Copyright (c) 2016 yohhoy
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://www.boost.org/LICENSE_1_0.txt)
*
* Requirement:
* - C++11 support
* - (u)int64_t support
@yohhoy
yohhoy / defer_block.hpp
Created October 5, 2016 08:38
Emulate 'defer' block
#include <memory>
namespace detail {
template <typename F>
std::shared_ptr<void> set_defer(F f)
{ return std::shared_ptr<void>(nullptr, [f](void*){ return f(); }); }
}
#define SET_DEFER_IMPL2(id_, f_) auto deferobj##id_ = detail::set_defer(f_)
#define SET_DEFER_IMPL1(id_, f_) SET_DEFER_IMPL2(id_, f_)