我正在尝试从 flea3 相机(代码为“FL3-U3-32S2C-CS”,显示其为彩色相机)获取彩色图像(在我的情况下 rgb 或 bgr 没有区别),但我的代码生成灰度照片.. . 下面的代码片段有什么问题?任何的想法?
# Begin acquiring images
cam.BeginAcquisition()
# Retrieve next image and convert it
image_result = cam.GetNextImage()
img_converted = image_result.Convert(PySpin.PixelFormat_RGB8, PySpin.HQ_LINEAR)
# Convert the Image object to RGB array
width = image_result.GetWidth()
height = image_result.GetHeight()
rgb_array = img_converted.GetData()
rgb_array = rgb_array.reshape(height, width, 3)
Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的文本文件:
但所有 unicode 字符都需要用相应的字符替换,并且应该如下所示:
问题是我不想自己替换所有 unicode 代码,自动执行此操作的最有效方法是什么?我的代码现在看起来像这样,但它确实需要改进!(代码在 Python3 中)
import io
input = io.open("input.json", "r", encoding="utf-8")
output = io.open("output.txt", "w", encoding="utf-8")
with input, output:
# Read input file.
file = input.read()
file = file.replace("\\u00e4", "ä")
# I think last line is the same as line below:
# file = file .replace("\\u00e4", u"\u00e4")
file = file.replace("\\u00c4", "Ä")
file = file.replace("\\u00f6", "ö")
file = file.replace("\\u00d6", "Ö")
.
.
.
# I cannot put all codes in unicode here manually!
. …Run Code Online (Sandbox Code Playgroud) 我试图绘制两个更新图,一个是图表,另一个是从相机捕获的图像。
我在这一行收到一个错误:
"current_line.set_data(y_data)" in the "update" function.
The error says: "AttributeError: 'list' object has no attribute 'set_data'".
Run Code Online (Sandbox Code Playgroud)
知道为什么我会收到此错误吗?如果我注释掉这一行,我将从相机中获取不断变化的图像,除第二个图外的所有内容看起来都很好(因为第二个图未更新)但我也需要更新第二个图。
y_data = [0]
# Capture intial frame
ret, initial_frame = lsd.cap.read()
# Function for making the initial figure
def makeFigure():
fig = plt.figure()
# Show frame
ax1 = plt.subplot2grid((2, 2), (0, 0), colspan=2)
plot_frame = ax1.imshow(initial_frame, animated=True)
# Set the limits of the plot and plot the graph
ax2 = plt.subplot2grid((2, 2), (1, 0), colspan=2)
ax2.set_title('Title')
ax2.set_ylabel('Y-Label')
ax2.set_ylim(0, 100)
ax2.set_xlim(0, 100)
ax2.grid() …Run Code Online (Sandbox Code Playgroud)