Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PYTHON-HACKATHON by RUNTIME-ERROR #4

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added HACKATHON REPORT BY RUN-TIME ERROR.pdf
Binary file not shown.
Binary file added images/s1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/s2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/s3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/s4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions stick_hero_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import numpy as np
import os
from matplotlib import pyplot as plt
import pause
import cv2

rate = 0.51
def srcTarget(rcord):
prev=rcord[0]
for i in rcord:
# print(prev,i)
if abs(i-prev) > 10:
return i, prev + 5 # +5 is just to vaguely compenate for extra distance where stick rises
prev=i
while True:

os.system('adb shell screencap -p /sdcard/screencap.png')
os.system('adb pull /sdcard/screencap.png')

# read the image using openCV
img = cv2.imread('screencap.png')
screen_height, screen_width, _ = img.shape

img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)

yf, xf, zf = np.shape(img)
yf = yf/2280
xf = xf/1080

img_crop = img[int(np.floor(1500*yf)):int(np.floor(1640*yf)), :]
y_crop, x_crop, z_crop = np.shape(img_crop)

""" setting all the rgb values to ZERO gives black color, here we do the same using np.zeros_like() """
my_img = np.zeros_like(img_crop)

rcord=set()

for j in range(y_crop):
for k in range(x_crop):
if(((img_crop[j,k,0]==255) and (img_crop[j,k,1]==0) and (img_crop[j,k,2]==0)) or ((img_crop[j,k,0]==247) and (img_crop[j,k,1]==27) and (img_crop[j,k,2]==27))):
my_img[j,k,0] = 0
my_img[j,k,1] = 255
my_img[j,k,2] = 0
rcord.add(k) # record the x-coordinates of your red-color cells in a set

# sort the elements in the set in ascending order and make a list

rcord = sorted(rcord)
target, src = srcTarget(rcord)

dist = abs(src-target)
rate = 1.0475 * (screen_width/1080)
time = str(int(dist/rate))

print(dist)

""" just fix some x, y coordinate to swipe on the screen, with time already calculated before """

x = str(int(np.ceil(530*yf)))
y = str(int(np.ceil(830*xf)))

os.system('adb shell input touchscreen swipe ' + x + ' ' + x + ' ' + y + ' ' + y + ' ' + time)
pause.seconds(2)