0

I am trying trying to display webcam footage using openCV on Ubuntu but i am getting the following error:

Error: BadDrawable (invalid Pixmap or Window parameter) 9Major opcode: 62 (X_CopyArea)Resource id: 0x3800056]

Here is my full code

import cv2

cap = cv2.VideoCapture(1)
cap.set(3,320)
cap.set(4,240)
while(1):
    _, frame = cap.read()
    cv2.imshow('frame',frame)

    k = cv2.waitKey(5) & 0xFF
    if k == 27:
        break

cap.release()

cv2.destroyAllWindows()

I have tried googling the error and it seems to be GUI related. I have also read the docs on imshow and I seem to be calling it fine, can anyone figure out why I am getting this error.

Thanks

6
  • Is frame non null and does it actually contain an image? Commented Aug 8, 2018 at 12:46
  • i can run this on raspbian and it works fine. and the camera light turns on so I am assuming it is not null, how would I check? Commented Aug 8, 2018 at 12:48
  • Try debugging it. Do you have 2 cameras? If I remember correctly the default camera is on number 0, therefor you might need cv2.VideoCapture(0). Commented Aug 8, 2018 at 12:52
  • I have tried 2 different cameras at different points in the hardware array. 0, 1 and the webcam works though other applications (i.e Cheese) Commented Aug 8, 2018 at 12:56
  • What if you try the example from the documentations? docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/… Commented Aug 8, 2018 at 13:13

1 Answer 1

1

Seems like a problem when Python tries to present the window. It's probably an OS issue. Try editing the /etc/environment.

sudo nano /etc/environment

Add this line:

QT_X11_NO_MITSHM=1

Also try running your app as sudo and checking this for any solutions if before mentioned doesn't help.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you!! this fixed the issue.
Glad to help :) Please accept the answer if it solved your issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.