From cd05d9aaadd85271f0ac32c32d1f0327028ada98 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Sat, 15 Sep 2012 15:36:37 +0400 Subject: [PATCH] Fix build of Java API for Windows --- modules/java/CMakeLists.txt | 4 +++- modules/java/generator/gen_java.py | 18 ++++++++++++------ modules/java/generator/src/cpp/Mat.cpp | 18 +++++++++++------- modules/java/generator/src/cpp/converters.cpp | 10 +++++----- .../generator/src/cpp/features2d_manual.hpp | 2 ++ 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/modules/java/CMakeLists.txt b/modules/java/CMakeLists.txt index 29b6a0b58..4b23effbc 100644 --- a/modules/java/CMakeLists.txt +++ b/modules/java/CMakeLists.txt @@ -187,7 +187,9 @@ set_target_properties(${the_module} PROPERTIES LINK_INTERFACE_LIBRARIES "" ) -install(TARGETS ${the_module} LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main) +install(TARGETS ${the_module} + LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main + ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main) set(lib_target ${the_module}_library) if(ANDROID) diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py index 474f53a0c..7d9dc8f07 100644 --- a/modules/java/generator/gen_java.py +++ b/modules/java/generator/gen_java.py @@ -462,8 +462,10 @@ JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Core_n_1getTextSize env->SetDoubleArrayRegion(result, 0, 2, fill); - if (baseLine != NULL) - env->SetIntArrayRegion(baseLine, 0, 1, pbaseLine); + if (baseLine != NULL) { + jint jbaseLine = (jint)(*pbaseLine); + env->SetIntArrayRegion(baseLine, 0, 1, &jbaseLine); + } return result; @@ -872,13 +874,17 @@ public class %(jc)s { #include "converters.h" #if defined DEBUG && defined ANDROID -#include -#define MODULE_LOG_TAG "OpenCV.%(m)s" -#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, MODULE_LOG_TAG, __VA_ARGS__)) +# include +# define MODULE_LOG_TAG "OpenCV.%(m)s" +# define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, MODULE_LOG_TAG, __VA_ARGS__)) #else //DEBUG -#define LOGD(...) +# define LOGD(...) #endif //DEBUG +#ifdef _MSC_VER +# pragma warning(disable:4800 4244) +#endif + #include "opencv2/%(m)s/%(m)s.hpp" using namespace cv; diff --git a/modules/java/generator/src/cpp/Mat.cpp b/modules/java/generator/src/cpp/Mat.cpp index ddafe4d23..66e41b5f1 100644 --- a/modules/java/generator/src/cpp/Mat.cpp +++ b/modules/java/generator/src/cpp/Mat.cpp @@ -18,6 +18,10 @@ #define LOGD(...) #endif +#ifdef _MSC_VER +# pragma warning(disable:4800) +#endif + #include "opencv2/core/core.hpp" using namespace cv; @@ -2170,7 +2174,7 @@ template static int mat_put(cv::Mat* m, int row, int col, int count, if(! buff) return 0; count *= sizeof(T); - int rest = ((m->rows - row) * m->cols - col) * m->elemSize(); + int rest = ((m->rows - row) * m->cols - col) * (int)m->elemSize(); if(count>rest) count = rest; int res = count; @@ -2179,14 +2183,14 @@ template static int mat_put(cv::Mat* m, int row, int col, int count, memcpy(m->ptr(row, col), buff, count); } else { // row by row - int num = (m->cols - col) * m->elemSize(); // 1st partial row + int num = (m->cols - col) * (int)m->elemSize(); // 1st partial row if(countptr(row++, col); while(count>0){ memcpy(data, buff, num); count -= num; buff += num; - num = m->cols * m->elemSize(); + num = m->cols * (int)m->elemSize(); if(countptr(row++, 0); } @@ -2330,7 +2334,7 @@ template int mat_get(cv::Mat* m, int row, int col, int count, char* if(! buff) return 0; int bytesToCopy = count * sizeof(T); - int bytesRestInMat = ((m->rows - row) * m->cols - col) * m->elemSize(); + int bytesRestInMat = ((m->rows - row) * m->cols - col) * (int)m->elemSize(); if(bytesToCopy > bytesRestInMat) bytesToCopy = bytesRestInMat; int res = bytesToCopy; @@ -2339,7 +2343,7 @@ template int mat_get(cv::Mat* m, int row, int col, int count, char* memcpy(buff, m->ptr(row, col), bytesToCopy); } else { // row by row - int bytesInRow = (m->cols - col) * m->elemSize(); // 1st partial row + int bytesInRow = (m->cols - col) * (int)m->elemSize(); // 1st partial row while(bytesToCopy > 0) { int len = std::min(bytesToCopy, bytesInRow); @@ -2348,7 +2352,7 @@ template int mat_get(cv::Mat* m, int row, int col, int count, char* buff += len; row++; col = 0; - bytesInRow = m->cols * m->elemSize(); + bytesInRow = m->cols * (int)m->elemSize(); } } return res; @@ -2525,7 +2529,7 @@ JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Mat_nGet jdoubleArray res = env->NewDoubleArray(me->channels()); if(res){ - jdouble buff[me->channels()]; + jdouble buff[CV_CN_MAX];//me->channels() int i; switch(me->depth()){ case CV_8U: for(i=0; ichannels(); i++) buff[i] = *((unsigned char*) me->ptr(row, col) + i); break; diff --git a/modules/java/generator/src/cpp/converters.cpp b/modules/java/generator/src/cpp/converters.cpp index 380ed3810..9153dde11 100644 --- a/modules/java/generator/src/cpp/converters.cpp +++ b/modules/java/generator/src/cpp/converters.cpp @@ -198,12 +198,12 @@ void Mat_to_vector_KeyPoint(Mat& mat, vector& v_kp) void vector_KeyPoint_to_Mat(vector& v_kp, Mat& mat) { - int count = v_kp.size(); + int count = (int)v_kp.size(); mat.create(count, 1, CV_32FC(7)); for(int i=0; i >(i, 0) = Vec(kp.pt.x, kp.pt.y, kp.size, kp.angle, kp.response, kp.octave, kp.class_id); + mat.at< Vec >(i, 0) = Vec(kp.pt.x, kp.pt.y, kp.size, kp.angle, kp.response, (float)kp.octave, (float)kp.class_id); } } #endif @@ -231,7 +231,7 @@ void Mat_to_vector_Mat(cv::Mat& mat, std::vector& v_mat) void vector_Mat_to_Mat(std::vector& v_mat, cv::Mat& mat) { - int count = v_mat.size(); + int count = (int)v_mat.size(); mat.create(count, 1, CV_32SC2); for(int i=0; i& v_dm) void vector_DMatch_to_Mat(vector& v_dm, Mat& mat) { - int count = v_dm.size(); + int count = (int)v_dm.size(); mat.create(count, 1, CV_32FC4); for(int i=0; i >(i, 0) = Vec(dm.queryIdx, dm.trainIdx, dm.imgIdx, dm.distance); + mat.at< Vec >(i, 0) = Vec((float)dm.queryIdx, (float)dm.trainIdx, (float)dm.imgIdx, dm.distance); } } #endif diff --git a/modules/java/generator/src/cpp/features2d_manual.hpp b/modules/java/generator/src/cpp/features2d_manual.hpp index 32bdc2641..38331c668 100644 --- a/modules/java/generator/src/cpp/features2d_manual.hpp +++ b/modules/java/generator/src/cpp/features2d_manual.hpp @@ -6,6 +6,8 @@ #ifdef HAVE_OPENCV_FEATURES2D #include "opencv2/features2d/features2d.hpp" +#undef SIMPLEBLOB // to solve conflict with wincrypt.h on windows + namespace cv {