When I try to use the script underneath to get the data back to the cpu, there is an error. I don't get an error when I try to put some values in "ref" if I would just put:
ref[1] = 255; ref[0] = 255; ref[2] = 255;
but if I do something like this:
if (verschil.a[idx+idy*640]>5){
ref[1] = 255; ref[0] = 255; ref[2] = 255;
}
the error message I get is:
Traceback (most recent call last):
File "./zwartwit.py", line 159, in <module>
verwerking(cuda.InOut(refe),cuda.InOut(frame), block=(640, 1, 1))
File "/usr/lib/python2.7/dist-packages/pycuda/driver.py", line 374, in function_call
func._launch_kernel(grid, block, arg_buf, shared, None)
pycuda._driver.LogicError: cuLaunchKernel failed: invalid value
Thanks for the help!
ps, this is a symplified version of the script I was talking about. to get the same error, the // must be removed.
import pycuda.driver as cuda
import pycuda.autoinit
from pycuda.compiler import SourceModule
import numpy
import cv2
from time import time,sleep
mod = SourceModule("""
struct legear{ int a[307200];};
__global__ void totaal(int *ref){
int idx = threadIdx.x + blockIdx.x * blockDim.x;
legear test;
for (int idy=0;idy<480;idy++){
if (idy < 480){
if (idx < 640){
if (ref[idx*3+idy*640*3]>100){
test.a[idx+idy*640] = 255;
}
//if (test.a[idx+idy*640] == 255){
ref[idx*3+idy*640*3] = 255; ref[idx*3+idy*640*3+1] = 255; ref[idx*3+idy*640*3+2] = 255;
//}
}
}
}
}
""")
camera = cv2.VideoCapture(0)
im2 = numpy.zeros((768, 1024, 1 ),dtype=numpy.uint8)
cv2.imshow("projector", im2)
key = cv2.waitKey(100)
for i in range(0,8):
refe = camera.read()[1]
im2[500:502] = [100]
cv2.imshow("projector", im2)
key = cv2.waitKey(100)
verwerking = mod.get_function("totaal")
refe = refe.astype(numpy.int32)
verwerking(cuda.InOut(refe), block=(640, 1, 1))
refe = refe.astype(numpy.uint8)
cv2.imshow("test", refe)
cv2.waitKey(200)
raw_input()