Skip to content

Instantly share code, notes, and snippets.

View IAmSuyogJadhav's full-sized avatar
☝️
One thing at a time.

Suyog Jadhav IAmSuyogJadhav

☝️
One thing at a time.
View GitHub Profile
@IAmSuyogJadhav
IAmSuyogJadhav / Transparent drawings in OpenCV.py
Created July 10, 2018 09:41
Add transparency to rectangles, circles, polgons, text or any shape drawn in OpenCV.
import cv2
image = cv2.imread('test.jpg')
overlay = image.copy()
x, y, w, h = 10, 10, 10, 10 # Rectangle parameters
cv2.rectangle(overlay, (x, y), (x+w, y+h), (0, 200, 0), -1) # A filled rectangle
alpha = 0.4 # Transparency factor.

This short tutorial will get you set up with your programming environment, so that you can get started with your programming assignments.

Setting up the docker container

We will be using a prebuilt docker instance from NVIDIA's docker repository (NGC), as it simplifies setup for us.

Run the following command. Replace <local_dir> with a local directory path you would like to access from within the container.

docker run -p 8888:9989 --ulimit memlock=-1 --ulimit stack=67108864 --shm-size=8g --gpus all -it -v <local_dir>:/workspace/ nvcr.io/nvidia/pytorch:23.05-py3

You can change the part after nvcr.io/pytorch: to change the version of the docker. 23.05-py3 is the latest version from 2023.

@IAmSuyogJadhav
IAmSuyogJadhav / PDF_Rearrange_Preserve_Bookmarks_Hyperlinks.md
Created May 14, 2023 12:15
Rearrange PDF pages while keeping hyperlinks and bookmarks intact.
@IAmSuyogJadhav
IAmSuyogJadhav / opencv-camera-calibration-undistortion.py
Created March 20, 2021 15:02
A working script for calibrating and undistorting/dewarping the distortion from any regular or fisheye camera. Takes care of resizing and rescaling the FOV appropriately to get rid of the empty black space on both the sides (which is observed in case of high FOV fisheye lenses).
"""
Modified version of the original script from https://github.com/mesutpiskin/opencv-fisheye-undistortion/blob/master/src/python/camera_calibration_undistortion.py
"""
import cv2
import numpy as np
import glob
def calibrate(folder, rows=6, cols=9, save_file='calibrationdata.npz'):
import cv2
import numpy as np
image_path = 'path/to/image' # Path to the input image
bgcolor = [255, 255, 255] # BGR value of background color.
img = cv2.imread(image_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2BGRA)
img[np.all(img == bgcolor + [255], axis=2)] = [0,0,0,0]
@IAmSuyogJadhav
IAmSuyogJadhav / asus-mutemic
Created June 15, 2021 10:19
Refer to the blog for more info:
event=button/micmute MICMUTE 00000080 00000000 K
action=/etc/acpi/asus-mutemic.sh
@IAmSuyogJadhav
IAmSuyogJadhav / asus-mutemic.sh
Last active June 15, 2021 10:18
Refer to the blog for more info:
#!/bin/sh
#sudo PULSE_RUNTIME_PATH=/var/run/pulse -u pulse pacmd list-sources | grep -oP 'index: \d+' | awk '{ print $2 }' | xargs -I{} pactl set-source-mute {} toggle
sudo PULSE_RUNTIME_PATH=/var/run/pulse -u pulse pactl set-source-mute 2 toggle && pactl set-source-mute 1 toggle && pactl set-source-mute 0 toggle
@IAmSuyogJadhav
IAmSuyogJadhav / FourierShift2D.py
Last active April 15, 2021 22:40
2D shifting in python. Accepts both real and complex inputs. Accepts integer as well as floating-point values for shifting. Allows for subpixel shifting of both real and complex 2D matrices/images in python. Based on: https://github.com/aludnam/MATLAB/blob/master/image_proc/FourierShift2D.m
def FourierShift2D(x, delta):
"""
FourierShift2D(x, delta)
Subpixel shifting in python. Based on the original script (FourierShift2D.m)
by Tim Hutt.
Original Description
--------------------
Shifts x by delta cyclically. Uses the fourier shift theorem.
Real inputs should give real outputs.
@IAmSuyogJadhav
IAmSuyogJadhav / number_of_parameters.py
Created January 12, 2021 11:23
Count and display the total no. of parameters in a PyTorch model.
# model is your pytorch model (an nn.Module instance)
pytorch_total_params = sum(p.numel() for p in model.parameters())
print(pytorch_total_params)
@IAmSuyogJadhav
IAmSuyogJadhav / remove_data_parallel.py
Last active January 3, 2021 05:56
Remove DataParallel from PyTorch models trained with nn.DataParallel or nn.DistributedDataParallel. Input = old state_dict, output = new state_dict that works without nn.DataParallel or nn.DistributedDataParallel
def remove_data_parallel(old_state_dict):
new_state_dict = OrderedDict()
for k, v in old_state_dict.items():
name = k[7:] # remove `module.`
new_state_dict[name] = v
return new_state_dict