ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Ros-opencv after few computations cannot see the image

asked 2016-07-22 08:09:36 -0500

Hi ,

So i'm trying to detect lines with turtlebot via kinect rgb camera. Everything was working until i added cv2.HoughLinesP() i think it still works but image window comes up as menubar only :) canny and gaussianblur works fine with a bit latency but at least i can see the image

i tried to add rospy.sleep() . im not sure where to go from this point. any suggestions?

thanks

def __init__(self):
    rospy.init_node('test_node')
    self.bridge=CvBridge()

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

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

    cv_image=(255-cv_image)

    g_img=cv2.cvtColor(cv_image,cv2.COLOR_BGR2GRAY)
    g_img=cv2.GaussianBlur(g_img,(5,5),200)
    thresh=cv2.Canny(g_img,5,150,5)
    lines = cv2.HoughLinesP(thresh,2,np.pi/180,100,100,1)
    print lines.shape
    for i in range(0,lines.shape[0]):
        for x1,y1,x2,y2 in lines[i]:
            cv2.line(cv_image,(x1,y1),(x2,y2),(0,255,0),2)

    cv2.imshow("image",lines)
    cv2.waitKey(3)
    #rospy.sleep(10)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-07-22 15:40:27 -0500

Chrissi gravatar image

updated 2016-07-22 15:43:47 -0500

Your lines is a numpy array of x,y coordinates for the lines the hough transform found and not an image. You cannot visualise that using

cv2.imshow("image",lines)

try

cv2.imshow("image",cv_image)

which is what you draw the lines on anyway with

cv2.line(cv_image,(x1,y1),(x2,y2),(0,255,0),2)

EDIT:

Also if you want real-time, you want to add a queue_size=1 to your subscriber to prevent the lag and get real-time results. Otherwise the image you produce will always be lagging behind the input image.

self.image_sub = rospy.Subscriber("/camera/rgb/image_color", Image, self.callback, queue_size=1)
edit flag offensive delete link more

Comments

thank you , i'll try that and update tomorrow

orhan gravatar image orhan  ( 2016-07-22 15:45:23 -0500 )edit

it works thanks alot

orhan gravatar image orhan  ( 2016-07-23 05:15:01 -0500 )edit

You're welcome.

Chrissi gravatar image Chrissi  ( 2016-07-23 05:32:32 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-07-22 08:09:36 -0500

Seen: 338 times

Last updated: Jul 22 '16