Ask Your Question
0

Segmentation Fault (core dump)

asked 2014-06-12 08:26:27 -0500

jashanvir gravatar image

I am working on ROS and Opencv. I am able to run the code but after some times the code stops and show the error Segmentation Fault (Core Dumped). The following is the code in which a quadrotor is finding the color box which I will modify by giving the values of RGB through trackbars. I have added some of the debugging statements to find out the line of error. and I think the line of error is hsv=cv2.cvtColor(cv_image,cv2.COLOR_BGR2HSV) The following is the whole code

#!/usr/bin/env python
import roslib
import sys
import time
import math
import rospy
import cv2
import cv2.cv as cv
import numpy as np
from geometry_msgs.msg import PoseStamped
from geometry_msgs.msg import Vector3
from geometry_msgs.msg import Twist
from geometry_msgs.msg import Wrench
from geometry_msgs.msg import Pose
from geometry_msgs.msg import Point
from sensor_msgs.msg import NavSatFix
from sensor_msgs.msg import CameraInfo
from sensor_msgs.msg import Image
from sensor_msgs.msg import RegionOfInterest
from cv_bridge import CvBridge, CvBridgeError
from rospy.numpy_msg import numpy_msg

H_MIN = 0
H_MAX = 255
V_MIN = 0
V_MAX = 255
S_MIN = 0
S_MAX = 255

class test_vision_node_fly:
    def __init__(self):
        print('a')
        self.image_pub = rospy.Publisher("quadrotor/videocamera1/camera_info",Image)
        print('b')
        self.ROI = rospy.Publisher("roi", RegionOfInterest)
        print('c')  
        rospy.sleep(1)
        print('d')
        self.cv_window_name = "Image window"
        print('e')
            cv.NamedWindow(self.cv_window_name, 0)
        print('f')
            cv.NamedWindow("trackbars" , 0) 
        print('g')      
            self.bridge = CvBridge()
        print('h')
            self.image_sub = rospy.Subscriber("quadrotor/videocamera1/image",Image,self.callback)
        print('i')
        rospy.loginfo("Waiting for image topics...")
        print('j')
    def on_trackbar(self,x):
            global H_MAX
            global H_MIN
            global S_MAX
            global S_MIN
            global V_MAX
            global V_MIN
            print('k')
        H_MIN = cv2.getTrackbarPos('H_MIN', 'trackbars')
            H_MAX = cv2.getTrackbarPos('H_MAX', 'trackbars')  
            S_MAX = cv2.getTrackbarPos('S_MAX', 'trackbars')
            S_MIN = cv2.getTrackbarPos('S_MIN', 'trackbars')
            V_MIN = cv2.getTrackbarPos('V_MIN', 'trackbars')
            V_MAX = cv2.getTrackbarPos('V_MAX', 'trackbars')
        print('l')     
            pass   
    def callback(self,data):

        """ Convert the raw image to OpenCV format using the convert_image() helper function """
            cv_image = self.convert_image(data)
        print('m')
        # Convert the image to a Numpy array since most cv2 functions
            # require Numpy arrays.
            cv_image = np.array(cv_image, dtype=np.uint8)
        print('n')
            """ Apply the CamShift algorithm using the do_camshift() helper function """
            cv_image = self.do_camshift(cv_image)
        print('o')
            """ Refresh the displayed image """
            cv.ShowImage(self.cv_window_name, cv_image)
        print('p')
    def convert_image(self, ros_image):  
        try:
                cv_image = self.bridge.imgmsg_to_cv(ros_image, "bgr8")
            print('q')
            return cv_image
            except CvBridgeError, e:
                print e
    def do_camshift(self, cv_image):            
            ''' converting bgr to hsv ''' 
        print('r')         
            hsv=cv2.cvtColor(cv_image,cv2.COLOR_BGR2HSV) 
        print('s')    
        '''creating trackbars'''
        cv2.createTrackbar('H_MIN', 'trackbars', H_MIN, H_MAX, self.on_trackbar) 
        cv2.createTrackbar('H_MAX', 'trackbars', H_MAX, H_MAX, self.on_trackbar)
            cv2.createTrackbar('S_MIN', 'trackbars', S_MIN, S_MAX, self.on_trackbar) 
        cv2.createTrackbar('S_MAX', 'trackbars', S_MAX, S_MAX, self.on_trackbar)    
        cv2.createTrackbar('V_MIN', 'trackbars', V_MIN, V_MAX, self.on_trackbar)    
            cv2.createTrackbar('V_MAX', 'trackbars', V_MAX, V_MAX, self.on_trackbar)
        print('t')                                      
            ''' threshdolding '''
        COLOR_MIN = np.array([H_MIN, S_MIN, V_MIN],dtype=np.uint8)
        print('u')
            COLOR_MAX = np.array([H_MAX, S_MAX, V_MAX],dtype=np.uint8)
        print('v')
            mask=cv2.inRange(hsv ...
(more)
edit retag flag offensive close merge delete

Comments

use bridge.imgmsg_to_cv2 and drop cv. support is a first advice What is the error message ? Please also print the shape of the numpy array.

Vincent Rabaud gravatar imageVincent Rabaud ( 2014-06-12 09:30:29 -0500 )edit

The following is the error:- o OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /tmp/buildd/ros-hydro-opencv2-2.4.6-3precise-20140303-2244/modules/highgui/src/window.cpp, line 261 [ERROR] [WallTime: 1402584675.408560] bad callback: <bound method="" test_vision_node_fly.callback="" of="" <__main__.test_vision_node_fly="" instance="" at="" 0x3431170="">> Traceback (most recent call last): File "/opt/ros/hydro/lib/python2.7/dist-packages/rospy/topics.py", line 682, in _invoke_callback cb(msg) File "/home/user/catkin_ws/src/my_package/scripts/pilot.py", line 81, in callback cv2.imshow(self.cv_window_name, cv_image) error: /tmp/buildd/ros-hydro-opencv2-2.4.6-3precise-20140303-2244/modules/highgui/src/window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow m (256, 256, 3) and when i print the numpy arraY I GOT

jashanvir gravatar imagejashanvir ( 2014-06-12 09:53:23 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-06-15 04:04:18 -0500

Vincent Rabaud gravatar image

You are displaying an empty image. Just add a test: if it is empty, do not display it.

edit flag offensive delete link more

Comments

Where ? can u help me find that command ?

jashanvir gravatar imagejashanvir ( 2014-06-16 04:28:21 -0500 )edit

you have 3 imshow, it's one of those.

Vincent Rabaud gravatar imageVincent Rabaud ( 2014-06-16 07:27:17 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-06-12 08:26:27 -0500

Seen: 2,779 times

Last updated: Jun 15 '14