fixed issue where non-binary images where in dataset at the cost of .bmp increasing the size by 2. Made it so id.py prevents their future inclusion.

This commit is contained in:
Caroline Marceano 2024-06-08 13:41:53 +09:00
parent 7b50a63cff
commit 40766115a9
5 changed files with 29 additions and 33 deletions

View file

@ -1 +1 @@
cat ./src/db/schema/schema.sql | sqlite3 ./src/dbmariokart.db
cat ./src/db/schema/schema.sql | sqlite3 ./src/db/mariokart.db

View file

@ -3,7 +3,8 @@ from PIL import Image
import base64
import sqlite3
import hashlib
import numpy as np
from lib.dbtools import print_image
#This is a much updated version of the older ID. This one marks the exit from the ascii days of this project
#As did before. you add your images into id/x (1 .. 2 .. 3), and include a bunch. One full black, and one full white at the bare minimum
#this generates a 0 and 1 representation of that data allowing for classifying. the images based upon this data.
@ -14,7 +15,6 @@ rank_to_pixelarray = {}
for digit in range(1, 13):
one_holder = []
images = []
binary = []
base = f"id/{digit}"
files = os.listdir(base)
im = Image.open(f'{base}/{files[0]}')
@ -29,26 +29,26 @@ for digit in range(1, 13):
for image in images:
#because of the binary image setup, it only returns 1 value.
#encase it isn't binary
if type(image[0,0]) != int:
if image[x,y][0] == 0:
binary.append(0)
break
if image[x,y] == 0:
binary.append(0)
value = image[x,y]
if type(value) == tuple:
value = value[0]
if value != 255:
break
assert value != 255 or value != 0
#for-elses only execute if the for loop doesn't break
else:
binary.append(1)
one_holder.append((x,y))
for x in range(0, im.size[1]):
holder = []
for y in range(0, im.size[0]):
holder.append(str(binary[(x*im.size[0])+y]))
print("".join(holder))
empty = np.zeros((im.size[0], im.size[1]), dtype=np.uint8)
for x in one_holder:
empty[x] = 1
print_image(empty, inverted=True)
rank_to_pixelarray[digit] = one_holder
#I'm afraid python may oneday change the __str__ for Dict and then this will create a version issue...
raw_string = str(rank_to_pixelarray)
encoded = raw_string.encode('ascii')
base64_encoded = base64.b64encode(encoded)

Binary file not shown.

View file

@ -14,7 +14,7 @@ import lz4.frame
import sqlite3
import hashlib
from lib.classes import RankEvent, ProcessReturn, State
debug = False
debug = True
def get_2d_value(n, width):
@ -56,11 +56,7 @@ def deserialize_bitfield_video(bit_array, height, width):
return np.unpackbits(frames).reshape((output_frame_count, height, width))
def print_image(a):
for row in np.rollaxis(a, 0, 0):
pythonified = row.tobytes()
output = map(lambda x: str(int(int(x) == 1)), pythonified)
print(''.join(output))
def process_ranks(events : List[RankEvent], minimum_length : int):
#Removes transients of a given amount

View file

@ -2,19 +2,11 @@ import sqlite3
import matplotlib.pyplot as plt
import pickle
import more_itertools as it
from compile import deserialize_bitfield_frame, print_image, deserialize_bitfield_video, compile
from lib.compile import deserialize_bitfield_frame, deserialize_bitfield_video, compile
import lz4.frame
import cv2
import numpy as np
con = sqlite3.connect("../db/mariokart.db")
race_id = 7
cur = con.cursor()
class mock_state():
def __init__(self, video_data, channel_name, date):
self.video_data = video_data
self.channel_name = channel_name
self.date = date
from lib.classes import State
def get_archived_video(con, cur, race_id):
video_prepare = cur.execute("select VideoDataBinaryLZ4 from Race where Id = ? ", (race_id,))
video = video_prepare.fetchall()[0][0]
@ -37,9 +29,17 @@ def recompile(cur, con, race_id, model_id):
info_prepare = cur.execute("select UploadDate, Uploader from Race where Id = ? ", (race_id,))
date, channel_name = info_prepare.fetchone()
video_data = prepare_video_for_export(get_archived_video(con, cur, race_id))
state = mock_state(video_data, channel_name, date)
state = State(channel_name, date, "./db/mariokart.db")
state.video_data = video_data
compile(state, model_id=model_id, recompile=True, race_id=race_id)
def print_image(a, inverted = False):
axis = 0
if inverted: axis = 1
for row in np.rollaxis(a, axis, 0):
pythonified = row.tobytes()
output = map(lambda x: str(int(int(x) == 1)), pythonified)
print(''.join(output))
#recompile(con, cur, 7, -1)
#for_export = prepare_video_for_export(get_archived_video(con, cur, race_id))
#data = np.concatenate(np.concatenate(for_export[583:583+20].reshape(4, 5, 80, 110), axis=1), axis=1)