36

What causes the SystemError in this line of code cv2.line(output, point1, point2, (0,0,255), 5)?

3

7 Answers 7

25

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)
1
  • 3
    Facing the same issue and tried your solution but no luck. Jun 5, 2019 at 19:36
12

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]

3

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.

0

Try this...

point1=(x1,x2)
point2=(y1,y2)
new_img=cv2.line(img,point1,point2,(0,0,255),3)
1
  • 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
0

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)
0

just write this following way v2.line(output, tuple(point1), tuple(point2), (0,0,255), 5)?

1
  • 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.
    – Yunnosch
    May 8, 2022 at 14:07
0

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) 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy