I've been trying to use my ArduCam Camera module 3 for Raspberry Pi and I'm using a Raspberry Pi 4/B (bookworm 64-bit). I keep getting this message in the terminal of VScode:
QObject::moveToThread: Current thread (0x7f6c02f960) is not the object's thread (0x7f6c1753c0).
Cannot move to target thread (0x7f6c02f960)
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/cbarreto/env/lib/python3.11/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: xcb, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx.
Aborted
while running this code:
#PiCam
import cv2
import numpy as np
import time
from picamera2 import Picamera2, Preview
ARUCO_DICT = {
"DICT_4X4_50" : cv2.aruco.DICT_4X4_50,
"DICT_4X4_100" : cv2.aruco.DICT_4X4_100,
"DICT_4X4_250" : cv2.aruco.DICT_4X4_250,
"DICT_4X4_1000" : cv2.aruco.DICT_4X4_1000,
"DICT_5X5_50" : cv2.aruco.DICT_5X5_50,
"DICT_5X5_100" : cv2.aruco.DICT_5X5_100,
"DICT_5X5_250" : cv2.aruco.DICT_5X5_250,
"DICT_5X5_1000" : cv2.aruco.DICT_5X5_1000,
"DICT_6X6_50" : cv2.aruco.DICT_6X6_50,
"DICT_6X6_100" : cv2.aruco.DICT_6X6_100,
"DICT_6X6_250" : cv2.aruco.DICT_6X6_250,
"DICT_6X6_1000" : cv2.aruco.DICT_6X6_1000,
"DICT_7X7_50" : cv2.aruco.DICT_7X7_50,
"DICT_7X7_100" : cv2.aruco.DICT_7X7_100,
"DICT_7X7_250" : cv2.aruco.DICT_7X7_250,
"DICT_7X7_1000" : cv2.aruco.DICT_7X7_1000,
"DICT_ARUCO_ORIGINAL" : cv2.aruco.DICT_ARUCO_ORIGINAL,
"DICT_APRILTAG_16h5" : cv2.aruco.DICT_APRILTAG_16H5,
"DICT_APRILTAG_25h9" : cv2.aruco.DICT_APRILTAG_25H9,
"DICT_APRILTAG_36h10" : cv2.aruco.DICT_APRILTAG_36H10,
"DICT_APRILTAG_36h11" : cv2.aruco.DICT_APRILTAG_36H11,
}
def aruco_display(corners, ids, rejected, image):
if len(corners) > 0:
ids = ids.flatten()
for (markerCorner, markerID) in zip(corners, ids):
corners = markerCorner.reshape((4,2))
(topLeft, topRight, bottomRight, bottomLeft) = corners
topRight = (int(topRight[0]), int(topRight[1]))
bottomRight = (int(bottomRight[0]), int(bottomRight[1]))
bottomLeft = (int(bottomLeft[0]), int(bottomLeft[1]))
topLeft = (int(topLeft[0]), int(topLeft[1]))
cv2.line(image, topLeft, topRight, (0, 255, 0), 2)
cv2.line(image, topRight, bottomRight, (0, 255, 0), 2)
cv2.line(image, bottomRight, bottomLeft, (0, 255, 0), 2)
cv2.line(image, bottomLeft, topLeft, (0, 255, 0), 2)
cX = int((topLeft[0] + bottomRight[0])/ 2.0)
cY = int((topLeft[1] + bottomRight[1])/ 2.0)
cv2.circle(image, (cX, cY), 4, (0, 0, 255), -1)
cv2.putText(image, str(markerID),(topLeft[0], topLeft[1] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
print("[Inference] Aruco marker ID: {}".format(markerID))
return image
arucoDict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_100)
arucoParams = cv2.aruco.DetectorParameters()
try:
# Initialize picamera2
picam2 = Picamera2()
picam2.start_preview(Preview.QTGL)
# Set the stream format
config = picam2.create_preview_configuration({"size": (640, 480)})
#preview = Preview(picam2, show_fps=True)
picam2.configure(config)
# Start capturing
np_array = picam2.capture_array()
raw_np_array = picam2.capture_array("raw")
time.sleep(0.1) # allow the camera to warmup
for frame in picam2.capture_continuous(np_array, format="bgr", use_video_port=True):
# Convert the raw buffer data to an image
img = frame.array
h, w, _ = img.shape
width = 1000
height = int(width*(h/w))
img = cv2.resize(img,(width, height), interpolation=cv2.INTER_CUBIC)
corners, ids, rejected = cv2.aruco.detectMarkers(img, arucoDict, parameters=arucoParams)
detected_markers = aruco_display(corners, ids, rejected, img)
##cv2.imshow("Image", detected_markers)
Preview.show(detected_markers)
picam2.start_preview(Preview.QTGL)
key = cv2.waitKey(1) & 0xFF
# clear the stream in preparation for the next frame
#np_array.truncate(0)
if key == ord("q"):
break
# clear the stream in preparation for the next frame
np_array.truncate(0)
except KeyboardInterrupt:
print("Exiting program...")
finally:
cv2.destroyAllWindows()
picam2.close()
I've checked the dependencies and confirmed the libraries where installed. I installed 'xcb', I updated picamera2, opencv and the entire system. Other things that have been suggested is to "Double-check that the QT_QPA_PLATFORM_PLUGIN_PATH and QT_QPA_PLATFORM environment variables are set correctly. Make sure the paths are correct and point to the right directories." which I'm not really understanding how to do and I have yet to try an alternative platform plugins.
Could anyone help me?
QObject::moveToThread: Current thread (0x7f6c02f960) is not the object's thread (0x7f6c1753c0).
Cannot move to target thread (0x7f6c02f960)
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/cbarreto/env/lib/python3.11/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: xcb, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx.
Aborted
while running this code:
#PiCam
import cv2
import numpy as np
import time
from picamera2 import Picamera2, Preview
ARUCO_DICT = {
"DICT_4X4_50" : cv2.aruco.DICT_4X4_50,
"DICT_4X4_100" : cv2.aruco.DICT_4X4_100,
"DICT_4X4_250" : cv2.aruco.DICT_4X4_250,
"DICT_4X4_1000" : cv2.aruco.DICT_4X4_1000,
"DICT_5X5_50" : cv2.aruco.DICT_5X5_50,
"DICT_5X5_100" : cv2.aruco.DICT_5X5_100,
"DICT_5X5_250" : cv2.aruco.DICT_5X5_250,
"DICT_5X5_1000" : cv2.aruco.DICT_5X5_1000,
"DICT_6X6_50" : cv2.aruco.DICT_6X6_50,
"DICT_6X6_100" : cv2.aruco.DICT_6X6_100,
"DICT_6X6_250" : cv2.aruco.DICT_6X6_250,
"DICT_6X6_1000" : cv2.aruco.DICT_6X6_1000,
"DICT_7X7_50" : cv2.aruco.DICT_7X7_50,
"DICT_7X7_100" : cv2.aruco.DICT_7X7_100,
"DICT_7X7_250" : cv2.aruco.DICT_7X7_250,
"DICT_7X7_1000" : cv2.aruco.DICT_7X7_1000,
"DICT_ARUCO_ORIGINAL" : cv2.aruco.DICT_ARUCO_ORIGINAL,
"DICT_APRILTAG_16h5" : cv2.aruco.DICT_APRILTAG_16H5,
"DICT_APRILTAG_25h9" : cv2.aruco.DICT_APRILTAG_25H9,
"DICT_APRILTAG_36h10" : cv2.aruco.DICT_APRILTAG_36H10,
"DICT_APRILTAG_36h11" : cv2.aruco.DICT_APRILTAG_36H11,
}
def aruco_display(corners, ids, rejected, image):
if len(corners) > 0:
ids = ids.flatten()
for (markerCorner, markerID) in zip(corners, ids):
corners = markerCorner.reshape((4,2))
(topLeft, topRight, bottomRight, bottomLeft) = corners
topRight = (int(topRight[0]), int(topRight[1]))
bottomRight = (int(bottomRight[0]), int(bottomRight[1]))
bottomLeft = (int(bottomLeft[0]), int(bottomLeft[1]))
topLeft = (int(topLeft[0]), int(topLeft[1]))
cv2.line(image, topLeft, topRight, (0, 255, 0), 2)
cv2.line(image, topRight, bottomRight, (0, 255, 0), 2)
cv2.line(image, bottomRight, bottomLeft, (0, 255, 0), 2)
cv2.line(image, bottomLeft, topLeft, (0, 255, 0), 2)
cX = int((topLeft[0] + bottomRight[0])/ 2.0)
cY = int((topLeft[1] + bottomRight[1])/ 2.0)
cv2.circle(image, (cX, cY), 4, (0, 0, 255), -1)
cv2.putText(image, str(markerID),(topLeft[0], topLeft[1] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
print("[Inference] Aruco marker ID: {}".format(markerID))
return image
arucoDict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_100)
arucoParams = cv2.aruco.DetectorParameters()
try:
# Initialize picamera2
picam2 = Picamera2()
picam2.start_preview(Preview.QTGL)
# Set the stream format
config = picam2.create_preview_configuration({"size": (640, 480)})
#preview = Preview(picam2, show_fps=True)
picam2.configure(config)
# Start capturing
np_array = picam2.capture_array()
raw_np_array = picam2.capture_array("raw")
time.sleep(0.1) # allow the camera to warmup
for frame in picam2.capture_continuous(np_array, format="bgr", use_video_port=True):
# Convert the raw buffer data to an image
img = frame.array
h, w, _ = img.shape
width = 1000
height = int(width*(h/w))
img = cv2.resize(img,(width, height), interpolation=cv2.INTER_CUBIC)
corners, ids, rejected = cv2.aruco.detectMarkers(img, arucoDict, parameters=arucoParams)
detected_markers = aruco_display(corners, ids, rejected, img)
##cv2.imshow("Image", detected_markers)
Preview.show(detected_markers)
picam2.start_preview(Preview.QTGL)
key = cv2.waitKey(1) & 0xFF
# clear the stream in preparation for the next frame
#np_array.truncate(0)
if key == ord("q"):
break
# clear the stream in preparation for the next frame
np_array.truncate(0)
except KeyboardInterrupt:
print("Exiting program...")
finally:
cv2.destroyAllWindows()
picam2.close()
I've checked the dependencies and confirmed the libraries where installed. I installed 'xcb', I updated picamera2, opencv and the entire system. Other things that have been suggested is to "Double-check that the QT_QPA_PLATFORM_PLUGIN_PATH and QT_QPA_PLATFORM environment variables are set correctly. Make sure the paths are correct and point to the right directories." which I'm not really understanding how to do and I have yet to try an alternative platform plugins.
Could anyone help me?
Statistics: Posted by cbarreto — Wed May 08, 2024 6:35 am