Skip to content

Contours for cv2 dont working #514

Description

@Sasa578639

contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

        for cnt in contours:

            shape = get_shape(cnt)

            # Draw on frame
            draw_color = COLOR_MAP.get(name, (0, 255, 0))
            M = cv2.moments(cnt)
            if M["m00"] > 0:
                cx = int(M["m10"] / M["m00"])
                cy = int(M["m01"] / M["m00"])
                cv2.drawContours(frame, [cnt], -1, draw_color, 2)
                cv2.circle(frame, (cx, cy), 5, draw_color, -1)
                cv2.putText(frame, f"{name} {shape}", (cx - 40, cy - 20),
                            cv2.FONT_HERSHEY_SIMPLEX, 0.5, draw_color, 2)

sys.stdout.write('\r' + ' ' * 80 + '\r')
sys.stdout.flush()

debug_pub.publish(bridge.cv2_to_imgmsg(frame, 'bgr8'))

def main():
rospy.init_node(NODE_NAME)

global detection_pub, debug_pub
detection_pub = rospy.Publisher(RESULT_TOPIC, String, queue_size=1)
debug_pub = rospy.Publisher(DEBUG_TOPIC, Image, queue_size=1)

# Subscribe with large buffer for performance
rospy.Subscriber(CAMERA_TOPIC, Image, image_callback, queue_size=1, buff_size=2**24)

rospy.loginfo(f"{NODE_NAME} started. Listening on {CAMERA_TOPIC}")
rospy.spin()

if name == 'main':
main()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions