[英]Opencv4Android: How to use with C++
我也在嘗試使用適用於Android的opencv構建示例。 這是我的C ++代碼:
頭文件:
#ifdef __cplusplus extern "C" { #endif #include "jni.h" #include "opencv2/core/core.hpp" namespace openCVFuncs { cv::Mat contrastFilter(cv::Mat inputMatm, float contrastValue); } #ifdef __cplusplus } #endif
Cpp文件:
namespace openCVFuncs { cv::Mat contrastFilter(cv::Mat inputMat, float contrastValue) { contrastValue = pow(2,contrastValue); cv::Mat outMat = inputMat.clone(); uchar* data_img_in=(uchar*)inputMat.data; uchar* data_img_out=(uchar*)outMat.data; int temp = 0; for(int i=0;i<inputMat.size().height;i++) for(int j=0;j<inputMat.size().width;j++) for (int c=0;c<inputMat.channels();c++) { temp = (data_img_in+inputMat.step[0]*i)[j*inputMat.channels()+c]; temp = (int)((temp - 128.0) * contrastValue) +128; if (temp < 5) temp = 5; if (temp > 255) temp = 255; (data_img_out+outMat.step[0]*i)[j*outMat.channels()+c] = temp; } return outMat; }; }
我有很多這樣的錯誤:
/opt/android-ndk-r9/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/valarray_before.h:652:3:錯誤:具有C鏈接的模板
我的代碼有什么問題?
當使用“外部C”塊時,您只能使用C可用的東西,從而排除函數重載/多態性,名稱空間等。
在發布的頭文件中,您包含一個.hpp文件(該文件可能包含不可用的定義之一)並定義一個名稱空間。
該頁面提供了一些關於該主題的很好的指針,說明了可以做什么和不能做什么以及如何包裝對C ++名稱空間/重載函數的調用,以供在C編譯器編譯的庫中使用,請參閱“從C源代碼訪問C ++代碼”:
http://www.oracle.com/technetwork/articles/servers-storage-dev/mixingcandcpluspluscode-305840.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.