简体   繁体   English

ROS错误:分段错误(核心已转储)

[英]ROS ERROR: segmentation fault (core Dumped)

I've been developing a face detection app with ROS to run on a Drone. 我一直在使用ROS开发可在无人机上运行的人脸检测应用程序。 The face detection code is the code that can be find on google and works fine but when I mixed it with ROS, I've been struggling with an error: segmentation fault (core dumped) . 人脸检测代码是可以在google上找到并且可以正常工作的代码,但是当我将其与ROS混合时,我一直在遇到一个错误: 分段错误(核心已转储) I've tried to find error like using the wrong type of variables but unsuccessfully. 我试图找到错误,例如使用错误类型的变量,但未成功。 Here is the code: 这是代码:

    while not rospy.is_shutdown():
        # Capture frame-by-frame
        ret, frame = video_capture.read()
        frame = imutils.resize(frame, width=600)

        #convert the frame (of the webcam) to gray)
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        mask = cv2.erode(gray, None, iterations=2)
        mask = cv2.dilate(mask, None, iterations=2)

        # detecting the faces
        faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30), flags=cv2.CASCADE_SCALE_IMAGE)

        # Draw a rectangle around the faces
        for (x, y, w, h) in faces:
            cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
            x_imagem = x + (w/2)
            y_imagem = y + (h/2)

            cv2.circle(frame, (x+(w/2), y+(h/2)), 5, (0,0,255), -1)
            #600 x 450;

            cmd_vel_msg = Twist()
            if(x_imagem > 200 and x_imagem < 400):
                rospy.loginfo("CENTER")

            elif(x_imagem < 200):  #WHERE IT CRASH
                rospy.loginfo("LEFT")
                cmd_vel_msg.linear.x = 0.0
                cmd_vel_msg.linear.y = -0.3
                cmd_vel_msg.linear.z = 0.0
                pub_cmd_vel.publish(cmd_vel_msg)

            elif(x_imagem > 400): #WHERE IT CRASH
                rospy.loginfo("RIGHT")
                cmd_vel_msg.linear.x = 0.0
                cmd_vel_msg.linear.y = 0.3
                cmd_vel_msg.linear.z = 0.0
                pub_cmd_vel.publish(cmd_vel_msg)

         # Display the resulting frame

        cv2.imshow('Video', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

# When everything is done, release the capture
    video_capture.release()
    cv2.destroyAllWindows()

The program is crashing everytime my face goes to the left or right of the windows. 每当我的脸靠近窗户的左侧或右侧时,程序都会崩溃。 I marked where it's crashing. 我标记了它崩溃的位置。 No ERRO MSG are appearing in the terminal. 终端中未出现ERRO MSG。

Hope you can help me and could make it clear this time! 希望您能对我有所帮助,这次可以说清楚! Thanks! 谢谢!

Thanks! 谢谢!

I finally make it works, what I did was: 我终于使它起作用,我所做的是:

  1. Instantiate the publisher and init_node inside the function that was called by the main 在main调用的函数内实例化发布者和init_node
  2. Now my function main just call the function that recognize the face 现在我的函数主要只是调用识别人脸的函数
  3. Delete rospy.spin() 删除rospy.spin()
  4. Create a new .py to work with the publishing, the one that was crashing is being used to just sent to the new one the value where the drone must go. 创建一个新的.py来与发布一起工作,崩溃的那个被用来将无人机必须到达的值发送给新的。

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

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