Reputation: 111
I have a very large image on which I need to draw around 130 markers. The points for these markers are in a numpy array. I need to use the array with cv2.drawMarker
Sorry if this is trivial but I am just learning python. These markers are based on GPS coordinates and I have managed to convert the coordinates into pixel points. The points are stored in arr (provided a snippet below). The image size is 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)
Upvotes: 5
Views: 11425
Reputation: 246
You are attempting to pass 135 elements into the cv2.drawMarker function all at once, this is the source of the error.
You need to loop through each element in the array and call the drawMarker function for each element in 'arr'.
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)
Upvotes: 5