Skip to content

Instantly share code, notes, and snippets.

View dimaxano's full-sized avatar
🎯
Focusing

Dmitry Klimenkov dimaxano

🎯
Focusing
View GitHub Profile
import inspect
import sys
import os
import time
connection_string = "udp:127.0.0.1:14551"
# connection_string = "/dev/ttyACM0"
# Import DroneKit-Python
@dimaxano
dimaxano / send_vision_pose.py
Created November 21, 2019 11:33
Sending VISION_POSE_ESTIMATE message via MAVlink
import numpy as np
import time
from dronekit import connect, VehicleMode
vehicle = connect('udp:127.0.0.1:14551', wait_ready = True, source_system = 255)
def send_vision_position_message():
x, y, z = np.random.rand(3, ) * 10
# metrics
def dice_coef(y_true, y_pred):
y_true_f = K.flatten(y_true)
y_pred = K.cast(y_pred, 'float32')
y_pred_f = K.cast(K.greater(K.flatten(y_pred), 0.5), 'float32')
intersection = y_true_f * y_pred_f
score = 2. * K.sum(intersection) / (K.sum(y_true_f) + K.sum(y_pred_f))
return score
#losses
import os
import numpy as np
import cv2
def mask_to_label(mask_rgb):
pascal_palette = np.array([(0, 0, 0), (192, 128, 128)], dtype=np.uint8)
mask_labels = np.ones(mask_rgb.shape[:2])
pixel = 0
for i in range(mask_rgb.shape[0]):
@dimaxano
dimaxano / change_color.py
Last active October 10, 2017 08:14
Code snippet for changing exact color in the image
import numpy as np
import cv2
data = cv2.imread(path)
r1, g1, b1 = 255, 0,0 # Original value
r2, g2, b2 = 255, 255, 255 # Value that we want to replace it with
blue, green, red = data[:,:,0], data[:,:,1], data[:,:,2]
mask = (red == r1) & (green == g1) & (blue == b1)