-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31c95dc
commit 30eb890
Showing
4 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "rumble-web"] | ||
path = rumble-web | ||
url = https://github.com/NovaSagittarii/rumble-web |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import subprocess | ||
import os | ||
import sys | ||
|
||
import tkinter | ||
from tkinter import ttk | ||
from PIL import ImageTk, Image | ||
# from tkinter import Image, ImageTk | ||
|
||
from removegreen import convert as processImage | ||
|
||
# print(processImage("./nate-doublepunch")) | ||
|
||
def vsum(a, b): | ||
return tuple(a[i] + b[i] for i in range(len(a))) | ||
def processSprites(folder): | ||
vals = [] | ||
files = os.listdir(folder) | ||
filesOut = [] | ||
for i, filename in enumerate(files): | ||
if "out" in filename: continue | ||
os.system(f"title {i} of {len(files)}") | ||
path = os.path.join(folder, filename) | ||
coords = processImage(path) | ||
# x = -(coords['left'] + coords['right'])/2 | ||
# y = -(coords['bottom'] + coords['top'])/2 | ||
x,y = 0,0 | ||
vals.append((x, y)) | ||
filesOut.append(coords['file']); | ||
delta = [vsum(vals[i], list(-x for x in vals[i-1 if i > 1 else i])) for i in range(len(vals))] | ||
|
||
# def savePosn(event): | ||
# global lastx, lasty | ||
# lastx, lasty = event.x, event.y | ||
|
||
# def addLine(event): | ||
# canvas.create_line((lastx, lasty, event.x, event.y)) | ||
# savePosn(event) | ||
|
||
global framecount | ||
global pos | ||
global fstart | ||
global fend | ||
|
||
pos = (0, 0) | ||
framecount = 0 | ||
fstart = 0 | ||
fend = 100 | ||
def mousedown(event): | ||
global pos | ||
global framecount | ||
framecount = event.x | ||
# print(event.x) | ||
pos = (0, 0) | ||
def restart(): | ||
global framecount | ||
framecount = 0 | ||
|
||
print(filesOut[0]) | ||
im = Image.open(filesOut[0]) | ||
print(im.mode) | ||
|
||
global yumyum | ||
yumyum = [] | ||
|
||
def nextframe(): | ||
global pos | ||
global framecount | ||
global yumyum | ||
global fstart | ||
global fend | ||
i = fstart+ ( (framecount) % (min(fend, len(delta))-fstart) ) | ||
pos = vsum(pos, delta[i]) | ||
dx, dy = 0,0 #vals[i] | ||
|
||
canvas.delete("all") | ||
myimg = ImageTk.PhotoImage(file=filesOut[i]) | ||
yumyum = myimg | ||
# img=ImageTk.PhotoImage(Image.open("camels.jpg")) | ||
# canvas.create_image(250, 250, anchor=CENTER, image=img) | ||
|
||
# photoimage = ImageTk.PhotoImage(file="example.png") | ||
# canvas.create_image(150, 150, image=photoimage) | ||
|
||
# canvas.create_image(-pos[0]+dx, -pos[1]+dy, image=myimg, anchor='nw') | ||
canvas.create_image(100, 100, image=myimg) # anchor='nw') | ||
canvas.create_text(20, 20, text=f'{fstart}->{fend} {framecount} {i}', anchor='nw', font='TkMenuFont', fill='red') | ||
|
||
framecount += 1 | ||
root.after(30, nextframe) | ||
|
||
root = tkinter.Tk() | ||
# root.columnconfigure(0, weight=1) | ||
# root.rowconfigure(0, weight=1) | ||
# root.geometry("400x400") | ||
|
||
canvas = tkinter.Canvas(root, width=400, height=400, background='white') | ||
# canvas.grid(column=0, row=0, sticky=(N, W, E, S)) | ||
canvas.bind("<Button-1>", mousedown) | ||
# canvas.bind("<Button-1>", savePosn) | ||
# canvas.bind("<B1-Motion>", addLine) | ||
canvas.pack() | ||
|
||
def setstart(): | ||
global fstart | ||
fstart = int(inputtxt.get(1.0, "end-1c")) | ||
def setend(): | ||
global fend | ||
fend = int(inputtxt.get(1.0, "end-1c")) | ||
|
||
# TextBox Creation | ||
inputtxt = tkinter.Text(root, height=1, width=20) | ||
inputtxt.pack() | ||
# Button Creation | ||
printButton = tkinter.Button(root, text="start", command=setstart) | ||
printButton.pack() | ||
printButton = tkinter.Button(root, text="end", command=setend) | ||
printButton.pack() | ||
printButton = tkinter.Button(root, text="reset", command=restart) | ||
printButton.pack() | ||
|
||
root.after(30, nextframe) | ||
root.mainloop() | ||
|
||
return ("// END //",) | ||
|
||
def main(): | ||
# Load image and convert it to RGBA, so it contains alpha channel | ||
# print(sys.argv) | ||
file_path = sys.argv[1] if len(sys.argv) >= 2 else "nate-fullanphufightsource" | ||
print(processSprites(file_path)) | ||
|
||
if __name__ == '__main__': | ||
main() | ||
|
||
# https://stackoverflow.com/questions/2810970/how-to-remove-a-green-screen-portrait-background |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# https://github.com/kimmobrunfeldt/howto-everything/blob/master/remove-green.md | ||
|
||
""" | ||
Removes greenscreen from an image. | ||
Usage: python greenscreen_remove.py image.jpg | ||
""" | ||
|
||
from PIL import Image | ||
import sys | ||
import os | ||
|
||
def rgb_to_hsv(r, g, b): | ||
maxc = max(r, g, b) | ||
minc = min(r, g, b) | ||
v = maxc | ||
if minc == maxc: | ||
return 0.0, 0.0, v | ||
s = (maxc-minc) / maxc | ||
rc = (maxc-r) / (maxc-minc) | ||
gc = (maxc-g) / (maxc-minc) | ||
bc = (maxc-b) / (maxc-minc) | ||
if r == maxc: | ||
h = bc-gc | ||
elif g == maxc: | ||
h = 2.0+rc-bc | ||
else: | ||
h = 4.0+gc-rc | ||
h = (h/6.0) % 1.0 | ||
return h, s, v | ||
|
||
GREEN_RANGE_MIN_HSV = (100, 60, 70) # (100, 80, 70) | ||
GREEN_RANGE_MAX_HSV = (185, 255, 255) | ||
|
||
def convert(file_path): | ||
name, ext = os.path.splitext(file_path) | ||
im = Image.open(file_path) | ||
im = im.convert('RGBA') | ||
|
||
# Go through all pixels and turn each 'green' pixel to transparent | ||
|
||
output = {} | ||
newfile = name + '-out.png' | ||
output['file'] = newfile | ||
skip = True | ||
|
||
if not skip: | ||
pix = im.load() | ||
width, height = im.size | ||
for x in range(width): | ||
for y in range(height): | ||
r, g, b, a = pix[x, y] | ||
h_ratio, s_ratio, v_ratio = rgb_to_hsv(r / 255.0, g / 255.0, b / 255.0) | ||
h, s, v = (h_ratio * 360, s_ratio * 255, v_ratio * 255) | ||
|
||
min_h, min_s, min_v = GREEN_RANGE_MIN_HSV | ||
max_h, max_s, max_v = GREEN_RANGE_MAX_HSV | ||
if min_h <= h <= max_h and min_s <= s <= max_s and min_v <= v <= max_v: | ||
pix[x, y] = (0, 0, 0, 0) | ||
im.save(newfile) | ||
return output | ||
def main(): | ||
# Load image and convert it to RGBA, so it contains alpha channel | ||
# print(sys.argv) | ||
file_path = sys.argv[1] | ||
convert(file_path) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Submodule rumble-web
added at
ac75b4