Skip to content

Instantly share code, notes, and snippets.

View aliyevorkhan's full-sized avatar
🌍
Working from Earth

Orkhan ALIYEV aliyevorkhan

🌍
Working from Earth
View GitHub Profile
@aliyevorkhan
aliyevorkhan / pymongo_utils.py
Last active May 7, 2022 18:57
PyMongo exercises
import pymongo
def connect_server(): #connect mongo server
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
return myclient
#######################DATABASE UTILS#################################
def create_db():
mydb = myclient["mydatabase"] #create database
import cv2
# import matplotlib.pyplot as plt
from glob import glob
import sys
import uuid
from tqdm import tqdm
import os
num_of_files = len([x for x in os.listdir(str(sys.argv[1])) if (x.endswith('.txt'))])
import cv2
import sys
import uuid
from tqdm import tqdm
video_name = str(sys.argv[1])
e_rate = int(sys.argv[2])
cap = cv2.VideoCapture(video_name+'.mp4')
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
count=0
import glob
import sys
import os
lbls = []
frames = []
if_lbl_exists = False
for lbl in glob.glob(str(sys.argv[1])+'/*.txt'):
lbls.append(lbl.split('/')[1].split('.')[0])
import math
BATCH_SIZE=32
TRAINING_SIZE = 40000
# We take the ceiling because we do not drop the remainder of the batch
compute_steps_per_epoch = lambda x: int(math.ceil(1. * x / BATCH_SIZE))
steps_per_epoch = compute_steps_per_epoch(TRAINING_SIZE)
import os
import cv2
src_path = os.path.abspath(os.path.join(os.getcwd(), "bolu_tunnel_nvr"))
print(src_path)
ch1_dst_path = os.path.abspath(os.path.join(os.getcwd(), "ch1"))
ch2_dst_path = os.path.abspath(os.path.join(os.getcwd(), "ch2"))
print(ch1_dst_path)
import os
import cv2
src_path = os.path.abspath(os.path.join(os.getcwd(), "bolu_tunnel_nvr"))
print(src_path)
ch1_dst_path = os.path.abspath(os.path.join(os.getcwd(), "ch1"))
ch2_dst_path = os.path.abspath(os.path.join(os.getcwd(), "ch2"))
print(ch1_dst_path)
import os
from PIL import Image
def has_transparency(img):
if img.mode == "P":
transparent = img.info.get("transparency", -1)
for _, index in img.getcolors():
if index == transparent:
return True
elif img.mode == "RGBA":
import cv2
import glob, errno
# Replace mydir with the directory you want
mydir = 'Train1/'
#check if directory exist, if not create it
try:
os.makedirs(mydir)
except OSError as e:
import cv2
path = '/home/orkhan/Desktop/train/'
cap = cv2.VideoCapture('video.mp4')
i = 0
counter = 0
while cap.isOpened():
ret, frame = cap.read()
if not ret: