Skip to content

Instantly share code, notes, and snippets.

View Saafke's full-sized avatar
🖥️
Training...

Xavier Weber Saafke

🖥️
Training...
View GitHub Profile
@Saafke
Saafke / gsoc19_dnn_superres.md
Last active March 28, 2022 13:55
[GSoC '19] Learning-based Super-Resolution in OpenCV

Google Summer of Code 2019 with OpenCV

Learning-based Super Resolution

Student: Xavier Weber
Mentors: Vladimir Tyan & Yida Wang
Student on the same project: Fanny Monori

Link to accomplished work:

@Saafke
Saafke / code.cpp
Last active March 17, 2020 19:24
Code for SR
#include <opencv2/dnn_superres.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
using namespace cv;
using namespace dnn;
using namespace dnn_superres;
int main(int argc, char *argv[])
@Saafke
Saafke / countBlobs.m
Last active March 28, 2020 21:50
Matlab code for counting number of blobs. Also known as a connected component labeling algorithm.
% Code created by Xavier Weber
% ============= PART 1: READING AND PADDING THE IMAGE =====================
function [count,im] = countBlobs(img)
%countBlobs Counts the number of blobs: connected regions of positive
% values - and labels them.
% returns: number of blobs
% Get dimensions
@Saafke
Saafke / padImage.m
Created March 28, 2020 15:13
Matlab code for padding an image.
% Code created by Xavier Weber
function outimg = padImage(I, pad)
%padImage Pads an image with black pixels (zero-values)
% Works with single or multi-channels
% Get input dimensions
img_size = size(I);
src_height = img_size(1);
src_width = img_size(2);
@Saafke
Saafke / script.m
Last active March 29, 2020 15:02
Matlab script for the Connected Component Labelling blog.
% Code created by Xavier Weber
% Create an image -- like the one in the GIF.
im = zeros(5,5);
im(1:1,5:5) = 255;
im(2:2,2:2) = 255;
im(3:3,1:1) = 255;
@Saafke
Saafke / code.py
Created March 31, 2020 10:03
Python code for upscaling an image via OpenCV
import cv2
from cv2 import dnn_superres
# Create an SR object
sr = dnn_superres.DnnSuperResImpl_create()
# Read image
image = cv2.imread('./input.png')
# Read the desired model
@Saafke
Saafke / opencvcuda.txt
Last active January 14, 2023 18:09
Terminal command for building opencv with contrib modules and CUDA support.
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D WITH_CUDA=ON \
-D WITH_CUDNN=ON \
-D OPENCV_DNN_CUDA=ON \
-D ENABLE_FAST_MATH=1 \
# Read the desired model
path = "EDSR_x3.pb"
sr.readModel(path)
# Set CUDA backend and target to enable GPU inference
sr.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
sr.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
#etcetera..
//Read the desired model
string path = "FSRCNN_x2.pb";
sr.readModel(path);
//Set CUDA backend and target to enable GPU inference
sr.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA)
sr.setPreferableTarget(cv::dnn::DNN_BACKEND_CUDA)
//etcetera..
@Saafke
Saafke / subtract_rename.sh
Last active July 8, 2021 09:57
Subtracts a number from filenames with a number in them (no leading zeros). For example: out321.png -> out300.png if NUMBER_TO_SUBTRACT=21
NUMBER_TO_SUBTRACT=217
for file in `ls -1v out*`; do
echo $file
NUMBER=${file:3:-4}
NEW_NUMBER=$[NUMBER-NUMBER_TO_SUBTRACT]
NEW_FILE_NAME="out${NEW_NUMBER}.png"
echo $NEW_FILE_NAME