Skip to content

Instantly share code, notes, and snippets.

View sdi1982's full-sized avatar
๐Ÿ“š
Study&Develop Group

Daniel Shin sdi1982

๐Ÿ“š
Study&Develop Group
View GitHub Profile
@sdi1982
sdi1982 / SimpleParallelForLoop
Created April 25, 2021 20:22 — forked from KPB3rd/SimpleParallelForLoop
Simple Parallel For Loop C++
// Initialize detector vector
if (targetDetectors.size() == 0)
{
for (unsigned iter = 0; iter < inputImages.size(); iter++) targetDetectors.push_back(CalibTargetDetector());
}
// Create Output vector
for (unsigned iter = 0; iter < inputImages.size(); iter++) targetImages.push_back(TypedObject<cv::Mat>(cv::Mat()));
std::vector<std::thread*> threads(inputImages.size());
@sdi1982
sdi1982 / VideoPlayer.html
Created March 30, 2021 11:08 — forked from jaydenseric/VideoPlayer.html
A simple HTML5 video player.
<figure class="video-player">
<video preload="none" width="1280" height="720" poster="video.jpg">
<source src="video.webm" type="video/webm" />
<source src="video.mp4" type="video/mp4" />
</video>
<button class="play-toggle">Toggle play</button>
<button class="mute-toggle">Toggle mute</button>
</figure>
<script>
// Initialize video player
@sdi1982
sdi1982 / client.cpp
Created March 4, 2021 00:13 — forked from mendaparadarshit/client.cpp
Multiple streaming in c++ using opencv; OpenCV video streaming over TCP/IP
/**
* OpenCV video streaming over TCP/IP
* Client: Receives video from server and display it
* by Steve Tuenkam
*/
#include "opencv2/opencv.hpp"
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
@sdi1982
sdi1982 / sift.cpp
Created December 28, 2020 17:41 — forked from lxc-xx/sift.cpp
OpenCV's SIFT implementation
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
@sdi1982
sdi1982 / accuracy_recall_precision_f1.py
Created November 28, 2020 20:06 — forked from debonx/accuracy_recall_precision_f1.py
Accuracy, Recall, Precision and F1 score with sklearn.
# To be reminded
# 1) Classifying a single point can result in a true positive (truth = 1, guess = 1), a true negative (truth = 0, guess = 0), a false positive (truth = 0, guess = 1), or a false negative (truth = 1, guess = 0).
# 2) Accuracy measures how many classifications your algorithm got correct out of every classification it made.
# 3) Recall measures the percentage of the relevant items your classifier was able to successfully find.
# 4) Precision measures the percentage of items your classifier found that were actually relevant.
# 5) Precision and recall are tied to each other. As one goes up, the other will go down.
# 6) F1 score is a combination of precision and recall.
# 7) F1 score will be low if either precision or recall is low.
from sklearn.metrics import accuracy_score, recall_score, precision_score, f1_score
Clc
I=imread('cameraman.tif');
[m n]=size(I);
a=im2double(I);
for i=1:m-2
for j=1:n-2
v(i,j) = [a(i,j) + a(i,j+1) + a(i,j+2) + a(i+1,j) + a(i+1,j+1) + a(i+1,j+2) + a(i+2,j) + a(i+2,j+1) + a(i+2,j+2)]./9; %smoothing filter
x(i,j) = [0*a(i,j) + 1*a(i,j+1) + 0*a(i,j+2) + 1*a(i+1,j) + -4*a(i+1,j+1) + 1*a(i+1,j+2) + 0*a(i+2,j) + 1*a(i+2,j+1) + 0*a(i+2,j+2)]; %high pass filter
import argparse, os
import numpy as np
from scipy.misc import imread, imsave
parser = argparse.ArgumentParser()
parser.add_argument('--template_dir', required=True) # Low-res images
parser.add_argument('--source_dir', required=True) # Outputs from CNN
parser.add_argument('--output_dir', required=True)
args = parser.parse_args()
/*
http://benjithian.sg/2012/12/simple-background-subtraction/
Simple Background Subtraction. Simple stuff.
*/
#include <stdio.h>
#include <curl/curl.h>
#include <sstream>
#include <iostream>
#include <vector>
#include <opencv2/opencv.hpp>
@sdi1982
sdi1982 / gist:d0b749ebfd511653ab1cee181c389d39
Created October 23, 2020 16:15 — forked from petigura/gist:1927518
Linear Least Squares
def PLfit(p0,blin,x,data,model,engine=optimize.fmin_powell,err=1):
"""
Partial Linear Model Fitting.
Parameters
----------
p0 : Initial parameters
blin : Boolean array specifying which model parameters are fixed
"""
@sdi1982
sdi1982 / f1_score.py
Created October 23, 2020 16:02 — forked from SuperShinyEyes/f1_score.py
F1 score in PyTorch
def f1_loss(y_true:torch.Tensor, y_pred:torch.Tensor, is_training=False) -> torch.Tensor:
'''Calculate F1 score. Can work with gpu tensors
The original implmentation is written by Michal Haltuf on Kaggle.
Returns
-------
torch.Tensor
`ndim` == 1. 0 <= val <= 1