mirror of https://github.com/commaai/tinygrad.git
This reverts commit e7f2f43331
.
This commit is contained in:
parent
e7f2f43331
commit
6b982621f8
|
@ -171,21 +171,24 @@ if __name__ == "__main__":
|
|||
from PIL import Image
|
||||
url = sys.argv[1]
|
||||
if url == 'webcam':
|
||||
import pygame
|
||||
pygame.init()
|
||||
SCALE = 3
|
||||
screen = pygame.display.set_mode((224*SCALE, 224*SCALE))
|
||||
pygame.display.set_caption("capture")
|
||||
|
||||
import cv2
|
||||
cap = cv2.VideoCapture(0)
|
||||
cap.set(cv2.CAP_PROP_BUFFERSIZE, 1)
|
||||
while 1:
|
||||
_ = cap.grab() # discard one frame to circumvent capture buffering
|
||||
ret, frame = cap.read()
|
||||
img = Image.fromarray(frame[:, :, [2,1,0]])
|
||||
out, retimg = infer(model, img)
|
||||
frame = Image.fromarray(frame[:, :, [2,1,0]])
|
||||
out, retimg = infer(model, frame)
|
||||
simg = cv2.resize(retimg, (224*SCALE, 224*SCALE))
|
||||
pygame.surfarray.blit_array(screen, np.array(simg).swapaxes(0,1))
|
||||
pygame.display.update()
|
||||
for e in pygame.event.get():
|
||||
pass
|
||||
print(np.argmax(out.data), np.max(out.data), lbls[np.argmax(out.data)])
|
||||
retimg = cv2.cvtColor(retimg, cv2.COLOR_RGB2BGR)
|
||||
cv2.imshow('capture', retimg)
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
break
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
else:
|
||||
img = Image.open(io.BytesIO(fetch(url)))
|
||||
st = time.time()
|
||||
|
|
Loading…
Reference in New Issue