[英]Plotly - How to highlight two results from two figures in the same plot
[英]How to overlay two image figures plotly (python)
我正在嘗試在 plotly 中的圖像上覆蓋蒙版。 例如,我正在嘗試像使用兩個散點圖一樣執行此操作,但是錯誤表明在將圖形添加到跟蹤時數據屬性是錯誤的。
rgb_pad_removed, thermal_img = get_thermal_and_rgb(img_path)
img, mask = get_masked_image(rgb_pad_removed)
thermal_img_resized = cv2.resize(thermal_img, dsize=(mask.shape[1], mask.shape[0]), interpolation=cv2.INTER_CUBIC)
from plotly.subplots import make_subplots
f1 = px.imshow(rgb_pad_removed)
f2 = px.imshow(mask)
fig = make_subplots()
fig.add_trace(f1)
fig.add_trace(f2)
fig.show()
出現以下錯誤:
ValueError:
Invalid element(s) received for the 'data' property of
Invalid elements include: [Figure({
ect...
我使用的是正確的方法還是有更好的方法?
這里的問題是,您將圖形添加為跟蹤。 add_trace 僅支持跟蹤 object。 Trace 基本上是 Scatter 或 Bar。 您已添加一個圖形作為跟蹤。 這就是這里的錯誤。
要屏蔽圖像,您可以這樣做。 獲取您的圖像並從 opencv 添加掩碼並顯示圖像。 我添加了一個例子。 請檢查一下。
import numpy as np
import plotly.express as px
img_rgb = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]],
[[0, 255, 0], [0, 0, 255], [255, 0, 0]]
], dtype=np.uint8)
mask = np.array([[0, 1, 0],
[0, 1, 0]], dtype=np.uint8)
result = cv2.bitwise_and(img_rgb, img_rgb2, mask=mask)
f1 = px.imshow(result)
f1.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.