Skip to content

Instantly share code, notes, and snippets.

@adelosa
adelosa / db_test.py
Last active December 2, 2021 11:07
Python database unit testing class
import os
import tempfile
import unittest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from youapp.model import Base # replace this with your app's model base
"""
@FBosler
FBosler / code.py
Created February 21, 2020 18:43
functools.py
from functools import lru_cache
from datetime import datetime
@lru_cache(maxsize=None)
def fib_cache(n):
if n < 2:
return n
return fib_cache(n-1) + fib_cache(n-2)
def fib_no_cache(n):
@tzvsi
tzvsi / gist:222b3b22a847004a729744f89fe31255
Last active September 21, 2023 06:37
Installing CUDA 10.2, CuDNN 7.6.5, TensorRT 7.0, Ubuntu 18.04

Step 1: Installing CUDA (~5.5 minutes)

You can also install CUDA directly from the offline installer, but this is a little easier.

sudo apt update
sudo apt upgrade -y

mkdir install ; cd install
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
@YashasSamaga
YashasSamaga / yolov4.py
Last active July 13, 2024 06:42
YOLOv4 on OpenCV DNN
import cv2
import time
CONFIDENCE_THRESHOLD = 0.2
NMS_THRESHOLD = 0.4
COLORS = [(0, 255, 255), (255, 255, 0), (0, 255, 0), (255, 0, 0)]
class_names = []
with open("classes.txt", "r") as f:
class_names = [cname.strip() for cname in f.readlines()]
@myounus96
myounus96 / clean-voc-data.ipynb
Created November 12, 2019 08:20
remove the data of extra classes for voc to yolo gist
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@myounus96
myounus96 / convert_voc_to_yolo.md
Last active February 3, 2022 22:27 — forked from vdalv/convert_voc_to_yolo.md
convert pascal voc dataset to yolo format

Convert PascalVOC Annotations to YOLO

This script reads PascalVOC xml files, and converts them to YOLO txt files.

Note: This script was written and tested on Ubuntu. YMMV on other OS's.

Disclaimer: This code is a modified version of Joseph Redmon's voc_label.py

Instructions:

  1. Place the convert_voc_to_yolo.py file into your data folder.
@raulqf
raulqf / Install_OpenCV4_CUDA11_CUDNN8.md
Last active July 24, 2024 08:42
How to install OpenCV 4.5 with CUDA 11.2 in Ubuntu 22.04

How to install OpenCV 4.5.2 with CUDA 11.2 and CUDNN 8.2 in Ubuntu 22.04

First of all install update and upgrade your system:

    $ sudo apt update
    $ sudo apt upgrade

Then, install required libraries:

@smeschke
smeschke / align_scan.py
Last active May 17, 2024 01:45
Aligns a scanned document to find optimal rotation
import cv2
import numpy as np
src = 255 - cv2.imread('/home/stephen/Desktop/I7Ykpbs.jpg',0)
scores = []
h,w = src.shape
small_dimention = min(h,w)
src = src[:small_dimention, :small_dimention]
@leandrobmarinho
leandrobmarinho / yolo.py
Last active December 11, 2021 09:37
An example in Python using Yolo from Opencv.
import cv2
import numpy as np
scale = 0.00392
classes_file = "coco.names"
weights = "yolov2.weights"
config_file = "yolov2.cfg"
# read class names from text file
classes = None
@pknowledge
pknowledge / mouse_event_opencv_python.py
Created March 3, 2019 14:52
How to Detect Mouse Clicks and Moves
import numpy as np
import cv2
#events = [i for i in dir(cv2) if 'EVENT' in i]
#print(events)
def click_event(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
print(x,', ' ,y)
font = cv2.FONT_HERSHEY_SIMPLEX