adding OpenCV with TAPI (UMats)
This commit is contained in:
parent
274aba1a89
commit
0e4bb2b49f
@ -7,8 +7,15 @@ LOCAL_EXPORT_C_INCLUDES := $(OPENCL_SDK)/include
|
|||||||
include $(PREBUILT_SHARED_LIBRARY)
|
include $(PREBUILT_SHARED_LIBRARY)
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
OPENCV_INSTALL_MODULES:=on
|
||||||
|
ifeq ($(O4A_SDK_ROOT),)
|
||||||
|
include ../../sdk/native/jni/OpenCV.mk
|
||||||
|
else
|
||||||
|
include $(O4A_SDK_ROOT)/sdk/native/jni/OpenCV.mk
|
||||||
|
endif
|
||||||
|
|
||||||
LOCAL_MODULE := JNIrender
|
LOCAL_MODULE := JNIrender
|
||||||
LOCAL_SRC_FILES := jni.c GLrender.cpp CLprocessor.cpp
|
LOCAL_SRC_FILES := jni.c GLrender.cpp CLprocessor.cpp
|
||||||
LOCAL_LDLIBS := -llog -lGLESv2 -lEGL
|
LOCAL_LDLIBS += -llog -lGLESv2 -lEGL
|
||||||
LOCAL_SHARED_LIBRARIES := OpenCL
|
LOCAL_SHARED_LIBRARIES += OpenCL
|
||||||
include $(BUILD_SHARED_LIBRARY)
|
include $(BUILD_SHARED_LIBRARY)
|
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
#include <EGL/egl.h>
|
#include <EGL/egl.h>
|
||||||
|
|
||||||
|
#include <opencv2/opencv.hpp>
|
||||||
|
#include <opencv2/core/ocl.hpp>
|
||||||
|
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
|
|
||||||
const char oclProgB2B[] = "// clBuffer to clBuffer";
|
const char oclProgB2B[] = "// clBuffer to clBuffer";
|
||||||
@ -79,6 +82,8 @@ cl::Program theProgB2B, theProgI2B, theProgI2I;
|
|||||||
|
|
||||||
void initCL()
|
void initCL()
|
||||||
{
|
{
|
||||||
|
dumpCLinfo();
|
||||||
|
|
||||||
EGLDisplay mEglDisplay = eglGetCurrentDisplay();
|
EGLDisplay mEglDisplay = eglGetCurrentDisplay();
|
||||||
if (mEglDisplay == EGL_NO_DISPLAY)
|
if (mEglDisplay == EGL_NO_DISPLAY)
|
||||||
LOGE("initCL: eglGetCurrentDisplay() returned 'EGL_NO_DISPLAY', error = %x", eglGetError());
|
LOGE("initCL: eglGetCurrentDisplay() returned 'EGL_NO_DISPLAY', error = %x", eglGetError());
|
||||||
@ -113,6 +118,12 @@ void initCL()
|
|||||||
cl::Program::Sources src(1, std::make_pair(oclProgI2I, sizeof(oclProgI2I)));
|
cl::Program::Sources src(1, std::make_pair(oclProgI2I, sizeof(oclProgI2I)));
|
||||||
theProgI2I = cl::Program(theContext, src);
|
theProgI2I = cl::Program(theContext, src);
|
||||||
theProgI2I.build(devs);
|
theProgI2I.build(devs);
|
||||||
|
|
||||||
|
cv::ocl::attachContext(p.getInfo<CL_PLATFORM_NAME>(), p(), theContext(), devs[0]());
|
||||||
|
if( cv::ocl::useOpenCL() )
|
||||||
|
LOGD("OpenCV+OpenCL works OK!");
|
||||||
|
else
|
||||||
|
LOGE("Can't init OpenCV with OpenCL TAPI");
|
||||||
}
|
}
|
||||||
catch(cl::Error& e)
|
catch(cl::Error& e)
|
||||||
{
|
{
|
||||||
@ -166,3 +177,38 @@ void procOCL_I2I(int texIn, int texOut, int w, int h)
|
|||||||
theQueue.finish();
|
theQueue.finish();
|
||||||
LOGD("enqueueReleaseGLObjects() costs %d ms", getTimeInterval(t));
|
LOGD("enqueueReleaseGLObjects() costs %d ms", getTimeInterval(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void procOCL_OCV(int tex, int w, int h)
|
||||||
|
{
|
||||||
|
int64_t t = getTimeMs();
|
||||||
|
cl::ImageGL imgIn (theContext, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, tex);
|
||||||
|
std::vector < cl::Memory > images(1, imgIn);
|
||||||
|
theQueue.enqueueAcquireGLObjects(&images);
|
||||||
|
theQueue.finish();
|
||||||
|
cv::UMat uIn, uOut, uTmp;
|
||||||
|
cv::ocl::convertFromImage(imgIn(), uIn);
|
||||||
|
LOGD("loading texture data to OpenCV UMat costs %d ms", getTimeInterval(t));
|
||||||
|
theQueue.enqueueReleaseGLObjects(&images);
|
||||||
|
|
||||||
|
t = getTimeMs();
|
||||||
|
//cv::blur(uIn, uOut, cv::Size(5, 5));
|
||||||
|
cv::Laplacian(uIn, uTmp, CV_8U);
|
||||||
|
cv:multiply(uTmp, 10, uOut);
|
||||||
|
cv::ocl::finish();
|
||||||
|
LOGD("OpenCV processing costs %d ms", getTimeInterval(t));
|
||||||
|
|
||||||
|
t = getTimeMs();
|
||||||
|
cl::ImageGL imgOut(theContext, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, tex);
|
||||||
|
images.clear();
|
||||||
|
images.push_back(imgOut);
|
||||||
|
theQueue.enqueueAcquireGLObjects(&images);
|
||||||
|
cl_mem clBuffer = (cl_mem)uOut.handle(cv::ACCESS_READ);
|
||||||
|
cl_command_queue q = (cl_command_queue)cv::ocl::Queue::getDefault().ptr();
|
||||||
|
size_t offset = 0;
|
||||||
|
size_t origin[3] = { 0, 0, 0 };
|
||||||
|
size_t region[3] = { w, h, 1 };
|
||||||
|
CV_Assert(clEnqueueCopyBufferToImage (q, clBuffer, imgOut(), offset, origin, region, 0, NULL, NULL) == CL_SUCCESS);
|
||||||
|
theQueue.enqueueReleaseGLObjects(&images);
|
||||||
|
cv::ocl::finish();
|
||||||
|
LOGD("uploading results to texture costs %d ms", getTimeInterval(t));
|
||||||
|
}
|
||||||
|
@ -238,17 +238,18 @@ void drawFrameProcCPU()
|
|||||||
drawTex(FBOtex, GL_TEXTURE_2D, 0);
|
drawTex(FBOtex, GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void procOCL(int tex, int w, int h);
|
|
||||||
void procOCL_I2I(int texIn, int texOut, int w, int h);
|
void procOCL_I2I(int texIn, int texOut, int w, int h);
|
||||||
|
void procOCL_OCV(int tex, int w, int h);
|
||||||
void drawFrameProcOCL()
|
void drawFrameProcOCL()
|
||||||
{
|
{
|
||||||
drawTex(texOES, GL_TEXTURE_EXTERNAL_OES, FBO);
|
drawTex(texOES, GL_TEXTURE_EXTERNAL_OES, FBO);
|
||||||
|
|
||||||
// modify pixels in FBO texture using OpenCL and CL-GL interop
|
// modify pixels in FBO texture using OpenCL and CL-GL interop
|
||||||
procOCL_I2I(FBOtex, FBOtex2, texWidth, texHeight);
|
//procOCL_I2I(FBOtex, FBOtex2, texWidth, texHeight);
|
||||||
|
procOCL_OCV(FBOtex, texWidth, texHeight);
|
||||||
|
|
||||||
// render to screen
|
// render to screen
|
||||||
drawTex(FBOtex2, GL_TEXTURE_2D, 0);
|
drawTex(/*FBOtex2*/FBOtex, GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package org.opencv.samples.tutorial4;
|
|||||||
public class NativeGLRenderer {
|
public class NativeGLRenderer {
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
|
System.loadLibrary("opencv_java3");
|
||||||
System.loadLibrary("JNIrender");
|
System.loadLibrary("JNIrender");
|
||||||
}
|
}
|
||||||
public static native int initGL();
|
public static native int initGL();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user