Skip to content

Instantly share code, notes, and snippets.

@oak-tree
oak-tree / realtime.cpp
Created August 16, 2022 10:20
realtime
void SetRealTimePriority() {
int ret;
pthread_t this_thread = pthread_self();
// used to store the scheduling priority
struct sched_param params;
// set the priority to the maximum.
params.sched_priority = sched_get_priority_max(SCHED_FIFO);
LOG(INFO) << "Trying to set thread realtime prio = " << params.sched_priority << std::endl;
// Attempt to set thread real-time priority to the SCHED_FIFO policy
ret = pthread_setschedparam(this_thread, SCHED_FIFO, &params);
import tensorflow as tf
import os
import time
import numpy as np
import matplotlib.pyplot as plt
from tensorflow import keras
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions
#include <stdio.h>
#include <assert.h>
inline cudaError_t checkCuda(cudaError_t result)
{
if (result != cudaSuccess) {
fprintf(stderr, "CUDA Runtime Error: %s\n", cudaGetErrorString(result));
assert(result == cudaSuccess);
}
return result;
@oak-tree
oak-tree / video_builder.py
Created March 4, 2020 12:42
create video from all jpeg in current folder
image_height,image_width,_ =cv2.imread(os.listdir()[0]).shape
output_path = os.path.join(os.getcwd(), "result.avi")
video_size = image_width, image_height
video_fps = 5
video_size = image_width, image_height
video_FourCC = cv2.VideoWriter_fourcc(*'MJPG')
out = cv2.VideoWriter(output_path, video_FourCC, video_fps, video_size)
for i in sorted(os.listdir()):
@oak-tree
oak-tree / motor.cpp
Last active November 24, 2019 16:30
motor
// in this example the position mode will be selected and started, after the input 1 is triggered, the motor moves to a set position (flagposition mode)
//1. Step: mapping the frequently used SDO´s
map U16 ControlWord as output 0x6040:00
map U32 ProfileVelocity as output 0x6081:00
map S32 TargetPosition as output 0x607A:00
map U32 Inputs as input 0x60FD:00
map S32 ActualPosition as input 0x6064:00
map S32 AnalogInput as input 0x3320:01
map S08 HomingMethod as output 0x6098:00
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
def do_something(img):
return np.dot(img[...,:3], [0.299, 0.587, 0.114])
img = mpimg.imread('image.png')
result = do_something(img)
plt.imshow(result, cmap = plt.get_cmap('gray'))
@oak-tree
oak-tree / renew azure message lock.py
Created November 14, 2017 14:20
azure mssage lock
msg_locked_until = dateutil.parser.parse(msg.broker_properties['LockedUntilUtc'])
if (datetime.now(utc) + timedelta(0, lock_buff_seconds)) > msg_locked_until:
logger.info("Renewing message lock")
try:
msg.renew_lock()
logger.info("Done.")
except Exception as e:
logger.error("Failed renewing the message lock.")
logger.error(e.message)
@oak-tree
oak-tree / install_opencv.sh
Last active August 22, 2017 17:40
install opencv 3.3 from sources
sudo apt-get install qt-sdk
then follow
#http://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html
sudo apt-get install build-essential
#install python header and includes
#
sudo apt-get install python2.7-dev
sudo apt-get install python3.4-dev
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
@oak-tree
oak-tree / remote_display.sh
Created June 19, 2017 15:32
remote display Xvfb
sudo apt-get install xvfb
nohup Xvfb :1 > /dev/null 2>&1 &
#testing with
python
import matplotlib
import matplotlib.pyplot as plt
@oak-tree
oak-tree / remote_display.sh
Created June 19, 2017 15:32
remote display Xvfb
sudo apt-get install xvfb
nohup Xvfb :1 > /dev/null 2>&1 &
#testing with
python
import matplotlib
import matplotlib.pyplot as plt