THE FOLLOW CODE IS GIVIN THIS ERROR PLEASE SEND A FIX IF YOU CAN '''' File…
- User
THE FOLLOW CODE IS GIVIN THIS ERROR PLEASE SEND A FIX IF YOU CAN
'''' File "triangulate.py", line 18, in subdiv.insert((x, y)) cv2.error: OpenCV(4.9.0) /io/opencv/modules/imgproc/src/subdivision2d.cpp:285: error: (-2:Unspecified error) Subdivision is empty in function 'locate'
'''
import numpy as np import cv2
Generate 69 random 2D points
np.random.seed(42) # Set seed for reproducibility num_points = 69 coordinates2D = np.random.rand(num_points, 2) # Random 2D points
Perform Delaunay triangulation using OpenCV
subdiv = cv2.Subdiv2D() unique_points = np.unique(coordinates2D, axis=0) # Remove duplicate points
print("Unique Points:") for idx, point in enumerate(unique_points): print(f'Index: {idx}, Coordinates: {point}')
for x, y in unique_points: subdiv.insert((x, y)) triangle_list = subdiv.getTriangleList()
triangles = [] for t in triangle_list: pt1 = (t[0], t[1]) pt2 = (t[2], t[3]) pt3 = (t[4], t[5])
codeindex1 = np.where((unique_points == pt1).all(axis=1))[0][0] index2 = np.where((unique_points == pt2).all(axis=1))[0][0] index3 = np.where((unique_points == pt3).all(axis=1))[0][0] triangles.append([index1, index2, index3])print("\nTriangles:") for idx, face in enumerate(triangles): print(f'Triangle {idx}: {face}')
- Assistant
- Assistant
It looks like your message is empty. If you meant to ask a question or have any other inquiries or follow-up requests based on the last response, please go ahead and provide the details, and I'll be happy to assist you!