Skip to content

Instantly share code, notes, and snippets.

import numpy as np
from os import listdir
from os.path import isfile, join
from PIL import Image
from sklearn.datasets.base import Bunch
from sklearn import svm
from sklearn.naive_bayes import MultinomialNB
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
# This does work by using only one sample:
data = [[0,0,0,0,0,0,0,0,0,2,1]]
data = np.array(data, dtype=float)
target = [0,0,0,0,0,0,0,0,2,1,0]
from PIL import Image, ImageDraw, ImageFont, ImageOps
import numpy as np
import random
try:
unichr
except NameError:
unichr = chr
def render(input_arr):
output = input_arr
from pybrain.structure import FeedForwardNetwork
from pybrain.structure import LinearLayer, SigmoidLayer
from pybrain.structure import FullConnection
from pybrain.rl.agents import LearningAgent
from PIL import Image, ImageDraw, ImageFont, ImageOps
import numpy as np
import copy
def mse(imageA, imageB):
# the 'Mean Squared Error' between the two images is the
@steveway
steveway / create_clock.py
Created November 9, 2017 15:23
Create Clock images with separate masks.
# -*- coding: utf-8 -*-
from PIL import Image, ImageDraw, ImageFont, ImageOps
import numpy as np
import os
width = 600
halfwidth = width/2
avatarsize = 48
height = 800
background_color = (255, 255, 255, 0)
@steveway
steveway / gmplay_with_addon.c
Last active May 7, 2019 00:09
This should add the ability to overlay images on a gmv video.
//====================================================
// gmplay 2.1 - geekmaster's kindle video player
// Copyright (C) 2012 by geekmaster, with MIT license:
// http://www.opensource.org/licenses/mit-license.php
// Modified by Stefan Murawski ([email protected])
//----------------------------------------------------
// Tested on DX,DXG,K3,K4main,K4diags,K5main,K5diags.
//----------------------------------------------------
#include <sys/ioctl.h> // ioctl
#include <sys/mman.h> // mmap, munmap
@steveway
steveway / st_dither2.pyx
Last active April 19, 2017 09:16
Cython version of the ordered dither function, immensely faster!
import numpy as np
cimport numpy as np
cimport cython
DTYPE = np.double
ctypedef np.double_t DTYPE_t
DTYPE2 = np.uint8
ctypedef np.uint8_t DTYPE2_t
@cython.boundscheck(False) # turn off bounds-checking for entire function
@steveway
steveway / st_dither.py
Created April 18, 2017 15:51
Belongs to the opencvvideoclock.py, test using cython for this.
import numpy as np
def apply_ordered_dither(inputarray, bayer_map, bayer_size):
width, height = inputarray.shape
for y in range(height):
for x in range(width):
inputarray[x, y] = 0 if inputarray[x, y] < bayer_map[x % bayer_size, y % bayer_size] else 255
return inputarray
@steveway
steveway / gmvplayer.py
Last active May 16, 2017 09:48
A videoplayer able to play back gmv and gzipped gmv files
import numpy as np
import cv2
import gzip
import sys, os
from time import sleep, time
def main():
width = 600
height = 800
@steveway
steveway / raw2gmv.py
Created April 11, 2017 15:41
Port of raw2gmv.c to Python
# //====================================================
# // raw2gmv 1.0a - raw to geekmaster video transcoder
# // Copyright (C) 2012 by geekmaster, with MIT license:
# // http://www.opensource.org/licenses/mit-license.php
# //----------------------------------------------------
##include <stdio.h> // stdin,stdout
# typedef unsigned char u8; typedef unsigned int u32;
# int main(void) {
# u8 o,to,tb,wb0[800*600]; u32 x,y,xi,yi,c=250,b=120; // c=contrast, b=brightness
# while (fread(wb0,800*600,1,stdin)) for (y=0;y<800;y++) { xi=y; tb=0;