import cv2
import plotly.graph_objs as go
from IPython.display import HTML
state = ['safe driving', 'texting - right', 'talking on the phone - right', 'texting - left', 'talking on the phone - left',
'operating the radio', 'drinking', 'reaching behind', 'hair and makeup', 'talking to passenger', 'UNKNOWN']
def Display(path, Class=None):
img = cv2.imread(path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
if Class is None:
return go.Figure(data=[go.Image(z=img)])
else:
return go.Figure(data=[go.Image(z=img)], layout=go.Layout(title=state[Class]))
# Create subplots
fig = go.Figure()
fig.update_layout(
title="Images",
grid=dict(rows=2, columns=5),
)
# Add images to the subplots
fig.add_trace(Display("/content/imgs/train/c0/img_100026.jpg", 0), row=1, col=1)
fig.add_trace(Display("/content/imgs/train/c1/img_100021.jpg", 1), row=1, col=2)
fig.add_trace(Display("/content/imgs/train/c2/img_100029.jpg", 2), row=1, col=3)
fig.add_trace(Display("/content/imgs/train/c3/img_100006.jpg", 3), row=1, col=4)
fig.add_trace(Display("/content/imgs/train/c4/img_100225.jpg", 4), row=1, col=5)
fig.add_trace(Display("/content/imgs/train/c5/img_10000.jpg", 5), row=2, col=1)
fig.add_trace(Display("/content/imgs/train/c6/img_100036.jpg", 6), row=2, col=2)
fig.add_trace(Display("/content/imgs/train/c7/img_100057.jpg", 7), row=2, col=3)
fig.add_trace(Display("/content/imgs/train/c8/img_100015.jpg", 8), row=2, col=4)
fig.add_trace(Display("/content/imgs/train/c9/img_100090.jpg", 9), row=2, col=5)
# Update layout
fig.update_layout(showlegend=False)
# Save the figure as an HTML file
fig.write_html("/content/plotly_images.html")
# Display the HTML file using an iframe
HTML(filename="/content/plotly_images.html")