def main():
# Load the Inception model so it is ready for classifying images.
try:
model = inception.Inception()
except FileNotFoundError:
print ('###### warning ######')
print ('this script requires inception.maybe_download() executed at least once, running it now')
inception.maybe_download()
model = inception.Inception()
while True:
try:
start_time_camera = time.time()
cam.start()
# start and stop prevent the buffer from filling up with more useless frames
img = cam.get_image()
cam.stop()
image = pygame.surfarray.array3d(img)
image = np.rot90(image, 3)
end_time_camera = time.time()
start_time = time.time()
print ("Classifying image from camera...")
with warnings.catch_warnings():
warnings.simplefilter("ignore")
classify(model=model, image=image)
end_time = time.time()
time_dif_camera = end_time_camera - start_time_camera
time_dif = end_time - start_time
# Print the time-usage.
print ('###### time usage camera ######')
print(str(timedelta(seconds=int(round(time_dif_camera)))))
print ('###### time usage NN ######')
print(str(timedelta(seconds=int(round(time_dif)))))
# Save the image that was just classified (for debug)
im = Image.fromarray(image)
im.save(image_path)
except (KeyboardInterrupt, SystemExit, RuntimeError, SystemError):
cam.stop()
model.close()
评论列表
文章目录