Skip to content

Instantly share code, notes, and snippets.

@vrunoa
Last active June 3, 2016 21:42
Show Gist options
  • Save vrunoa/f3b39aae10dafe30a8ed7930862834ba to your computer and use it in GitHub Desktop.
Save vrunoa/f3b39aae10dafe30a8ed7930862834ba to your computer and use it in GitHub Desktop.
cv::cvtColor fail
// trying to convert Luv image to BGR
JNIEXPORT jboolean JNICALL Java_com_test_run(JNIEnv* env, jobject thiz, jlong data) {
__android_log_write(ANDROID_LOG_INFO, "TEST", "run");
if(data == 0) {
__android_log_write(ANDROID_LOG_ERROR, "TEST", "empty jlong mat");
return false;
}
cv::Mat frame = *((cv::Mat*)data);
if(frame.empty()) {
return false;
}
cv::Mat bgr = cv::Mat(frame.rows, frame.cols);
cv::cvtColor(frame, bgr, cv::COLOR_Luv2BGR);
cv::Mat rotated;
cv::Point2f center(frame.cols/2.0F, frame.rows/2.0F);
cv::Mat rot = getRotationMatrix2D(center, 90, 1.0);
cv::warpAffine(frame, rotated, rot, frame.size());
return doCollStuff(rotated.data);
}
/* throws this error
* 05-31 21:02:23.021 22356-22854/? E/cv::error(): OpenCV Error: Assertion failed (scn == 3 && (dcn == 3 || dcn == 4) && (depth == CV_8U || depth == CV_32F)) in void cv::cvtColor(cv::InputArray, cv::OutputArray, int, int), file /builds/master_pack-android/opencv/modules/imgproc/src/color.cpp, line 8291
*/
@mshabunin
Copy link

I guess your bgr Mat initialization is wrong. Try to create it like this: cv::Mat(frame.rows, frame.cols, CV_8UC3); Also, try to check images configurations using Mat::channels() and Mat::depth() methods.

@vrunoa
Copy link
Author

vrunoa commented Jun 3, 2016

@mshabunin thanks for your reply. Actually the image provided by android opencv wasn't Luv, was actually RGBA, I thought it was Luv since it looks "violet" when I saved it. I fixed changing cv::cvtColor(frame, bgr, CV_RGBA2BGR);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment