X,Y and RGB data

asked 2019-10-08 10:32:21 -0600

GZ gravatar image

updated 2019-10-09 01:55:27 -0600

LBerger gravatar image

Hey, I got two cameras but somehow only one show a bar in the bottom with information of X,Y position of the mouse cursor along with the pixel RGB values. what do you think might be the reason?

class image_converter:

    def __init__(self):
        '''Initialize ros publisher, ros subscriber'''
        # topic where we publish
        self.image_pub = rospy.Publisher("/kodak/image_raw2", Image)
        self.bridge = CvBridge()

        # subscribed Topic
        self.subscriber = rospy.Subscriber(
            "/kodak/image_raw", Image, self.callback)

    def callback(self, data):
        try:
            cv_image = self.bridge.imgmsg_to_cv2(
                data, desired_encoding="passthrough")
        except CvBridgeError as e:
            print(e)

        (rows, cols, channels) = cv_image.shape
        # if cols > 60 and rows > 60 :
        #cv2.circle(cv_image, (50,50), 10, 255)
        np_image = np.array(cv_image, dtype=np.uint8)
edit retag flag offensive close merge delete

Comments

Show us your code as text please

LBerger gravatar imageLBerger ( 2019-10-08 15:28:17 -0600 )edit

class image_converter:

def __init__(self):
    '''Initialize ros publisher, ros subscriber'''
    # topic where we publish
    self.image_pub = rospy.Publisher("/kodak/image_raw2", Image)
    self.bridge = CvBridge()

    # subscribed Topic
    self.subscriber = rospy.Subscriber(
        "/kodak/image_raw", Image, self.callback)

def callback(self, data):
    try:
        cv_image = self.bridge.imgmsg_to_cv2(
            data, desired_encoding="passthrough")
    except CvBridgeError as e:
        print(e)

    (rows, cols, channels) = cv_image.shape
    # if cols > 60 and rows > 60 :
    #cv2.circle(cv_image, (50,50), 10, 255)
    np_image = np.array(cv_image, dtype=np.uint8)
GZ gravatar imageGZ ( 2019-10-08 16:55:24 -0600 )edit

Code:

#crop_img = np_image[608:1195, 266:1137].
cv2.namedWindow("Image", cv2.WINDOW_NORMAL)
cv2.resizeWindow("Image", 800, 1000)
#cv2.imshow("Image", crop_img)
cv2.imshow("Image", np_image)
cv2.setMouseCallback("Image",onMouse)
cv2.waitKey(3)
try:
    self.image_pub.publish(self.bridge.cv2_to_imgmsg(np_image, "bgr8"))
except CvBridgeError as e:
    print(e)
GZ gravatar imageGZ ( 2019-10-08 17:05:46 -0600 )edit

I added 2 parts of my code. Thanks

GZ gravatar imageGZ ( 2019-10-08 17:11:28 -0600 )edit

I format your code as above, becasue of idendation. Is that correct?

supra56 gravatar imagesupra56 ( 2019-10-08 21:19:47 -0600 )edit

@GZ remove comment and you can edit your post and add code. If you want to track event in two windows you must use two cv2.setMouseCallback, one with "image1" and one with "image2"

LBerger gravatar imageLBerger ( 2019-10-09 01:59:50 -0600 )edit

This is a simplified code.

class image_converter:
    def __init__(self):

        self.image_pub = rospy.Publisher("/kodak/image_raw2", Image)
        self.bridge = CvBridge()
        self.subscriber = rospy.Subscriber(
            "/kodak/image_raw", Image, self.callback)
    def callback(self, data):
        try:
            cv_image = self.bridge.imgmsg_to_cv2(
                data, desired_encoding="passthrough")
        except CvBridgeError as e:
            print(e)
        (rows, cols, channels) = cv_image.shape
        cv2.namedWindow("Image", cv2.WINDOW_NORMAL)
        cv2.imshow("Image", cv_image)
        cv2.waitKey(3)
        try:
            self.image_pub.publish(self.bridge.cv2_to_imgmsg(np_image, "bgr8"))
        except CvBridgeError as e:
            print(e)
GZ gravatar imageGZ ( 2019-10-10 09:05:19 -0600 )edit

As you see in this picture (its not me LOL), in my case i dont have no information at the bottom of the window like he does. but in my other code the window opens up at the same time with my namedWindow.

https://2.bp.blogspot.com/-iTEorlb0d7...

GZ gravatar imageGZ ( 2019-10-10 09:17:51 -0600 )edit

Here it works

try:
        while True:
            frames = pipeline.wait_for_frames()
            depth_frame = frames.get_depth_frame()
            color_frame = frames.get_color_frame()
            if not depth_frame or not color_frame:
                continue
            depth_image = np.asanyarray(depth_frame.get_data())
            color_image = np.asanyarray(color_frame.get_data())
            depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)
            images = np.hstack((color_image, depth_colormap))
            cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)
            cv2.imshow('RealSense', images)
            cv2.waitKey()
    finally:
        pipeline.stop()
GZ gravatar imageGZ ( 2019-10-10 09:24:29 -0600 )edit