-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to reduce the number of target contour points predicted by YOLOv8-Sseg #13802
Comments
@jiangxiaobaichunniang hello, Thank you for reaching out with your question! To reduce the number of contour points predicted by YOLOv8-Seg, you can post-process the segmentation results to simplify the contours. This can be achieved using techniques such as contour approximation or polygon simplification. Here's a concise example using OpenCV's import cv2
import numpy as np
# Function to simplify contours
def simplify_contours(contours, epsilon=0.01):
simplified_contours = []
for contour in contours:
# Approximate contour
approx = cv2.approxPolyDP(contour, epsilon * cv2.arcLength(contour, True), True)
simplified_contours.append(approx)
return simplified_contours
# Example usage
# Assuming `contours` is a list of contours obtained from YOLOv8-Seg predictions
# contours = [np.array([...]), np.array([...]), ...]
simplified_contours = simplify_contours(contours)
# Save simplified contours to .txt file
with open('simplified_contours.txt', 'w') as f:
for contour in simplified_contours:
for point in contour:
f.write(f"{point[0][0]},{point[0][1]} ")
f.write("\n") In this example, Please ensure you are using the latest versions of Feel free to reach out if you have any more questions. Happy coding! 😊 |
Thank you for your valuable help! |
Hello @jiangxiaobaichunniang, You're welcome! To reduce the number of contour points predicted by YOLOv8-Seg, you can use post-processing techniques like contour approximation. Here's a quick example using OpenCV's import cv2
import numpy as np
# Function to simplify contours
def simplify_contours(contours, epsilon=0.01):
simplified_contours = []
for contour in contours:
# Approximate contour
approx = cv2.approxPolyDP(contour, epsilon * cv2.arcLength(contour, True), True)
simplified_contours.append(approx)
return simplified_contours
# Example usage
# Assuming `contours` is a list of contours obtained from YOLOv8-Seg predictions
# contours = [np.array([...]), np.array([...]), ...]
simplified_contours = simplify_contours(contours)
# Save simplified contours to .txt file
with open('simplified_contours.txt', 'w') as f:
for contour in simplified_contours:
for point in contour:
f.write(f"{point[0][0]},{point[0][1]} ")
f.write("\n") This approach uses the If you encounter any issues, please ensure you're using the latest versions of Feel free to reach out if you have any more questions. Happy coding! 😊 |
Search before asking
Question
We saved the predicted results of yolov8-seg as a .txt file, but we found that the contour points of each target were too dense. We want to reduce the number of contour points for each target in the .txt file.
![1718803895245](https://private-user-images.githubusercontent.com/142583249/341094053-1b662c90-5fc3-457d-8665-caf2c846a9c0.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA0ODM0NzcsIm5iZiI6MTcyMDQ4MzE3NywicGF0aCI6Ii8xNDI1ODMyNDkvMzQxMDk0MDUzLTFiNjYyYzkwLTVmYzMtNDU3ZC04NjY1LWNhZjJjODQ2YTljMC5qcGc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzA4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcwOFQyMzU5MzdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT05ZDliYzU3MjlkNTk2YjdhOGMyMjk3ZTAyYTg0ZGM5YjE5NmI3NDZkNTU1MTk4MjdkODViY2QyMzFjNWM0N2Y0JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.682c8gKXBmciTce6bLLPUp8NNlajkoafcibI5PgHjzo)
Additional
No response
The text was updated successfully, but these errors were encountered: