What system do you use? Android, Ubuntu, OOWOW or other?
Ubuntu22.04
What version of the system do you use? Kadas official image, homebrew, or other?
Kadas official ubutu
Please describe your issue below:
kernel.cl
__kernel void vector_add(__global const float *a, __global const float *b, __global const float *c, const unsigned int n) {
int id = get_global_id(0);
if (id < n) {
c[id] = a[id] + b[id];
}
}
test.py
import cv2
import numpy as np
import pyopencl as cl
import time
Vector operations work fine, but when I process images, I get all zeros.
KERNEL_SOURCE = "kernel.cl"
with open(KERNEL_SOURCE, "r") as source_file:
kernel_str = source_file.read()
platforms = cl.get_platforms()
if not platforms:
print("No OpenCL platforms found.")
exit(1)
platform = platforms[0]
devices = platform.get_devices(cl.device_type.ALL)
if not devices:
print("No OpenCL devices found.")
exit(1)
device = devices[0]
print(f"Using device: {device.name}")
context = cl.Context([device])
queue = cl.CommandQueue(context, properties=cl.command_queue_properties.PROFILING_ENABLE)
try:
program = cl.Program(context, kernel_str).build()
except cl.RuntimeError as e:
print("Error during kernel build:", e)
print("Build log:\n", program.get_build_info(device, cl.program_build_info.LOG))
exit(1)
copy_image = program.copy_image
gst_pipeline = (
'v4l2src device=/dev/video0 ! '
'videoconvert ! '
'video/x-raw,format=BGRx ! '
'appsink'
)
OpenCV VideoCapture ๊ฐ์ฒด ์์ฑ
cap = cv2.VideoCapture(gst_pipeline, cv2.CAP_GSTREAMER)
if not cap.isOpened():
print("Error: Unable to open video source.")
exit(1)
try:
while True:
ret, frame = cap.read()
if not ret:
print("Failed to capture frame")
break
print("Frame captured")
height, width = frame.shape[:2]
print(f"Frame size: {width}x{height}")
image_format = cl.ImageFormat(cl.channel_order.RGBA, cl.channel_type.UNSIGNED_INT8)
mf = cl.mem_flags
frame_bgra = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA)
print("Converted frame to BGRA")
src_buf = cl.Image(context, mf.READ_ONLY | mf.COPY_HOST_PTR, image_format, shape=(width, height), hostbuf=frame_bgra)
dst_buf = cl.Image(context, mf.WRITE_ONLY, image_format, shape=(width, height))
copy_image.set_args(src_buf, dst_buf)
cl.enqueue_nd_range_kernel(queue, copy_image, (width, height), None)
queue.finish()
print("Kernel executed")
result = np.empty_like(frame_bgra)
cl.enqueue_copy(queue, result, dst_buf, origin=(0, 0), region=(width, height))
queue.finish()
print("Result copied from device")
result_bgr = cv2.cvtColor(result, cv2.COLOR_BGRA2BGR)
print("Converted result to BGR")
cv2.imshow('Original', frame)
cv2.imshow('Copied', result_bgr)
time.sleep(0.033)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
except KeyboardInterrupt:
print("KeyboardInterrupt detected, exiting gracefully.")
finally:
cap.release()
cv2.destroyAllWindows()
Vector operations work fine, but when I process images, I get all zeros.
Do you know why?
$ sudo mv /usr/lib/libOpenCL.so /usr/lib/libOpenCL.so.old
$ sudo ln -s /usr/lib/aarch64-linux-gnu/libOpenCL.so.1.0.0 /usr/lib/libOpenCL.so
I tried this as well and also installed cl and confirmed that the gpu is caught in clinfo
Post a console log of the issue below:
**Delete this line and post the log here.
Translated with DeepL Translate: The world's most accurate translator (free version)