Skip to content

Instantly share code, notes, and snippets.

View PolarNick239's full-sized avatar

Nikolai Poliarnyi PolarNick239

View GitHub Profile
@PolarNick239
PolarNick239 / stitch_pdf.py
Last active August 30, 2017 10:25
PDF from images. Script downscales all jpg images and then merges them into pdfs with pdftk.
#!/usr/bin/python3.5
import os
import glob
import pathlib
from pathlib import Path
# How to use:
# Run in directory with folders named from 1 and up to 99. Each folder should contain *.JPG files.
# Script will downscale all files that are not yet downscaled to "downscaled" subdirectory and stitch to multiple pdfs: pdf per folder + single full pdf.
# Example of input directories:
@PolarNick239
PolarNick239 / atomic_cmpxchg_f32.cl
Last active January 27, 2018 19:41
OpenCL overload of atomic_cmpxchg and atomic_add for float
// See https://streamhpc.com/blog/2016-02-09/atomic-operations-for-floats-in-opencl-improved/
static float atomic_cmpxchg_f32(volatile __global float *p, float cmp, float val) {
union {
unsigned int u32;
float f32;
} cmp_union, val_union, old_union;
cmp_union.f32 = cmp;
val_union.f32 = val;
@PolarNick239
PolarNick239 / ps_install_ocv.sh
Last active March 27, 2018 00:24
OpenCV compilation script for python bundled with PhotoScan. Should work with any other Python (and with virtualenv). Tested on Ubuntu 16.04
# Configure path to photoscan:
PHOTOSCAN_PATH=<.../photoscan-pro>
PYTHON_PATH=${PHOTOSCAN_PATH}/python
OPENCV_VERSION=3.4.0
INSTALLATION_PATH=/opt/opencv-${OPENCV_VERSION}
sudo mkdir -p ${INSTALLATION_PATH}
# Install numpy (OpenCV requires it)
CPPFLAGS=-I${PYTHON_PATH}/include/python3.5m LDFLAGS=-L${PYTHON_PATH}/lib ${PYTHON_PATH}/bin/python3.5 -m pip install numpy==1.08
const int triangles[256][5*3+1] = {{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},{ 0, 4, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 5, 0, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 8, 9, 5, 8, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 1, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 0, 4, 8, 1, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 9, 11, 1, 9, 1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 8, 9, 11, 8, 11, 1, 8, 1, 4, -1, -1, -1, -1, -1, -1, -1},
{ 4, 1, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 10, 8, 0, 10, 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 5, 0, 9, 4, 1, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
import os
import time
import subprocess
from collections import namedtuple
def get_memory(key="total"):
# See https://doeidoei.wordpress.com/2009/03/22/python-tip-3-checking-available-ram-with-python/
if os.name == "posix":
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
public class Main {
public static void main(String[] args) throws InterruptedException {
import os
import time
def get_memory(key="total"):
key_to_index = {
"total": 1,
"used": 2,
"free": 3,
"shared": 4,
@PolarNick239
PolarNick239 / CMakeLists.txt
Created May 27, 2019 15:51
Optical flow video tracking with per-triplet consistency check, using calcOpticalFlowFarneback from OpenCV
cmake_minimum_required(VERSION 3.13)
project(video_optflow)
set(CMAKE_CXX_STANDARD 14)
find_package(OpenMP)
if (OpenMP_CXX_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
else()
@PolarNick239
PolarNick239 / benchmark.py
Last active June 18, 2019 11:39
Metashape benchmark for Dense Cloud and alignment
import Metashape
# wget https://www.dropbox.com/s/hh5yg0fmpr4bpn3/benchmarking_1.3.zip
# unzip benchmarking_1.3.zip
project = "benchmark2.psz"
Metashape.app.gpu_mask = (2 ** 16) - 1
Metashape.app.cpu_enable = False
Metashape.app.document.open(project, read_only=True)
--- a/PC/python.manifest
+++ b/PC/python.manifest
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
- <trustInfo>
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>