相机提供GREYSCALE数据,而深度学习模型则需要BGR。是否可以通过使用opencv或numpy或其他任何东西“堆叠”灰度图像来创建人造bgr图像?
我正在使用其他人创建的两个ROS软件包。 我尝试了以下方法:
尝试更改模型以接受原始存储库中所述的灰度。
尝试使用
将灰度转换为bgrnp_image = cv2.cvtColor(np_image, cv2.COLOR_GRAY2BGR)
试图创建一个包含图像乘以三的数组
np_image = np.array([np_image, np_image, np_image])
以下代码检索图像
def run(self):
self._result_pub = rospy.Publisher('~result', Result, queue_size=1)
vis_pub = rospy.Publisher('~visualization', Image, queue_size=1)
sub = rospy.Subscriber('~input', Image,
self._image_callback, queue_size=1)
rate = rospy.Rate(self._publish_rate)
while not rospy.is_shutdown():
if self._msg_lock.acquire(False):
msg = self._last_msg
self._last_msg = None
self._msg_lock.release()
else:
rate.sleep()
continue
if msg is not None:
np_image = self._cv_bridge.imgmsg_to_cv2(msg,
desired_encoding='mono8')
#np_image = cv2.cvtColor(np_image, cv2.COLOR_GRAY2BGR) #(fail)
np_image = np.array([np_image, np_image, np_image])
# Run detection
results = self._model.detect([np_image], verbose=0)
result = results[0]
result_msg = self._build_result_msg(msg, result)
self._result_pub.publish(result_msg)
def _image_callback(self, msg):
rospy.logdebug("Get an image")
if self._msg_lock.acquire(False):
self._last_msg = msg
self._msg_lock.release()
我希望模型检索数据,评估数据并返回对象ID和掩码。但是,出现以下错误:
Traceback (most recent call last):
File "/home/riwo-rack-pc/ROS_Mask_rcnn/src/mask_rcnn_ros/nodes/mask_rcnn_node", line 196, in <module>
main()
File "/home/riwo-rack-pc/ROS_Mask_rcnn/src/mask_rcnn_ros/nodes/mask_rcnn_node", line 192, in main
node.run()
File "/home/riwo-rack-pc/ROS_Mask_rcnn/src/mask_rcnn_ros/nodes/mask_rcnn_node", line 116, in run
results = self._model.detect([np_image], verbose=0)
File "/home/riwo-rack-pc/ROS_Mask_rcnn/src/mask_rcnn_ros/src/mask_rcnn_ros/model.py", line 2333, in detect
molded_images, image_metas, windows = self.mold_inputs(images)
File "/home/riwo-rack-pc/ROS_Mask_rcnn/src/mask_rcnn_ros/src/mask_rcnn_ros/model.py", line 2236, in mold_inputs
padding=self.config.IMAGE_PADDING)
File "/home/riwo-rack-pc/ROS_Mask_rcnn/src/mask_rcnn_ros/src/mask_rcnn_ros/utils.py", line 409, in resize_image
image, (round(h * scale), round(w * scale)))
File "/home/riwo-rack-pc/.local/lib/python2.7/site-packages/scipy/misc/pilutil.py", line 490, in imresize
imnew = im.resize(size, resample=func[interp])
File "/home/riwo-rack-pc/.local/lib/python2.7/site-packages/PIL/Image.py", line 1806, in resize
return self._new(self.im.resize(size, resample, box))
TypeError: integer argument expected, got float
我尽我所能跟踪了踪迹,但是找不到引入浮点的点。
答案 0 :(得分:0)
merged_image = cv2.merge((np_image, np_image, np_image))
应该给您您想要的东西。