Skip to content

Instantly share code, notes, and snippets.

View wermarter's full-sized avatar
🐹
lọ mọ

Hà Minh Chiến wermarter

🐹
lọ mọ
View GitHub Profile
@wermarter
wermarter / python_opencv_camera_app.py
Created January 22, 2017 09:17
Rotation, Mouse events, Perspectives and more...
import cv2, time, sys
from random import *
import numpy as np
font = cv2.FONT_HERSHEY_SIMPLEX
xi, yi = 0, 0
def func(event, x, y, _, __):
global cap, img, xi, yi
xi, yi = x, y
if event == cv2.EVENT_LBUTTONUP:
___, img = cap.read()
@wermarter
wermarter / python_opencv_inrange.py
Created January 22, 2017 09:20
Color filtering and Bitwise AND
import cv2, time, sys
from random import *
import numpy as np
cap = cv2.VideoCapture(0)
while 1:
_, frame = cap.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_clr = np.array([0,0,0])
upper_clr = np.array([176,100,100])
mask = cv2.inRange(frame, lower_clr, upper_clr)
@wermarter
wermarter / python_opencv_addWeighted.py
Created January 22, 2017 09:22
Transitional Fade Effect
import cv2, time, sys
from random import *
import numpy as np
def trans_effect(named, img1, img2, speed=100):
h1, w1, c1 = img1.shape
h2, w2, c2 = img2.shape
h, w, c = min(h1, h2), min(w1, w2), min(c1, c2)
img1 = img1[:h, :w, :c]
img2 = img2[:h, :w, :c]
for i in range(1, 10):
@wermarter
wermarter / python_opencv_putText_basic.py
Created January 22, 2017 09:24
putText, cvtColor, font, random and more...
import cv2, time, sys
from random import *
import numpy as np
font = cv2.FONT_HERSHEY_SIMPLEX
cap = cv2.VideoCapture(0)
width, height = cap.get(3), cap.get(4)
print(width, height)
ck = 0
start = time.time()
@wermarter
wermarter / cpp_zahada.cpp
Created January 22, 2017 09:35
Tiny Cutie Zahada Riddle Bot ( Using Web BRowser )
#include <windows.h>
#include <string>
#include <iostream>
using namespace std;
int main() {
string url; cin >> url;
url = "http://www.mcgov.co.uk/riddles/" + url + ".html";
ShellExecute(NULL, "open", url.c_str(), "", ".", SW_SHOWNORMAL);
return 0;
}
@wermarter
wermarter / python_ML_intro_regression.py
Created January 22, 2017 09:41
Pickle vs. Joblib, some ML with update features, DF, predict GOOGL from Quandl
import quandl, pickle, math, datetime
import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn import preprocessing, cross_validation
from sklearn.externals import joblib
import matplotlib.pyplot as plt
from matplotlib import style
one_day = 86400
one_week = one_day*7
@wermarter
wermarter / python_webscraper_MyAnimeList(MAL).py
Created January 22, 2017 09:44
some web scraping and relational database, regex stuff... + some hours to get data
from lxml import html
import requests, sqlite3, re
def Process(url):
id = int(re.findall('/([0-9]+)/.*?$', url)[0])
if (id in id_fetched):
print('Skiping ', id)
return
page = requests.get(url + '/userrecs')
tree = html.fromstring(page.content)
@wermarter
wermarter / python_USB_TheSinner.py
Created January 22, 2017 09:46
Auto-turbo-copy USB content on plug, used for lecturers' personal data
import os, shutil, stat, sys, win32api, time, datetime
from distutils.dir_util import copy_tree
curr_dir = sys.argv[0]
args = sys.argv[1:]
argc = len(args)
def get_IVG(location):
try:
return open(os.path.join(location, 'System Volume Information', 'IndexerVolumeGuid')).readlines()[0]
except:
return 'None_Info'
@wermarter
wermarter / python_opencv_edges.py
Created January 25, 2017 12:06
Sobel, Laplacian, Gaussian Blur, Canny Edge
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('me.png', 0)
img = cv2.resize(img, (0, 0), fx=0.5, fy=0.5)
# img = cv2.GaussianBlur(img, (5, 5), 0)
img = cv2.Laplacian(img, cv2.CV_64F)
img = np.uint8(np.absolute(img))
canny = cv2.Canny(img, 200, 200)# Dissemination,
@wermarter
wermarter / python_imagesearch_MAL.py
Created January 25, 2017 14:51
MAL Basic Image Search Engine
import pickle, cv2, sqlite3
import numpy as np
class BGRHist:
def __init__(self, bins):
self.bins = bins
def describe(self, img):
hist = cv2.calcHist([img], range(3), None, self.bins, [0, 256]*3)
cv2.normalize(hist, hist)
return hist.flatten()
class Searcher: