简体   繁体   English

使用GRAYSCALE图像创建BGR图像

[英]Creating BGR image using GRAYSCALE image

Camera provides GRAYSCALE data while deep learning model requires BGR. Camera提供GRAYSCALE数据,而深度学习模型需要BGR。 Is it possible to create artificial bgr image by "stacking" the grayscale image using opencv or numpy or anything? 是否可以通过使用opencv或numpy或任何东西“堆叠”灰度图像来创建人工bgr图像?

I am using two ROS packages created by other people. 我正在使用其他人创建的两个ROS包。 I have tried the following: 我尝试过以下方法:

Attempted altering the model to accept grayscale as described by the original repo. 试图改变模型以接受原始回购所描述的灰度。

Attempted to convert grayscale to bgr using 尝试使用灰度转换为bgr

np_image = cv2.cvtColor(np_image, cv2.COLOR_GRAY2BGR)

Attempted to create an array consisting of the image times three 尝试创建一个由图像时间三组成的数组

np_image = np.array([np_image, np_image, np_image])

The following code retrieves the 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()

I expect the model to retrieve the data, evaluate it and return an object id and mask. 我希望模型检索数据,评估它并返回一个对象id和掩码。 However, I get the following error: 但是,我收到以下错误:

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

I followed the trace as best I could but can't find the point where the float is introduced. 我尽可能地跟踪了痕迹,但是找不到引入浮点的点。

merged_image = cv2.merge((np_image, np_image, np_image))

应该给你你想要的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM