Search in sources :

Example 1 with CLImage2d

use of com.jogamp.opencl.CLImage2d in project javacv by bytedeco.

the class JavaCVCL method main.

public static void main(String[] args) {
    JavaCVCL context = new JavaCVCL();
    CLImageFormat[] formats = context.getCLContext().getSupportedImage2dFormats();
    for (CLImageFormat f : formats) {
        System.out.println(f);
    }
    CameraDevice camera = new CameraDevice("Camera");
    camera.imageWidth = 1280;
    camera.imageHeight = 960;
    camera.cameraMatrix = CvMat.create(3, 3);
    double f = camera.imageWidth * 2.5;
    camera.cameraMatrix.put(f, 0.0, camera.imageWidth / 2, 0.0, f, camera.imageHeight / 2, 0.0, 0.0, 1);
    camera.R = CvMat.create(3, 3);
    cvSetIdentity(camera.R);
    camera.T = CvMat.create(3, 1);
    cvSetZero(camera.T);
    camera.distortionCoeffs = CvMat.create(1, 4);
    cvSetZero(camera.distortionCoeffs);
    camera.distortionCoeffs.put(0.2);
    camera.colorMixingMatrix = CvMat.create(3, 3);
    cvSetIdentity(camera.colorMixingMatrix);
    IplImage srcImg = cvLoadImageRGBA(args[0]);
    // IplImage dstImg = srcImg.clone();
    IplImage downDst = IplImage.create(srcImg.width() / 2, srcImg.height() / 2, IPL_DEPTH_8U, /*IPL_DEPTH_32F*/
    4);
    camera.setFixedPointMaps(false);
    camera.setMapsPyramidLevel(1);
    IplImage mapxImg = camera.getUndistortMap1();
    IplImage mapyImg = camera.getUndistortMap2();
    long start = System.nanoTime();
    cvRemap(srcImg, downDst, mapxImg, mapyImg, CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS, CvScalar.ZERO);
    System.out.println("cvRemap: " + (System.nanoTime() - start) / 1000000.0);
    cvSaveImage("/tmp/opencv.png", downDst);
    CLImage2d src = context.createCLImageFrom(srcImg);
    // CLImage2d dst = context.createCLImageFrom(dstImg);
    CLImage2d dst = context.createCLImageFrom(downDst);
    CLImage2d mapx = context.createCLImageFrom(mapxImg);
    CLImage2d mapy = context.createCLImageFrom(mapyImg);
    context.writeImage(src, srcImg, false);
    context.writeImage(mapx, mapxImg, false);
    context.writeImage(mapy, mapyImg, false);
    // context.pyrDown(src, dst);
    context.remap(src, dst, mapx, mapy);
    context.readImage(dst, downDst, true);
    // cvConvertScale(downDst, downDst, 255, 0);
    cvSaveImage("/tmp/javacvcl.png", downDst);
    context.release();
    System.exit(0);
}
Also used : CLImage2d(com.jogamp.opencl.CLImage2d) CLImageFormat(com.jogamp.opencl.CLImageFormat)

Example 2 with CLImage2d

use of com.jogamp.opencl.CLImage2d in project javacv by bytedeco.

the class ProCamTransformerCL method transform.

@Override
public void transform(CLImage2d srcImg, CLImage2d subImg, CLImage2d srcDotImg, CLImage2d transImg, CLImage2d dstImg, CLImage2d maskImg, ImageTransformer.Parameters[] parameters, boolean[] inverses, InputData inputData, OutputData outputData) {
    if (inverses != null) {
        for (int i = 0; i < inverses.length; i++) {
            if (inverses[i]) {
                throw new UnsupportedOperationException("Inverse transform not supported.");
            }
        }
    }
    prepareTransforms(H1Buffer, H2Buffer, XBuffer, inputData.pyramidLevel, parameters);
    final int dotSize = parameters[0].size();
    final int localSize = parameters.length > 1 ? parameters.length : (inputData.roiWidth > 32 ? 64 : 32);
    final int globalSize = JavaCVCL.alignCeil(inputData.roiWidth, localSize);
    final int reduceSize = globalSize / localSize;
    // allocate buffers if necessary
    CLBuffer inputBuffer = inputData.getBuffer(context);
    CLBuffer outputBuffer = outputData.getBuffer(context, dotSize, reduceSize);
    CLEventList list = new CLEventList(1);
    // setup kernel
    if (surfaceTransformer != null) {
        // upload H1
        context.writeBuffer(H1Buffer, false);
    }
    // upload H2
    context.writeBuffer(H2Buffer, false);
    // upload X
    context.writeBuffer(XBuffer, false);
    if (inputData.autoWrite) {
        inputData.writeBuffer(context);
    }
    CLImage2d srcImg2 = projectorImageCL[inputData.pyramidLevel];
    CLKernel kernel = null;
    if (subImg == null) {
        assert parameters.length == 1;
        kernel = oneKernel.putArg(srcImg2).putArg(srcImg).putArg(dstImg == null ? transImg : dstImg).putArg(maskImg).putArg(H2Buffer);
    } else if (srcDotImg == null) {
        assert parameters.length == 1;
        kernel = subKernel.putArg(srcImg2).putArg(srcImg).putArg(subImg).putArg(transImg).putArg(dstImg).putArg(maskImg).putArg(H2Buffer);
    } else {
        assert parameters.length == dotSize;
        kernel = dotKernel.putArg(srcImg2).putArg(srcImg).putArg(subImg).putArg(srcDotImg).putArg(maskImg).putArg(H2Buffer);
    // System.out.println(kernel.getWorkGroupSize(context.getCLCommandQueue().getDevice()));
    }
    if (H1Buffer != null) {
        kernel.putArg(H1Buffer);
    } else {
        kernel.putNullArg(nullSize);
    }
    kernel.putArg(XBuffer).putArg(inputBuffer).putArg(outputBuffer).rewind();
    context.executeKernel(kernel, inputData.roiX, 0, 0, globalSize, 1, parameters.length, localSize, 1, parameters.length, // execute program
    list);
    if (reduceSize > 1) {
        reduceKernel.putArg(outputBuffer).rewind();
        context.executeKernel(reduceKernel, 0, reduceSize, reduceSize);
    }
    if (outputData.autoRead) {
        outputData.readBuffer(context);
    }
// CLEvent event = list.getEvent(0);
// System.out.println((event.getProfilingInfo(CLEvent.ProfilingCommand.END) -
// event.getProfilingInfo(CLEvent.ProfilingCommand.START))/1000000.0);
// long res = q.getDevice().getProfilingTimerResolution();
// System.out.println(res);
}
Also used : CLBuffer(com.jogamp.opencl.CLBuffer) CLImage2d(com.jogamp.opencl.CLImage2d) CLEventList(com.jogamp.opencl.CLEventList) CLKernel(com.jogamp.opencl.CLKernel)

Aggregations

CLImage2d (com.jogamp.opencl.CLImage2d)2 CLBuffer (com.jogamp.opencl.CLBuffer)1 CLEventList (com.jogamp.opencl.CLEventList)1 CLImageFormat (com.jogamp.opencl.CLImageFormat)1 CLKernel (com.jogamp.opencl.CLKernel)1