Closer to game!

This commit is contained in:
cubernetes 2023-08-10 23:59:01 +02:00
parent 08a5f49559
commit a39279ee7f
4 changed files with 35 additions and 14 deletions

BIN
42.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View File

@ -15,6 +15,7 @@
*/ */
#include "config.h" #include "config.h"
#include <stdio.h>
#if !defined(__KERNEL__) #if !defined(__KERNEL__)
# if defined(HAVE_ENDIAN_H) # if defined(HAVE_ENDIAN_H)
@ -86,8 +87,8 @@ static int const rgb_weight[] =
/* List of glyphs */ /* List of glyphs */
static uint32_t ascii_glyphs[] = static uint32_t ascii_glyphs[] =
{ {
// ' ', '.', ':', ';', 't', '%', 'S', 'X', '@', '8', '?' ' ', '.', ':', ';', 't', '%', 'S', 'X', '@', '8', '?'
'#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' // '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#'
}; };
static uint32_t shades_glyphs[] = static uint32_t shades_glyphs[] =
@ -1183,9 +1184,8 @@ int caca_dither_bitmap(caca_canvas_t *cv, int x, int y, int w, int h,
} }
/* Now output the character */ /* Now output the character */
// printf("%d, %d, %d, %d\r\n", x, y, w, h); // HERE TIMO
caca_set_color_ansi(cv, outfg, outbg); caca_set_color_ansi(cv, outfg, outbg);
if (x == 5)
outch = '?';
caca_put_char(cv, x, y, outch); caca_put_char(cv, x, y, outch);
d->increment_dither(); d->increment_dither();

View File

@ -21,16 +21,42 @@ def main() -> NoReturn:
# pTime = 0 # pTime = 0
# cTime = 0 # cTime = 0
img = cv2.imread("42.png", 0)
if len(img.shape) == 2 or img.shape[2] == 1:
img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
img = cv2.flip(img, 1)
height, width, _ = img.shape
margin = 100
top_margin = margin + 20
bottom_margin = margin + 20
left_margin = margin
right_margin = margin
img = img[top_margin:height-bottom_margin, left_margin:width-right_margin]
side_length = min(640, 480) // 3
overlay_resized = cv2.resize(img, (side_length, side_length))
print(repr(overlay_resized))
input()
sys.exit()
while True: while True:
success, frame = cap.read() success, frame = cap.read()
if not success:
continue
imgRGB = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) imgRGB = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
results = hands.process(imgRGB) results = hands.process(imgRGB)
h, w, c = frame.shape
img_x, img_y = 10, 10
frame[img_y:img_y+side_length, img_x:img_x+side_length] = overlay_resized
if results.multi_hand_landmarks: if results.multi_hand_landmarks:
for handLms in results.multi_hand_landmarks: for handLms in results.multi_hand_landmarks:
visited_7 = False visited_7 = False
for id, lm in enumerate(handLms.landmark): for id, lm in enumerate(handLms.landmark):
h, w, c = frame.shape
cx = int(lm.x * w) cx = int(lm.x * w)
cy = int(lm.y * h) cy = int(lm.y * h)
# 7 one-before-index, 8 index, 4 thumb, 0 base # 7 one-before-index, 8 index, 4 thumb, 0 base
@ -73,9 +99,6 @@ def main() -> NoReturn:
# cv2.putText(frame, str(int(fps)), (10,70), cv2.FONT_HERSHEY_PLAIN, 3, (255, 0, 255), 3) # cv2.putText(frame, str(int(fps)), (10,70), cv2.FONT_HERSHEY_PLAIN, 3, (255, 0, 255), 3)
if not success:
continue
sys.stdout.buffer.write(frame.tobytes()) sys.stdout.buffer.write(frame.tobytes())
# cv2.imshow("Image", frame) # cv2.imshow("Image", frame)
# cv2.waitKey(1) # cv2.waitKey(1)

View File

@ -1,7 +1,5 @@
#!/bin/sh #!/bin/sh
# st -f 'SauceCodePro Nerd Font Mono' -e sh -c '2>/dev/null ffmpeg -re -i /dev/video0 -noautoscale -map 0:V:0 -filter:v "fps=fps=30,format=gray,hflip" -c:v libx265 -preset ultrafast -tune zerolatency -crf 30 -f nut - | TERM=xterm-mono CACA_DRIVER=ncurses DISPLAY= mpv --really-quiet --no-cache --no-config --vo=caca --untimed --profile=low-latency --fps=30 -' # xterm -bg black -fg white -s -fullscreen -fa 'SauceCodePro Nerd Font Mono' -fs 8 -e '{ ./track_hand.py | 2>/dev/null ffmpeg -y -f rawvideo -s 640x480 -pix_fmt bgr24 -i - -map 0:V:0 -filter:v "format=gray,hflip" -c:v libx264 -preset ultrafast -tune zerolatency -crf 30 -f nut - | TERM=xterm-mono CACA_DRIVER=ncurses DISPLAY= mpv --really-quiet --no-cache --no-config --vo=caca --untimed --profile=low-latency - || { echo Error 1>&2; read X; }; }'
# st -f 'SauceCodePro Nerd Font Mono:size=10' -e sh -c '{ ./track_hand.py | 2>/dev/null ffmpeg -y -f rawvideo -s 640x480 -pix_fmt bgr24 -i - -map 0:V:0 -filter:v "format=gray,hflip" -c:v libx265 -preset ultrafast -tune zerolatency -crf 30 -f nut - | TERM=xterm-mono CACA_DRIVER=ncurses DISPLAY= mpv --really-quiet --no-cache --no-config --vo=caca --untimed --profile=low-latency - || { echo Error 1>&2; read X; }; } | ./game.py'
# xterm -bg black -fg white -s -fullscreen -fa 'SauceCodePro Nerd Font Mono' -fs 8 -e '2>/dev/null ffmpeg -re -i /dev/video0 -noautoscale -map 0:V:0 -filter:v "fps=fps=30,format=gray,hflip" -c:v libx265 -preset ultrafast -tune zerolatency -crf 30 -f nut - | TERM=xterm-mono CACA_DRIVER=ncurses DISPLAY= mpv --really-quiet --no-cache --no-config --vo=caca --untimed --profile=low-latency --fps=30 -; read X' st -f 'SauceCodePro Nerd Font Mono:size=10' -e sh -c '{ ./track_hand.py | 2>/dev/null ffmpeg -y -f rawvideo -s 640x480 -pix_fmt bgr24 -i - -map 0:V:0 -filter:v "format=gray,hflip" -c:v libx265 -preset ultrafast -tune zerolatency -crf 30 -f nut - | TERM=xterm-mono CACA_DRIVER=ncurses DISPLAY= mpv --really-quiet --no-cache --no-config --vo=caca --untimed --profile=low-latency - || { echo Error 1>&2; read X; }; }'
# st -f 'SauceCodePro Nerd Font Mono:size=10' -e sh -c '{ ./track_hand.py | 2>/dev/null ffmpeg -y -f rawvideo -s 640x480 -pix_fmt bgr24 -i - -map 0:V:0 -filter:v "format=gray,hflip" -c:v libx264 -preset ultrafast -tune zerolatency -crf 30 -f nut - | TERM=xterm-mono CACA_DRIVER=ncurses DISPLAY= mpv --really-quiet --no-cache --no-config --vo=tct --untimed --profile=low-latency - || { echo Error 1>&2; read X; }; }'
# st -f 'SauceCodePro Nerd Font Mono' -e sh -c '{ 2>/dev/null ./track_hand.py | 2>/dev/null ffmpeg -y -f rawvideo -s 640x480 -pix_fmt bgr24 -i - -map 0:V:0 -filter:v "format=gray,hflip" -c:v libx264 -preset ultrafast -tune zerolatency -crf 30 -f nut - | TERM=xterm-mono CACA_DRIVER=ncurses DISPLAY= mpv --really-quiet --no-cache --no-config --vo=tct --untimed --profile=low-latency - || { echo Error 1>&2; read X; }; }'
st -f 'SauceCodePro Nerd Font Mono' -e sh -c '{ 2>/dev/null ./track_hand.py | 2>/dev/null ffmpeg -y -f rawvideo -s 640x480 -pix_fmt bgr24 -i - -map 0:V:0 -filter:v "hflip" -c:v libx265 -preset ultrafast -tune zerolatency -crf 30 -f nut - | TERM=xterm-mono CACA_DRIVER=ncurses DISPLAY= mpv --really-quiet --no-cache --no-config --vo=caca --untimed --profile=low-latency - || { echo Error 1>&2; read X; }; }'