How best to deal with XCB errors and use OpenCV

  1. Where did you get the camera module(s)?
    Amazon
  2. Model number of the product(s)?
    IMX519
  3. What hardware/platform were you working on?
    Raspberry Pi 3B+

My camera works with picamera2 and I can even get autofocus working within a simple python application now. This is great, as it took 3 months to get here :wink:

Now, my whole purpose for having the camera is to try and detect objects. To do this I am trying to use opencv. Anytime I try running any command though I get the same error.

For example: If I run

import cv2
import numpy as np

cap = cv2.VideoCapture(0)
cv2.namedWindow("Trackbars")

I get

qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in "/usr/local/lib/python3.9/dist-packages/cv2/qt/plugins"
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Aborted

How do I avoid this error?