|
|
from PIL import Image |
|
|
import io |
|
|
import os |
|
|
import time |
|
|
import requests |
|
|
import msgpack |
|
|
import base64 |
|
|
import numpy as np |
|
|
from io import BytesIO |
|
|
def select_frames(input_frames, num_segments = 10): |
|
|
indices = np.linspace(start=0, stop=len(input_frames)-1, num=num_segments).astype(int) |
|
|
frames = [input_frames[ind] for ind in indices] |
|
|
return frames |
|
|
|
|
|
tic = time.time() |
|
|
video_dir = './images/' |
|
|
frames = [(os.path.splitext(item)[0], os.path.join(video_dir, item)) for item in os.listdir(video_dir)] |
|
|
frames = [item[1] for item in sorted(frames, key=lambda x: x[0])] |
|
|
|
|
|
image_paths = select_frames(frames, num_segments=10) |
|
|
|
|
|
request = {} |
|
|
byte_images = [] |
|
|
for image_path in image_paths: |
|
|
img = Image.open(image_path) |
|
|
byte_io = BytesIO() |
|
|
img.save(byte_io, format='PNG') |
|
|
encoded_image = base64.b64encode(byte_io.getvalue()).decode('utf-8') |
|
|
byte_images.append(encoded_image) |
|
|
|
|
|
|
|
|
|
|
|
payload = { |
|
|
"images": byte_images, |
|
|
} |
|
|
|
|
|
|
|
|
IP = '10.100.193.192' |
|
|
url = f'http://{IP}:8001/generate' |
|
|
headers = {'Content-Type': 'application/json'} |
|
|
|
|
|
tic1 = time.time() |
|
|
|
|
|
response = requests.post(url, json=payload, headers=headers) |
|
|
toc = time.time() |
|
|
print(response.text) |
|
|
|
|
|
print('stage 1', tic1 - tic) |
|
|
print('stage 2', toc - tic1) |