Some changes

master^2
Davide Bongiovanni 6 years ago
parent 071236bc0e
commit 3ed89ee6dc

@ -1,10 +1,12 @@
import cv2
import time
import serial
from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler
from threading import Thread
import numpy as np
cap = cv2.VideoCapture(0)
cap = cv2.VideoCapture(-1)
font = cv2.FONT_HERSHEY_SIMPLEX
list_img = cv2.imread('list.jpg')
list_img = cv2.resize(list_img,None,fx=0.8, fy=0.8, interpolation = cv2.INTER_CUBIC)
@ -28,6 +30,15 @@ IMG_H = 720
rect_w = 220
rect_h = 52
weight = []
weight.append(1.0)
weight.append(1.0)
weight.append(1.0)
weight.append(1.0)
ARDUPORT = 'COM12'
# serial = serial.Serial(ARDUPORT, 115200, timeout=1)
test_candy_stat = []
s = {}
s['img_idx'] = 0
@ -68,9 +79,9 @@ def print_stats(img, stats):
# draw_rectangles(img, len(stats))
img[0:list_img.shape[0], IMG_W-list_img.shape[1]:IMG_W, :] = list_img[:]
for i in range(len(stats)):
cv2.putText(frame,str(stats[i]['loaded']),(IMG_W - 130,188 + i * (rect_h + 5)), font, 1.3,(0, 0, 0),2,cv2.LINE_AA)
cv2.putText(frame,"/",(IMG_W - 90,188 + i * (rect_h + 5)), font, 1.3,(0, 0, 0),2,cv2.LINE_AA)
cv2.putText(frame,str(stats[i]['required']),(IMG_W - 50,188 + i * (rect_h + 5)), font, 1.3,(0, 0, 0),2,cv2.LINE_AA)
cv2.putText(img,str(stats[i]['loaded']),(IMG_W - 130,188 + i * (rect_h + 5)), font, 1.3,(0, 0, 0),2,cv2.LINE_AA)
cv2.putText(img,"/",(IMG_W - 90,188 + i * (rect_h + 5)), font, 1.3,(0, 0, 0),2,cv2.LINE_AA)
cv2.putText(img,str(stats[i]['required']),(IMG_W - 50,188 + i * (rect_h + 5)), font, 1.3,(0, 0, 0),2,cv2.LINE_AA)
img[150+(rect_h + 5)*i:150+(rect_h + 5)*i + target_w, IMG_W-130-target_w-20:IMG_W-130-20, :] = img_list[stats[i]['img_idx']][:]
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
@ -86,12 +97,23 @@ with SimpleXMLRPCServer(('localhost', 8000),
# Run the server's main loop
t = Thread(target=async_server_megahack, args=(server,))
t.start()
frame_counter = 0
weight = 0
canvas = np.zeros((720, 1280, 3)).astype(np.uint8)
while True:
frame_counter += 1
if frame_counter == 75:
# serial.write(b'e')
# weight = -float(serial.readline()[:-2])
frame_counter = 0
print(weight)
# check weights
# check game satus
ret, frame = cap.read()
frame = cv2.resize(frame,None,fx=2, fy=1.5, interpolation = cv2.INTER_CUBIC)
print_stats(frame, test_candy_stat)
print(frame.shape)
cv2.imshow("window", frame)
frame = cv2.resize(frame,None,fx=1.5, fy=1.5, interpolation = cv2.INTER_CUBIC)
canvas[0:720, 0:960, :] = frame[:]
print_stats(canvas, test_candy_stat)
cv2.imshow("window", canvas)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

Loading…
Cancel
Save