Skip to content

Instantly share code, notes, and snippets.

View Enigmatisms's full-sized avatar
☢️
R & D

Qianyue He Enigmatisms

☢️
R & D
View GitHub Profile
@Enigmatisms
Enigmatisms / fast_2d_img_3dviz.py
Created November 19, 2022 10:48
Visualize 2D intensity in 3D space
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
raw_rgb = plt.imread("VTA_trial.png")
iso_blue = raw_rgb[..., 2] - raw_rgb[..., 0]
iso_blue = np.maximum(iso_blue, np.full_like(iso_blue, 0.01))
@Enigmatisms
Enigmatisms / llmse.py
Created October 21, 2022 10:19
LLMSE estimation - modern signal processing course experiment 2
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
import sys
# input be of shape n (1d), then (periodic convolution)
def get_H(isi: np.ndarray):
n = isi.shape[0]
result_h = []
for i in range(n):
@Enigmatisms
Enigmatisms / exp_1_and_2.py
Last active October 11, 2022 05:27
Experiment 1 and 2 for modern signal processing experiment class I. (exp_1_and_2.py), for experiment 3 and 4: (l1_test.py)
import numpy as np
import matplotlib.pyplot as plt
__LOG_10__ = 2.3025851249694824
mse_loss_func = lambda src, dst: ((src - dst) ** 2).mean()
psnr_func = lambda x: -10. * np.log(x) / __LOG_10__
def solve_mls(X: np.ndarray, data: np.ndarray) -> np.ndarray:
XXt = X.T @ X
u, s, _ = np.linalg.svd(XXt)
@Enigmatisms
Enigmatisms / async_timer_event.rs
Created June 4, 2022 14:26
Timer event implemented using mpsc (a test).
use std::sync::mpsc;
use std::time::Duration;
struct AsyncTimerEvent<T> where T: Send + 'static {
receiver: Option<mpsc::Receiver<T>>,
sleep_time: u64,
}
impl<T> AsyncTimerEvent<T> where T: Send + 'static {
pub fn new(sleep_sec: u64) -> AsyncTimerEvent<T> {
@Enigmatisms
Enigmatisms / timer_event.cc
Created June 3, 2022 12:37
Timer event based on future and async
/**
* async returns future, which implicitly blocks the thread (waiting)
*
*/
#include <future>
#include <thread>
#include <mutex>
#include <iostream>
#include <chrono>
@Enigmatisms
Enigmatisms / async_image_fetch.cc
Last active June 3, 2022 12:25
Simple asynchronous high performance camera reading & decoding solution (no-async-version is correct.)
/**
* async returns future, which implicitly blocks the thread (waiting)
*
*/
#include <thread>
#include <mutex>
#include <iostream>
#include <chrono>
#include <atomic>
@Enigmatisms
Enigmatisms / autoComment.js
Created December 28, 2021 14:13
Semi-automatic teacher rating of XJTU.
var all_check_box = document.getElementsByClassName("sc-panel-content bh-clearfix bh-mv-8 wjzb-card-jskc");
for (let i=0; i < (all_check_box.length - 1);i++) {
let choice = Math.floor(Math.random() * 10) % 2;
all_check_box[i].children[1].children[0].children[choice].click();
}
var text_box = document.getElementsByClassName("bh-txt-input");
text_box[0].children[0].value = "老师很不错";
@Enigmatisms
Enigmatisms / face_det.py
Created June 20, 2021 11:23
Face detection via OpenMV with MyRIO PID control.
#人脸识别开关
import sensor, time, image #导入模块
from pyb import LED #导入模块
from pyb import DAC # DAC
# 设定图像基本参数
sensor.reset() #初始化摄像头
sensor.set_contrast(2) #亮度-3至3
sensor.set_gainceiling(2) #增益
sensor.set_framesize(sensor.QVGA) #图像格式
@Enigmatisms
Enigmatisms / DF.py
Created June 15, 2021 18:00
Simple illustration for DF of line segment.
import matplotlib.pyplot as plt
import numpy as np
def distanceField(sp, ep):
brx, bry = ep + np.array([25, 25])
direct = (ep - sp).astype(np.float64)
direct /= np.linalg.norm(direct)
normal = np.array([-direct[1], direct[0]], dtype = np.float64)
result = np.zeros((bry, brx))
for i in range(bry):
@Enigmatisms
Enigmatisms / csma_simulation.py
Last active May 20, 2021 03:35
CSMA/CD Implementation in Python and its visualization & Gist Test (What is gist?)
import cv2 as cv
import numpy as np
import imageio
class Link:
collision = False
def __init__(self, link_len = 10):
self.buf_1 = np.zeros(link_len)
self.buf_2 = np.zeros(link_len)
self.link_len = link_len