ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A
Ask Your Question

Problem viewing images using python-opencv

asked 2017-02-08 10:02:32 -0500

pnambiar gravatar image

I have trouble viewing color images from R200 realsense camera using the python-opencv interface. The window is blank when I run this script. When I comment out'cv2.namedWindow("Image window", 1)', it shows the first image.


import roslib import sys import rospy import cv2 from std_msgs.msg import String from geometry_msgs.msg import Twist from sensor_msgs.msg import Image from rospy.numpy_msg import numpy_msg #from rospy_tutorials.msg import Floats from cv_bridge import CvBridge, CvBridgeError import numpy as np import math; import cv2; #import matplotlib.pyplot as plt; import sys; #import caffe; import socket; #from sklearn import datasets; import subprocess;

import message_filters from rospy.numpy_msg import numpy_msg import time #####################

import os.path

class image_converter:

Initializing variables, publishers and subscribers

def __init__(self): print 'show window' cv2.namedWindow("Image window", 1)

print 'start bridge and subscribe'

self.bridge = CvBridge()

self.image_sub = rospy.Subscriber("/camera/rgb/image_color", Image, self.callback)

# The main callback that processes the color and depth data.
def callback(self,color):

start = time.time()
# acquiring color and depth data (from ROS-python tutorial)

  frame = self.bridge.imgmsg_to_cv2(color, "bgr8")
except CvBridgeError, e:
  print e

frame = np.array(frame, dtype=np.uint8)

cv2.imshow("Image window", frame)
print 'test'

def main(args): ic = image_converter() rospy.init_node('image_converter', anonymous=True) try: rospy.spin() except KeyboardInterrupt: print "Shutting down" cv2.destroyAllWindows()

if __name__ == '__main__': main(sys.argv)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-04-02 00:34:30 -0500

vibhor gravatar image

Remove self.bridge = CvBridge() statement from __init__(self) and move it to callback() function. On each callback, you need to reinitialize CvBridge object

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

The deadline to submit a proposal to present at ROSCon 2017 is June 25, 2017. Submit yours now!

Question Tools

1 follower


Asked: 2017-02-08 10:02:32 -0500

Seen: 72 times

Last updated: Feb 08