opencv - ROS 错误 : segmentation fault (core Dumped)

标签 opencv ros fault

我一直在开发一个带有 ROS 的人脸检测应用程序,可以在无人机上运行。
人脸检测代码是可以在谷歌上找到的代码并且工作正常,但是当我将它与 ROS 混合时,我一直在努力解决一个错误:段错误(核心转储) .我试图找到错误,比如使用错误类型的变量,但没有成功。
这是代码:

    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()

每次我的脸转向 window 的左侧或右侧时,程序都会崩溃。我标记了它崩溃的地方。终端中没有出现 ERRO MSG。

希望你能帮助我,这次能说清楚!谢谢!

谢谢!

最佳答案

我终于让它工作了,我所做的是:

  • 在函数内部实例化发布者和 init_node
    主叫
  • 现在我的main函数只是调用识别人脸的函数
  • 删除 rospy.spin()
  • 创建一个新的 .py 以用于发布,即
    崩溃被用于将值发送到新的
    无人机必须走。
  • 关于opencv - ROS 错误 : segmentation fault (core Dumped),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49653711/

    相关文章:

    c++ - 拉普拉斯金字塔重建

    python - 重定向从 Python 调用的 launchfile 的输出

    c - 段错误 Mac - C 代码

    C 编程中的核心转储

    c++ - 在GNU编译器中发现错误。更高版本?

    python - 无法在 Python (Windows) 中使用 OpenCV 更改网络摄像头分辨率

    opencv - opencv中的颜色检测

    python - 将图像分割成任意数量的框

    ros - 如果尚未运行,则启动节点

    c++ - 使用 Boost 线程监控对象队列