Skip to content

Commit 43b76e5

Browse files
author
Andrey Pavlenko
committed
adding NO_PROCESSING (i.e. just preview) mode
1 parent 016011f commit 43b76e5

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

samples/android/tutorial-4-opencl/jni/CLprocessor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ void dumpCLinfo()
7979
cl::Context theContext;
8080
cl::CommandQueue theQueue;
8181
cl::Program theProgB2B, theProgI2B, theProgI2I;
82+
bool haveOpenCL = false;
8283

8384
void initCL()
8485
{
@@ -100,6 +101,7 @@ void initCL()
100101

101102
try
102103
{
104+
haveOpenCL = false;
103105
cl::Platform p = cl::Platform::getDefault();
104106
std::string ext = p.getInfo<CL_PLATFORM_EXTENSIONS>();
105107
if(ext.find("cl_khr_gl_sharing") == std::string::npos)
@@ -124,6 +126,7 @@ void initCL()
124126
LOGD("OpenCV+OpenCL works OK!");
125127
else
126128
LOGE("Can't init OpenCV with OpenCL TAPI");
129+
haveOpenCL = true;
127130
}
128131
catch(cl::Error& e)
129132
{
@@ -147,6 +150,8 @@ void closeCL()
147150
#define GL_TEXTURE_2D 0x0DE1
148151
void procOCL_I2I(int texIn, int texOut, int w, int h)
149152
{
153+
if(!haveOpenCL) return;
154+
150155
LOGD("procOCL_I2I(%d, %d, %d, %d)", texIn, texOut, w, h);
151156
cl::ImageGL imgIn (theContext, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, texIn);
152157
cl::ImageGL imgOut(theContext, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, texOut);
@@ -179,6 +184,8 @@ void procOCL_I2I(int texIn, int texOut, int w, int h)
179184

180185
void procOCL_OCV(int tex, int w, int h)
181186
{
187+
if(!haveOpenCL) return;
188+
182189
int64_t t = getTimeMs();
183190
cl::ImageGL imgIn (theContext, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, tex);
184191
std::vector < cl::Memory > images(1, imgIn);

samples/android/tutorial-4-opencl/jni/GLrender.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ GLuint FBO = 0;
6363
GLuint texOES = 0;
6464
int texWidth = 0, texHeight = 0;
6565

66-
enum ProcMode {PROC_MODE_CPU=1, PROC_MODE_OCL_DIRECT=2, PROC_MODE_OCL_OCV=3};
66+
enum ProcMode {PROC_MODE_NO_PROC=0, PROC_MODE_CPU=1, PROC_MODE_OCL_DIRECT=2, PROC_MODE_OCL_OCV=3};
6767

68-
ProcMode procMode = PROC_MODE_CPU;
68+
ProcMode procMode = PROC_MODE_NO_PROC;
6969

7070
static inline void deleteTex(GLuint* tex)
7171
{
@@ -298,6 +298,7 @@ extern "C" void drawFrame()
298298

299299
switch(procMode)
300300
{
301+
case PROC_MODE_NO_PROC: drawFrameOrig(); break;
301302
case PROC_MODE_CPU: drawFrameProcCPU(); break;
302303
case PROC_MODE_OCL_DIRECT: drawFrameProcOCL(); break;
303304
case PROC_MODE_OCL_OCV: drawFrameProcOCLOCV(); break;
@@ -366,6 +367,7 @@ extern "C" void setProcessingMode(int mode)
366367
{
367368
switch(mode)
368369
{
370+
case PROC_MODE_NO_PROC: procMode = PROC_MODE_NO_PROC; break;
369371
case PROC_MODE_CPU: procMode = PROC_MODE_CPU; break;
370372
case PROC_MODE_OCL_DIRECT: procMode = PROC_MODE_OCL_DIRECT; break;
371373
case PROC_MODE_OCL_OCV: procMode = PROC_MODE_OCL_OCV; break;

samples/android/tutorial-4-opencl/res/menu/menu.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
33
<group android:checkableBehavior="single">
4+
<item android:id="@+id/no_proc" android:title="No processing" />
45
<item android:id="@+id/cpu" android:title="Use CPU code" />
56
<item android:id="@+id/ocl_direct" android:title="Use OpenCL direct" />
67
<item android:id="@+id/ocl_ocv" android:title="Use OpenCL via OpenCV" />

samples/android/tutorial-4-opencl/src/org/opencv/samples/tutorial4/NativeGLRenderer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class NativeGLRenderer {
77
System.loadLibrary("JNIrender");
88
}
99

10+
public static final int PROCESSING_MODE_NO_PROCESSING = 0;
1011
public static final int PROCESSING_MODE_CPU = 1;
1112
public static final int PROCESSING_MODE_OCL_DIRECT = 2;
1213
public static final int PROCESSING_MODE_OCL_OCV = 3;

samples/android/tutorial-4-opencl/src/org/opencv/samples/tutorial4/Tutorial4Activity.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public void onCreate(Bundle savedInstanceState) {
3434
mProcMode = (TextView)findViewById(R.id.proc_mode_text_view);
3535
runOnUiThread(new Runnable() {
3636
public void run() {
37-
mProcMode.setText("Processing mode: CPU");
37+
mProcMode.setText("Processing mode: No processing");
3838
}
3939
});
4040

41-
NativeGLRenderer.setProcessingMode(NativeGLRenderer.PROCESSING_MODE_CPU); }
41+
NativeGLRenderer.setProcessingMode(NativeGLRenderer.PROCESSING_MODE_NO_PROCESSING); }
4242

4343
@Override
4444
protected void onPause() {
@@ -62,6 +62,14 @@ public boolean onCreateOptionsMenu(Menu menu) {
6262
@Override
6363
public boolean onOptionsItemSelected(MenuItem item) {
6464
switch (item.getItemId()) {
65+
case R.id.no_proc:
66+
runOnUiThread(new Runnable() {
67+
public void run() {
68+
mProcMode.setText("Processing mode: No Processing");
69+
}
70+
});
71+
NativeGLRenderer.setProcessingMode(NativeGLRenderer.PROCESSING_MODE_NO_PROCESSING);
72+
return true;
6573
case R.id.cpu:
6674
runOnUiThread(new Runnable() {
6775
public void run() {

0 commit comments

Comments
 (0)