1
我試圖將圖像轉換爲Opencv(轉換爲numpy數組),並使用該數組將消息發佈到ROS節點上。我試圖通過下面的代碼「cv2.imdecode(numpyArray,cv2.CV_LOAD_IMAGE_COLOR)」返回無
fig.canvas.draw()
nparr = np.fromstring (fig.canvas.tostring_argb(), np.uint8)
print nparr
img_np = cv2.imdecode(nparr, cv2.CV_LOAD_IMAGE_COLOR)
print img_np
image_message = bridge.cv2_to_imgmsg(img_np, encoding="passthrough")
pub.publish(image_message)
但是,當我試着這樣做,我得到一個錯誤消息,做同樣的
AttributeError: 'NoneType' object has no attribute 'shape'
於是,我試着打印兩個numpy的數組,其值是值[255 191 191 ..., 191 191 191]
。而我不明白的是img_np
值是None
。我不知道我錯在哪裏。任何幫助表示讚賞。