What causes the SystemError in this line of code
cv2.line(output, point1, point2, (0,0,255), 5)
?
7 Answers
Faced with the same problem and solved it by using tuples instead of lists:
# How it looked before:
point1, point2 = [x1, y1], [x2, y2]
# How it should be:
point1, point2 = (x1, y1), (x2, y2)
-
3
Python OpenCV drawing functions take points as tuples. Possibly your point1
and point2
are of some other type, eg. a list
maybe. So try this
cv2.line(output, tuple(point1), tuple(point2), (0,0,255),5)
The error is raised, because the OpenCV Python extensions call the function PyArg_ParseTuple()
with something that is not a tuple. [see here]
It seems the lastest version opencv-python have fixed this issue, I upgrade opencv-python from 4.4.0.44 to 4.5.5.64 by pip install --upgrade opencv-python
, then this error disappear.
Try this...
point1=(x1,x2)
point2=(y1,y2)
new_img=cv2.line(img,point1,point2,(0,0,255),3)
-
Welcome to Stack Overflow! While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply. Jun 30, 2019 at 4:41
The passing arguments aren't matching with the desirable arguments. I have faced same problem for:
x = cv2.resize(img, (32*32)).flatten()
x.resize(3032, 1)
And, solve it by correcting 32*32 to 32, 32.
x = cv2.resize(img, (32,32)).flatten()
x.resize(3032, 1)
just write this following way v2.line(output, tuple(point1), tuple(point2), (0,0,255), 5)?
-
While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.– YunnoschMay 8, 2022 at 14:07
since it didn't work in colab :(with same error )
cv2.drawChessboardCorners(imgBoard, board_size, found_corners, True) plt.imshow("imgBoard", imgBoard)
*i switched to my own small function:*
def showImageWithCorners(img,cornerToShow):
plt.plot(cornerToShow[:,0], cornerToShow[:,1], marker='o', color="red")
plt.imshow(img)
point1
andpoint2
tuples?