简体   繁体   English

使用像素坐标 (OpenCV) 在图像上绘制多个标记

[英]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.

相关问题 使用 python 在图像上绘制可移动的垂直线并获取 opencv 坐标 - Draw moveable vertical lines on an image using python and get opencv coordinates 如何使用 Python OpenCV 中的坐标在图像中绘制热图? - How to draw a Heatmap in a image using the coordinates in Python OpenCV? 使用 opencv 获取由椭圆包围的图像区域中的像素坐标和像素值 python - Getting pixel coordinates and pixel values in image region bounded by an ellipse using opencv python 如何使用 Opencv 定位矩形的像素坐标? - How to locate pixel coordinates of a rectangle using Opencv? 使用 OpenCV 坐标裁剪图像 - Crop an image using OpenCV Coordinates 提取的圆的像素坐标(使用 scikit 图像)偏离在图像上绘制的圆的实际位置(使用 openCV) - Pixel coordinates of the circle extracted (using scikit image) shifts from the actual position of the circle drawn over an image(using openCV) 使用 opencv、numpy 和 python 在图像中搜索像素 - Searching for a pixel in an image using opencv, numpy and python 使用 OpenCV 从图像中查找房间的坐标 - Find coordinates of a room from an image using OpenCV OpenCV使用固定的相机位置将2D像素坐标映射到3D世界坐标 - Opencv map 2D pixel coordinates to 3D world coordinates using fixed camera position 如何使用 OpenCV 将 PyBullet 模拟坐标投影到渲染的帧像素坐标? - How to project PyBullet simulation coordinates to rendered Frame pixel coordinates using OpenCV?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM