Skip to content

Instantly share code, notes, and snippets.

@priteshgohil
priteshgohil / images2pdf.sh
Last active January 8, 2021 22:41
Convert all images in directory to pdf file and produce compressed pdf file using ghostscript. Most suitable for image compression without loosing much of information.
#!/bin/bash
#title :images2pdf.sh
#description :Best image compression ever.
#author :Pritesh Gohil
#date :08 Jan 2021
#version :0.1
#usage :bash images2pdf.sh -i ../Desktop/img_dir/
#notes :Install ImageMagick and ghostscript packages.
#bash_version :5.0.16(1)-release
@priteshgohil
priteshgohil / webcam_opencv.cpp
Last active May 18, 2024 20:25
C++ code to read images from webcam using CV 4.1.1
#include <opencv2/opencv.hpp>
#include <iostream>
int main(int, char**) {
// open the first webcam plugged in the computer
cv::VideoCapture camera(0); // in linux check $ ls /dev/video0
if (!camera.isOpened()) {
std::cerr << "ERROR: Could not open camera" << std::endl;
return 1;
}
@priteshgohil
priteshgohil / rosbag2images.py
Created December 10, 2020 10:32
Extract images from a rosbag file. It will also show the list of topics in rosbag.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2016 Massachusetts Institute of Technology
# Tutorial : http://wiki.ros.org/rosbag/Code%20API#Python_API
"""
Extract images from a rosbag.
How to use: In terminal, cd DIRECTORY_OF_THIS_FILE and then type following
python bag_to_images.py --bag_file camera_odom_compressed.bag --output_dir output/ --image_topic '/camera/image_raw'
python bag_to_images.py --bag_file my_rosbag_file.bag --output_dir output/ --image_topic '/eGolf/front_cam/image_raw'
@priteshgohil
priteshgohil / video2frames_cv.py
Last active November 4, 2023 18:56
Extract frames from video using OpenCV
#!/usr/bin/env python
"""
Author: Pritesh Gohil
Import or run this script to extract frames from a single video or
video directory using OpenCV
Requirement: numpy, cv2, tqdm
How to use:
Single Video
@priteshgohil
priteshgohil / pdb_cheatsheet.md
Last active September 30, 2020 10:19
Python Debugger pdb cheatsheet
Short cmd Full cmd Description
a args Print all arguments with its value in current function
b break Add breapoint at specific line or function
c continue Continue execution of program until next breakpoint
cl clear Clear all the soft breakpoints
l list Print next 11 line of code aroung the current line
l . list . Go back to the current debug point
import cv2
import random
import numpy as np
'''
Draw AABB in given image with labels
Inputs: img - image file path or cv2 image
: boxes_list - 2d list or 2d array of BBox (4 columns) with bounding boxes with top-left (x_min, y_min) and bottom right (x_max, y_max) pixel value. PS: maintain order xyxy
: label list - list(str) or 1-d array having name of the labels. Use cls = [classes[l] for l in list(labels)] # index to str labels
Return: CV2 image in BGR format
@priteshgohil
priteshgohil / mean_calculate_performance.py
Created September 10, 2020 11:47
Performance on calculating mean
import time
import statistics
import numpy as np
def mean_normal(list_data):
"""
Calculate mean of python list normaly
input: list of int or float
output: mean value
"""