Skip to content

Instantly share code, notes, and snippets.

import threading
import queue
import time
import random
# Producer class
class Producer(threading.Thread):
def __init__(self, buffer):
super().__init__()
self.buffer = buffer
abs_enc_ticks left_wheel_ticks right_wheel_ticks stamp
2105 0.92894 0.92894 1600094165.610474549
2095 1 1 1600094165.659472296
2096 2 1 1600094165.709469575
2100 0.0752273 1.07523 1600094165.713231086
2100 0.924773 1.84955 1600094165.759471541
2104 0.280612 -0.719388 1600094165.766628980
2104 1.71939 0.859694 1600094165.810484548
2091 1 2 1600094165.859469796
2094 0.194879 0.194879 1600094165.864341974
x y stamp
0 0 1600094165.564021110
0.00191943 0.00185668 1600094165.713231086
0.0104502 0.023996 1600094165.766628980
0.0177098 0.0451626 1600094165.864341974
0.0281736 0.0672945 1600094165.969501018
0.036788 0.0944362 1600094166.078454017
0.0498157 0.131995 1600094166.185786008
0.0735075 0.186108 1600094166.265960931
0.10357 0.265083 1600094166.364769935
@pietrocolombo
pietrocolombo / optimization.py
Created July 22, 2024 20:47
optimization class for pygmo
class optimization:
def __init__(self, enc_vector, gps_vector, ratio_t2ml, ratio_t2mr,
abs_zero_initial, abs_first_coef, abs_second_coef, abs_third_coef,
abs_first_exp, abs_second_exp, abs_third_exp, orientation_start):
self.enc_vector = enc_vector
self.gps_vector = gps_vector
self.ratio_t2ml = ratio_t2ml
self.ratio_t2mr = ratio_t2mr
# pip install opencv-python
import cv2
import queue
import threading
import time
class Video(threading.Thread):
def __init__(self, camera, interval, path) -> None:
threading.Thread.__init__(self)
self._cam = cv2.VideoCapture(camera)
@pietrocolombo
pietrocolombo / generation_pdf.py
Created December 22, 2022 22:25
example generation pdf (invoice) with reportlab
from reportlab.pdfgen import canvas
from reportlab.lib.units import mm
from reportlab.lib.pagesizes import A4
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase import pdfmetrics
from reportlab.lib.enums import TA_LEFT, TA_CENTER
from reportlab.lib.styles import ParagraphStyle
from reportlab.platypus import Paragraph
class DataDevice(Resource):
def put(self):
""" it receives the data from the devices and puts them in the database
:return:
"""
args = device_data_put_args.parse_args()
# check if the device exist
device = Device.query.get(args['id_device'])
if device is None:
@pietrocolombo
pietrocolombo / Extract frame.py
Last active January 13, 2022 07:23
Extract frame from a video
import cv2
import os
# Read the video from specified path
cam = cv2.VideoCapture("/content/gdrive/MyDrive/Foto & Video/2021/Casargo/Volo 2/DJI_0049.MP4")
try:
# creating a folder named data
if not os.path.exists('/content/gdrive/MyDrive/Foto & Video/2021/Casargo/Volo 2/DJI_0049'):
@pietrocolombo
pietrocolombo / example_bot_telegam_no_library.py
Created July 3, 2021 13:17
Example of a telegram bot in python without using specific libraries
import json
import requests
import urllib
TOKEN = ""
URL = "https://api.telegram.org/bot{}/".format(TOKEN)
USERNAME_BOT = ""
counting = {}
for activity in df['class'].unique():
counting[activity] = {}
activity_df = df[df['class'] == activity]
n_instance = activity_df.shape[0]
for user in df['user'].unique():
counting[activity][user] = activity_df[activity_df['user'] == user].shape[0]/n_instance*100
bars = []