diff --git a/HACKATHON REPORT BY RUN-TIME ERROR.pdf b/HACKATHON REPORT BY RUN-TIME ERROR.pdf new file mode 100644 index 0000000..81b55fc Binary files /dev/null and b/HACKATHON REPORT BY RUN-TIME ERROR.pdf differ diff --git a/images/s1.png b/images/s1.png new file mode 100644 index 0000000..49ab068 Binary files /dev/null and b/images/s1.png differ diff --git a/images/s2.png b/images/s2.png new file mode 100644 index 0000000..5e27b38 Binary files /dev/null and b/images/s2.png differ diff --git a/images/s3.png b/images/s3.png new file mode 100644 index 0000000..4ad4a42 Binary files /dev/null and b/images/s3.png differ diff --git a/images/s4.png b/images/s4.png new file mode 100644 index 0000000..b39b611 Binary files /dev/null and b/images/s4.png differ diff --git a/stick_hero_1.py b/stick_hero_1.py new file mode 100644 index 0000000..d30c386 --- /dev/null +++ b/stick_hero_1.py @@ -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) \ No newline at end of file