Issue
I have a numpy array that consist n (x and y) coordinate (i declared this nparray as 'line') from an image(newimg). lets take 5 coordinates as the example
[[ 33 101]
[170 95]
[151 190]
[125 223]
[115 207]]
an then i want to make a sequential line between that coordinates (point 1 to point 2, point 2 to point 3, ...., point n-1 to point n and the point n to point 1)
I trying to make the algorithm with cv2.line like this
for a in range(5) :
cv2.line(newimg, line[a:], line[a+1:], (255,255,255), 1)
cv2.line(newimg, line, line[1], (255,255,255), 1)
and it produce SystemError: new style getargs format but argument is not a tuple
any idea?
Solution
Problems:
There are some changes that need to be addressed:
- To access a single value in an array use
line[i]
.line[i:]
returns an array of points staring from indexi
till the end. cv2.line()
accepts tuples as start and end points.
Code:
# proposed line as an array
line = np.array([[ 33, 101], [170, 95], [151, 190], [125, 223], [115, 207]])
# blank image
newimg = np.zeros((300, 300, 3), np.uint8)
# iterate every point and connect a line between it and the next point
for a in range(len(line) - 1):
newimg = cv2.line(newimg, tuple(line[a]), tuple(line[a+1]), (255,255,255), 2)
newimg = cv2.line(newimg, tuple(line[0]), tuple(line[-1]), (255,255,255), 2)
Output:
EDIT
Updated the code to connect a line between the first and last points in line
Answered By - Jeru Luke
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.