[英]Draw multiple markers on an image using pixel coordinates (OpenCV)
I have a very large image on which I need to draw around 130 markers.我有一个非常大的图像,我需要在上面绘制大约 130 个标记。 The points for these markers are in a numpy array.这些标记的点位于一个 numpy 数组中。 I need to use the array with cv2.drawMarker我需要将数组与 cv2.drawMarker 一起使用
Sorry if this is trivial but I am just learning python.对不起,如果这是微不足道的,但我只是在学习 python。 These markers are based on GPS coordinates and I have managed to convert the coordinates into pixel points.这些标记基于 GPS 坐标,我已经设法将坐标转换为像素点。 The points are stored in arr (provided a snippet below).这些点存储在 arr (下面提供了一个片段)。 The image size is 25000*18568.图像大小为 25000*18568。
# This file contains the marker locations (pix_lat, pix_long)
df=pd.read_csv(r'.csv', sep=',',header=0)
# Image that needs to be drawn on
img = cv2.imread(r'.jpg',1)
df1 = df[['pix_lat','pix_long']]
arr = df1.to_numpy()
cv2.drawMarker(img, tuple(arr),(0,0,255), markerType=cv2.MARKER_STAR,
markerSize=40, thickness=2, line_type=cv2.LINE_AA)
cv2.imwrite('.jpg',img)
In: arr
Out: array([[14590, 3716],
[16637, 4148],
[11074, 6578],
[17216, 4009],
The current code gives an error for cv2.drawMarker: function takes exactly 2 arguments (135 given)当前代码给出了 cv2.drawMarker 的错误:函数需要 2 个参数(给出 135 个)
You are attempting to pass 135 elements into the cv2.drawMarker function all at once, this is the source of the error.您试图一次将 135 个元素传递到 cv2.drawMarker 函数中,这是错误的根源。
You need to loop through each element in the array and call the drawMarker function for each element in 'arr'.您需要遍历数组中的每个元素并为“arr”中的每个元素调用 drawMarker 函数。
Please see below请看下面
# This file contains the marker locations (pix_lat, pix_long)
df=pd.read_csv(r'.csv', sep=',',header=0)
# Image that needs to be drawn on
img = cv2.imread(r'.jpg',1)
df1 = df[['pix_lat','pix_long']]
arr = df1.to_numpy()
#loop through each coordinate pair in arr
for item in arr:
cv2.drawMarker(img, (item[0], item[1]),(0,0,255), markerType=cv2.MARKER_STAR,
markerSize=40, thickness=2, line_type=cv2.LINE_AA)
cv2.imwrite('.jpg',img)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.