I am quite new to `OpenCV`, I am trying to write quite a simple program in `OpenCV` to convert a `rgb` image to `grayscale`.
JNIEXPORT jint Java_NativeClass_convertGray
(JNIEnv *env, jobject, jlong addrRgba, jlong addrGray) {
Mat& mRgb = *(Mat*) addrRgba;
Mat& mGray = *(Mat*) addrGray;
int conv;
jint retVal;
conv = toGray(mRgb, mGray);
retVal = (jint) conv;
return retVal;
}
int toGray(Mat& img, Mat& gray){
cvtColor( (InputArray) img, (OutputArray) gray, CV_RGBA2GRAY, 0);
if(gray.rows == img.rows && gray.cols == img.cols)
return 1;
else
return 0;
}
I am unable to call the `cvtColor` function. I can't pass a `Mat` object also to the function like this. It is written in here that `InputArray` and` OutputArray` are created from Mat.
cvtColor(img, gray, CV_RGBA2GRAY, 0);
I get the following error.
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o: In function `Java__NativeClass_convertGray(_JNIEnv*, _jobject*, long long, long long)':
/mobile/src/main/cpp/native-lib.cpp:13: undefined reference to `toGray'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o: In function `Mat':
/usr/local/include/opencv2/core/mat.inl.hpp:400: undefined reference to `cv::Mat::copySize(cv::Mat const&)'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o: In function `~Mat':
/usr/local/include/opencv2/core/mat.inl.hpp:571: undefined reference to `cv::fastFree(void*)'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o: In function `toGray(cv::Mat&, cv::Mat&)':
/mobile/src/main/cpp/native-lib.cpp:24: undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o: In function `cv::Mat::release()':
/usr/local/include/opencv2/core/mat.inl.hpp:682: undefined reference to `cv::Mat::deallocate()'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
What should be done to fix it. I am writing the code in `Android-NDK` and `OpenCV 3.1.0`
↧