Hi all,
I have this simple code to downsample an image using linear interpolation
but I am stuck:
import pyopencl as cl
import numpy as np
import cv2 # OpenCV 2.3.1
# load a 512x512 image
Img = cv2.imread("testsmall.jpg", cv2.CV_LOAD_IMAGE_GRAYSCALE)
OutImg = np.empty(shape=(Img.shape[0]/2,Img.shape[1]/2), dtype=np.uint8) #
create Output-Image
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)
mf = cl.mem_flags
dev_Img = cl.Image(ctx,
mf.READ_ONLY | mf.USE_HOST_PTR,
cl.ImageFormat(cl.channel_order.R,
cl.channel_type.UNSIGNED_INT8),
hostbuf=Img)
dev_OutImg = cl.Image(ctx,
mf.WRITE_ONLY,
cl.ImageFormat(cl.channel_order.R,
cl.channel_type.UNSIGNED_INT8),
shape=(Img.shape[0]/2,Img.shape[1]/2))
prg = cl.Program(ctx, """
const sampler_t smp = CLK_NORMALIZED_COORDS_TRUE |
CLK_FILTER_LINEAR | CLK_ADDRESS_CLAMP_TO_EDGE;
__kernel void ImageDS(__read_only image2d_t Img, __write_only
image2d_t Out)
{
const int2 Coords = (int2)(get_global_id(0), get_global_id(1));
write_imagef(Out, Coords, read_imagef(Img, smp, Coords));
}
""").build()
prg.ImageDS(queue, Img.shape, None, dev_Img, dev_OutImg)
cl.enqueue_read_image(queue, dev_OutImg, (0, 0), OutImg.shape,
OutImg).wait()
cv2.imwrite("out.jpg", OutImg)
The error is:
Traceback (most recent call last):
File "pycltesttex.py", line 44, in <module>
cl.enqueue_read_image(queue, dev_OutImg, (0, 0), OutImg.shape,
OutImg).wait()
File "/Library/Python/2.7/site-packages/pyopencl/__init__.py", line 902,
in new_func
return func(*args, **kwargs)
pyopencl.LogicError: clEnqueueReadImage failed: invalid value
Not sure what I am doing wrong with the enqueue_read_image call. Does
anybody know?
Thanks a ton!
Daniel
_______________________________________________
PyOpenCL mailing list
[email protected]
http://lists.tiker.net/listinfo/pyopencl