Commit b5d73111 authored by Andrey Kamaev's avatar Andrey Kamaev

Added new module for Java API

parent f0624c08
......@@ -97,4 +97,4 @@ SET( ENABLE_SSE42 OFF CACHE INTERNAL "" FORCE )
SET( ENABLE_SSSE3 OFF CACHE INTERNAL "" FORCE )
#Set output folder to ${CMAKE_BINARY_DIR}
set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_BINARY_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" )
\ No newline at end of file
set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_BINARY_DIR} CACHE PATH "root for library output, set this to change where android libs are compiled to" )
......@@ -5,6 +5,7 @@ if(ANDROID)
endif()
add_subdirectory(androidcamera)
add_subdirectory(java)
endif()
add_subdirectory(calib3d)
......
# ----------------------------------------------------------------------------
# CMake file for java support
# ----------------------------------------------------------------------------
project(opencv_java)
SET(OPENCV_JAVA_MODULES objdetect features2d imgproc video highgui ml core)
SET(OPENCV_EXTRA_JAVA_MODULES calib3d contrib legacy flann)
IF(ANDROID AND NOT BUILD_SHARED_LIBS)
LIST(APPEND OPENCV_EXTRA_JAVA_MODULES androidcamera)
ENDIF()
SET(GEN_JAVA "${CMAKE_CURRENT_SOURCE_DIR}/gen_java.py")
SET(HDR_PARSER "${CMAKE_CURRENT_SOURCE_DIR}/../python/src2/hdr_parser.py")
foreach(module ${OPENCV_JAVA_MODULES})
IF(${module} STREQUAL core)
SET (module_cppheaders "${CMAKE_CURRENT_SOURCE_DIR}/../${module}/include/opencv2/${module}/${module}.hpp")
SET (module_cheaders "")
ELSE()
FILE(GLOB module_cheaders "${CMAKE_CURRENT_SOURCE_DIR}/../${module}/include/opencv2/${module}/*.h")
FILE(GLOB module_cppheaders "${CMAKE_CURRENT_SOURCE_DIR}/../${module}/include/opencv2/${module}/*.hpp")
ENDIF()
list(SORT module_cheaders)
list(SORT module_cppheaders)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${module}.java
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp
COMMAND ${PYTHON_EXECUTABLE} -B "${GEN_JAVA}" "${HDR_PARSER}" ${module} ${module_cheaders} ${module_cppheaders}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${GEN_JAVA}
DEPENDS ${HDR_PARSER}
DEPENDS ${module_headers}
)
endforeach()
set(target "opencv_java")
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
FILE(GLOB handwrittren_cpp_sources "${CMAKE_CURRENT_SOURCE_DIR}/srccpp/*.cpp")
SET (generated_cpp_sources "")
SET (generated_java_sources "")
SET (dependent_libs "")
SET (dependent_extra_libs "")
foreach(module ${OPENCV_JAVA_MODULES})
LIST(APPEND generated_cpp_sources "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp")
LIST(APPEND generated_java_sources "${CMAKE_CURRENT_BINARY_DIR}/${module}.java")
LIST(APPEND dependent_libs opencv_${module})
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../${module}/include")
endforeach()
foreach(module ${OPENCV_EXTRA_JAVA_MODULES})
LIST(APPEND dependent_extra_libs opencv_${module})
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../${module}/include")
endforeach()
#SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L/home/andreyk/OpenCV2/trunk/opencv/android/build/libs/armeabi-v7a")
add_library(${target} SHARED ${handwrittren_cpp_sources} ${generated_cpp_sources})
target_link_libraries(${target} ${dependent_libs} ${dependent_extra_libs} ${OPENCV_LINKER_LIBS})
if(ANDROID)
target_link_libraries(${target} jnigraphics)
endif()
#add_dependencies(${the_target} ${dependent_extra_libs} ${dependent_libs})
# Additional target properties
set_target_properties(${target} PROPERTIES
OUTPUT_NAME "${target}"
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
INSTALL_NAME_DIR lib
)
add_custom_target(opecv_java_api ALL DEPENDS ${target})
IF(ANDROID)
# create Android library project in build folder
add_custom_command(TARGET opecv_java_api COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/res")
FILE(GLOB android_lib_project_files "${CMAKE_CURRENT_SOURCE_DIR}/android/*")
foreach(lib_file ${android_lib_project_files})
if(NOT IS_DIRECTORY ${lib_file})
add_custom_command(TARGET opecv_java_api COMMAND ${CMAKE_COMMAND} -E copy "${lib_file}" "${CMAKE_BINARY_DIR}" DEPENDS "${lib_file}")
endif()
endforeach()
ENDIF()
FILE(GLOB java_project_files "${CMAKE_CURRENT_SOURCE_DIR}/srcjava/*.java")
SET(JAVA_OUTPUT_DIR "${CMAKE_BINARY_DIR}/src/org/opencv")
add_custom_command(TARGET opecv_java_api COMMAND ${CMAKE_COMMAND} -E make_directory "${JAVA_OUTPUT_DIR}")
foreach(java_file ${java_project_files} ${generated_java_sources})
add_custom_command(TARGET opecv_java_api COMMAND ${CMAKE_COMMAND} -E copy "${java_file}" "${JAVA_OUTPUT_DIR}" DEPENDS "${java_file}" DEPENDS "${JAVA_OUTPUT_DIR}")
endforeach()
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>OpenCVJavaAPI</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.opencv.JavaAPI"
android:versionCode="1"
android:versionName="1.0">
<application android:label="OpenCVJavaAPI">
<activity android:name="OpenCVJavaAPI"
android:label="OpenCVJavaAPI">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.
android.library=true
# Project target.
target=android-8
This diff is collapsed.
This diff is collapsed.
#include <jni.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_opencv_utils
* Method: nBitmapToMat(Bitmap b)
* Signature: (L)J
*/
JNIEXPORT jlong JNICALL Java_org_opencv_utils_nBitmapToMat
(JNIEnv *, jclass, jobject);
/*
* Class: org_opencv_utils
* Method: nBitmapToMat(long m, Bitmap b)
* Signature: (JL)Z
*/
JNIEXPORT jboolean JNICALL Java_org_opencv_utils_nMatToBitmap
(JNIEnv *, jclass, jlong, jobject);
#ifdef __cplusplus
}
#endif
#include "opencv2/core/core.hpp"
#include <android/bitmap.h>
JNIEXPORT jlong JNICALL Java_org_opencv_utils_nBitmapToMat
(JNIEnv * env, jclass cls, jobject bitmap)
{
AndroidBitmapInfo info;
void* pixels;
cv::Mat* m = NULL;
if ( AndroidBitmap_getInfo(env, bitmap, &info) < 0 )
return 0; // can't get info
if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888)
return 0; // incompatible format
if ( AndroidBitmap_lockPixels(env, bitmap, &pixels) < 0 )
return 0; // can't get pixels
m = new cv::Mat(info.height, info.width, CV_8UC4);
memcpy(m->data, pixels, info.height * info.width * 4);
AndroidBitmap_unlockPixels(env, bitmap);
return (jlong)m;
}
JNIEXPORT jboolean JNICALL Java_org_opencv_utils_nMatToBitmap
(JNIEnv * env, jclass cls, jlong m, jobject bitmap)
{
AndroidBitmapInfo info;
void* pixels;
cv::Mat* mat = (cv::Mat*) m;
if ( m == 0 )
return false; // no native Mat behind
if ( AndroidBitmap_getInfo(env, bitmap, &info) < 0 )
return false; // can't get info
if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888)
return false; // incompatible format
if ( AndroidBitmap_lockPixels(env, bitmap, &pixels) < 0 )
return false; // can't get pixels
memcpy(pixels, mat->data, info.height * info.width * 4);
AndroidBitmap_unlockPixels(env, bitmap);
return true;
}
This diff is collapsed.
package org.opencv;
public class Point {
public double x, y;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public Point() {
this(0, 0);
}
public Point clone() {
return new Point(x, y);
}
public double dot(Point p) {
return x * p.x + y * p.y;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if ( ! (obj instanceof Point) ) return false;
Point it = (Point) obj;
return x == it.x && y == it.y;
}
public boolean inside(Rect r) {
return r.contains(this);
}
}
package org.opencv;
public class Point3 {
public double x, y, z;
public Point3(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public Point3() {
this(0, 0, 0);
}
public Point3(Point p) {
x = p.x;
y = p.y;
z = 0;
}
public Point3 clone() {
return new Point3(x, y, z);
}
public double dot(Point3 p) {
return x * p.x + y * p.y + z * p.z;
}
public Point3 cross(Point3 p) {
return new Point3(y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(z);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Point3)) return false;
Point3 it = (Point3) obj;
return x == it.x && y == it.y && z == it.z;
}
}
package org.opencv;
public class Rect {
int x, y, width, height;
public Rect(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public Rect() {
this(0, 0, 0, 0);
}
public Rect(Point p1, Point p2) {
x = (int) (p1.x < p2.x ? p1.x : p2.x);
y = (int) (p1.y < p2.y ? p1.y : p2.y);
width = (int) (p1.x > p2.x ? p1.x : p2.x) - x;
height = (int) (p1.y > p2.y ? p1.y : p2.y) - y;
}
public Rect(Point p, Size s) {
this((int)p.x, (int)p.y, s.width, s.height);
}
public Rect clone() {
return new Rect(x, y, width, height);
}
public Point tl() {
return new Point(x, y);
}
public Point br() {
return new Point(x + width, y + height);
}
public Size size() {
return new Size(width, height);
}
public double area() {
return width * height;
}
public boolean contains(Point p) {
return x <= p.x && p.x < x + width && y <= p.y && p.y < y + height;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(height);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(width);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Rect)) return false;
Rect it = (Rect) obj;
return x == it.x && y == it.y && width == it.width && height == it.height;
}
}
package org.opencv;
public class Scalar {
public double v0, v1, v2, v3;
public Scalar(double v0, double v1, double v2, double v3) {
this.v0 = v0;
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
}
public Scalar(double v0, double v1, double v2) {
this(v0, v1, v2, 0);
}
public Scalar(double v0, double v1) {
this(v0, v1, 0, 0);
}
public Scalar(double v0) {
this(v0, 0, 0, 0);
}
public static Scalar all(double v) {
return new Scalar(v, v, v, v);
}
public Scalar clone() {
return new Scalar(v0, v1, v2, v3);
}
public Scalar mul(Scalar it, double scale) {
return new Scalar( v0 * it.v0 * scale, v1 * it.v1 * scale,
v2 * it.v2 * scale, v3 * it.v3 * scale );
}
public Scalar mul(Scalar it) {
return mul(it, 1);
}
public Scalar conj() {
return new Scalar(v0, -v1, -v2, -v3);
}
public boolean isReal() {
return v1 == 0 && v2 == 0 && v3 == 0;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(v0);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(v1);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(v2);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(v3);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Scalar)) return false;
Scalar it = (Scalar) obj;
return v0 == it.v0 && v1 == it.v1 && v2 == it.v2 && v3 == it.v3;
}
}
package org.opencv;
public class Size {
public int width, height;
public Size(int width, int height) {
this.width = width;
this.height = height;
}
public Size() {
this(0, 0);
}
public Size(Point p) {
width = (int) p.x;
height = (int) p.y;
}
public double area() {
return width * height;
}
public Size clone() {
return new Size(width, height);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(height);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(width);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Size)) return false;
Size it = (Size) obj;
return width == it.width && height == it.height;
}
}
package org.opencv;
import android.graphics.Bitmap;
public class utils {
public static Mat BitmapToMat(Bitmap b) {
return new Mat( nBitmapToMat(b) );
}
public static boolean MatToBitmap(Mat m, Bitmap b) {
return nMatToBitmap(m.nativeObj, b);
}
// native stuff
static { System.loadLibrary("opencv_java"); }
private static native long nBitmapToMat(Bitmap b);
private static native boolean nMatToBitmap(long m, Bitmap b);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment