Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
56bde913
Commit
56bde913
authored
Jul 31, 2015
by
Andrey Pavlenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding mode switching via menu
parent
9ab291ea
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
134 additions
and
16 deletions
+134
-16
GLrender.cpp
samples/android/tutorial-4-opencl/jni/GLrender.cpp
+38
-10
jni.c
samples/android/tutorial-4-opencl/jni/jni.c
+6
-0
activity.xml
samples/android/tutorial-4-opencl/res/layout/activity.xml
+15
-5
menu.xml
samples/android/tutorial-4-opencl/res/menu/menu.xml
+8
-0
MyGLSurfaceView.java
...ncl/src/org/opencv/samples/tutorial4/MyGLSurfaceView.java
+9
-0
NativeGLRenderer.java
...cl/src/org/opencv/samples/tutorial4/NativeGLRenderer.java
+6
-0
Tutorial4Activity.java
...l/src/org/opencv/samples/tutorial4/Tutorial4Activity.java
+52
-1
No files found.
samples/android/tutorial-4-opencl/jni/GLrender.cpp
View file @
56bde913
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <opencv2/opencv.hpp>
#include "common.hpp"
float
vertices
[]
=
{
...
...
@@ -60,6 +62,10 @@ GLuint FBO = 0;
GLuint
texOES
=
0
;
int
texWidth
=
0
,
texHeight
=
0
;
enum
ProcMode
{
PROC_MODE_CPU
=
1
,
PROC_MODE_OCL_DIRECT
=
2
,
PROC_MODE_OCL_OCV
=
3
};
ProcMode
procMode
=
PROC_MODE_CPU
;
static
inline
void
deleteTex
(
GLuint
*
tex
)
{
if
(
tex
&&
*
tex
)
...
...
@@ -223,12 +229,9 @@ void drawFrameOrig()
void
procCPU
(
char
*
buff
,
int
w
,
int
h
)
{
int64_t
t
=
getTimeMs
();
for
(
int
i
=
0
;
i
<
h
;
i
++
)
{
buff
[
i
*
w
*
4
+
i
*
4
+
0
]
=
255
;
buff
[
i
*
w
*
4
+
i
*
4
+
4
]
=
255
;
buff
[
i
*
w
*
4
+
i
*
4
+
8
]
=
255
;
}
cv
::
Mat
m
(
h
,
w
,
CV_8UC4
,
buff
);
cv
::
Laplacian
(
m
,
m
,
CV_8U
);
m
*=
10
;
LOGD
(
"procCPU() costs %d ms"
,
getTimeInterval
(
t
));
}
...
...
@@ -271,20 +274,35 @@ void drawFrameProcOCL()
// modify pixels in FBO texture using OpenCL and CL-GL interop
procOCL_I2I
(
FBOtex
,
FBOtex2
,
texWidth
,
texHeight
);
//procOCL_OCV(FBOtex, texWidth, texHeight);
// render to screen
drawTex
(
FBOtex2
,
GL_TEXTURE_2D
,
0
);
}
void
drawFrameProcOCLOCV
()
{
drawTex
(
texOES
,
GL_TEXTURE_EXTERNAL_OES
,
FBO
);
// modify pixels in FBO texture using OpenCL and CL-GL interop
procOCL_OCV
(
FBOtex
,
texWidth
,
texHeight
);
// render to screen
drawTex
(
FBOtex
,
GL_TEXTURE_2D
,
0
);
}
extern
"C"
void
drawFrame
()
{
LOGD
(
"*** drawFrame() ***"
);
int64_t
t
=
getTimeMs
();
//drawFrameOrig();
//drawFrameProcCPU();
drawFrameProcOCL
();
switch
(
procMode
)
{
case
PROC_MODE_CPU
:
drawFrameProcCPU
();
break
;
case
PROC_MODE_OCL_DIRECT
:
drawFrameProcOCL
();
break
;
case
PROC_MODE_OCL_OCV
:
drawFrameProcOCLOCV
();
break
;
default
:
drawFrameOrig
();
}
glFinish
();
LOGD
(
"*** drawFrame() costs %d ms ***"
,
getTimeInterval
(
t
));
}
...
...
@@ -342,3 +360,13 @@ extern "C" void changeSize(int width, int height)
texHeight
=
height
<=
MAX_H
?
height
:
MAX_H
;
initFBO
(
texWidth
,
texHeight
);
}
extern
"C"
void
setProcessingMode
(
int
mode
)
{
switch
(
mode
)
{
case
PROC_MODE_CPU
:
procMode
=
PROC_MODE_CPU
;
break
;
case
PROC_MODE_OCL_DIRECT
:
procMode
=
PROC_MODE_OCL_DIRECT
;
break
;
case
PROC_MODE_OCL_OCV
:
procMode
=
PROC_MODE_OCL_OCV
;
break
;
}
}
samples/android/tutorial-4-opencl/jni/jni.c
View file @
56bde913
...
...
@@ -4,6 +4,7 @@ int initGL();
void
closeGL
();
void
changeSize
(
int
width
,
int
height
);
void
drawFrame
();
void
setProcessingMode
(
int
mode
);
JNIEXPORT
jint
JNICALL
Java_org_opencv_samples_tutorial4_NativeGLRenderer_initGL
(
JNIEnv
*
env
,
jclass
cls
)
{
...
...
@@ -24,3 +25,8 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial4_NativeGLRenderer_drawFr
{
drawFrame
();
}
JNIEXPORT
void
JNICALL
Java_org_opencv_samples_tutorial4_NativeGLRenderer_setProcessingMode
(
JNIEnv
*
env
,
jclass
cls
,
jint
mode
)
{
setProcessingMode
(
mode
);
}
samples/android/tutorial-4-opencl/res/layout/activity.xml
View file @
56bde913
...
...
@@ -7,10 +7,20 @@
android:layout_height=
"match_parent"
android:id=
"@+id/my_gl_surface_view"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/fps_text_view"
android:text=
"FPS:"
/>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation =
"vertical"
>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/fps_text_view"
android:text=
"FPS:"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/proc_mode_text_view"
android:text=
"Processing mode:"
/>
</LinearLayout>
</FrameLayout>
samples/android/tutorial-4-opencl/res/menu/menu.xml
0 → 100644
View file @
56bde913
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<group
android:checkableBehavior=
"single"
>
<item
android:id=
"@+id/cpu"
android:title=
"Use CPU code"
/>
<item
android:id=
"@+id/ocl_direct"
android:title=
"Use OpenCL direct"
/>
<item
android:id=
"@+id/ocl_ocv"
android:title=
"Use OpenCL via OpenCV"
/>
</group>
</menu>
samples/android/tutorial-4-opencl/src/org/opencv/samples/tutorial4/MyGLSurfaceView.java
View file @
56bde913
package
org
.
opencv
.
samples
.
tutorial4
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.opengl.GLSurfaceView
;
import
android.util.AttributeSet
;
import
android.view.MotionEvent
;
import
android.view.SurfaceHolder
;
import
android.widget.TextView
;
...
...
@@ -53,4 +55,11 @@ public class MyGLSurfaceView extends GLSurfaceView {
mRenderer
.
onPause
();
super
.
onPause
();
}
@Override
public
boolean
onTouchEvent
(
MotionEvent
e
)
{
if
(
e
.
getAction
()
==
MotionEvent
.
ACTION_DOWN
)
((
Activity
)
getContext
()).
openOptionsMenu
();
return
true
;
}
}
samples/android/tutorial-4-opencl/src/org/opencv/samples/tutorial4/NativeGLRenderer.java
View file @
56bde913
...
...
@@ -6,8 +6,14 @@ public class NativeGLRenderer {
System
.
loadLibrary
(
"opencv_java3"
);
System
.
loadLibrary
(
"JNIrender"
);
}
public
static
final
int
PROCESSING_MODE_CPU
=
1
;
public
static
final
int
PROCESSING_MODE_OCL_DIRECT
=
2
;
public
static
final
int
PROCESSING_MODE_OCL_OCV
=
3
;
public
static
native
int
initGL
();
public
static
native
void
closeGL
();
public
static
native
void
drawFrame
();
public
static
native
void
changeSize
(
int
width
,
int
height
);
public
static
native
void
setProcessingMode
(
int
mode
);
}
samples/android/tutorial-4-opencl/src/org/opencv/samples/tutorial4/Tutorial4Activity.java
View file @
56bde913
...
...
@@ -3,6 +3,9 @@ package org.opencv.samples.tutorial4;
import
android.app.Activity
;
import
android.content.pm.ActivityInfo
;
import
android.os.Bundle
;
import
android.view.Menu
;
import
android.view.MenuInflater
;
import
android.view.MenuItem
;
import
android.view.Window
;
import
android.view.WindowManager
;
import
android.widget.TextView
;
...
...
@@ -10,6 +13,7 @@ import android.widget.TextView;
public
class
Tutorial4Activity
extends
Activity
{
private
MyGLSurfaceView
mView
;
private
TextView
mProcMode
;
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
@@ -27,7 +31,14 @@ public class Tutorial4Activity extends Activity {
mView
=
(
MyGLSurfaceView
)
findViewById
(
R
.
id
.
my_gl_surface_view
);
TextView
tv
=
(
TextView
)
findViewById
(
R
.
id
.
fps_text_view
);
mView
.
setFpsTextView
(
tv
);
}
mProcMode
=
(
TextView
)
findViewById
(
R
.
id
.
proc_mode_text_view
);
runOnUiThread
(
new
Runnable
()
{
public
void
run
()
{
mProcMode
.
setText
(
"Processing mode: CPU"
);
}
});
NativeGLRenderer
.
setProcessingMode
(
NativeGLRenderer
.
PROCESSING_MODE_CPU
);
}
@Override
protected
void
onPause
()
{
...
...
@@ -40,4 +51,43 @@ public class Tutorial4Activity extends Activity {
super
.
onResume
();
mView
.
onResume
();
}
@Override
public
boolean
onCreateOptionsMenu
(
Menu
menu
)
{
MenuInflater
inflater
=
getMenuInflater
();
inflater
.
inflate
(
R
.
menu
.
menu
,
menu
);
return
super
.
onCreateOptionsMenu
(
menu
);
}
@Override
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
switch
(
item
.
getItemId
())
{
case
R
.
id
.
cpu
:
runOnUiThread
(
new
Runnable
()
{
public
void
run
()
{
mProcMode
.
setText
(
"Processing mode: CPU"
);
}
});
NativeGLRenderer
.
setProcessingMode
(
NativeGLRenderer
.
PROCESSING_MODE_CPU
);
return
true
;
case
R
.
id
.
ocl_direct
:
runOnUiThread
(
new
Runnable
()
{
public
void
run
()
{
mProcMode
.
setText
(
"Processing mode: OpenCL direct"
);
}
});
NativeGLRenderer
.
setProcessingMode
(
NativeGLRenderer
.
PROCESSING_MODE_OCL_DIRECT
);
return
true
;
case
R
.
id
.
ocl_ocv
:
runOnUiThread
(
new
Runnable
()
{
public
void
run
()
{
mProcMode
.
setText
(
"Processing mode: OpenCL via OpenCV (TAPI)"
);
}
});
NativeGLRenderer
.
setProcessingMode
(
NativeGLRenderer
.
PROCESSING_MODE_OCL_OCV
);
return
true
;
default
:
return
false
;
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment