'OpenCV Error: Assertion failed (channels() == CV_MAT_CN (dtype))
I'm having a lot of time trying to get solve this problem. This is the following error in my log file (Android)
error()﹕ OpenCV Error: Assertion failed (channels() == CV_MAT_CN(dtype)) in void cv::Mat::copyTo(cv::OutputArray) const, file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/copy.cpp, line 212
I'm totally stumped. The Java code passes in the long values generated from the .getNativeObjAddr() calls.
Does anyone know about this error? I cannot trace the error(jni c++) in android.
Solution 1:[1]
Same problem. Apart from the gray/color number of channels problem, it could be that you do not send the proper structure to a function, in my case std::vector< cv::Point2d > in cv::solvePnP().
I did:
...
std::vector<cv::KeyPoint> keypoints;
_blob_detector->detect(image, keypoints);
cv::solvePnP(_model_points, keypoints, _camera_matrix, _dist_coeffs, _rotation_vector, _translation_vector);
// error 215 because sending cv::Keypoints vector instead of cv::Point2d vector
// (same thing if trying to send a cv::Mat as second argument)
What works is sending a simple and proper std::vector of cv::Point2d:
...
std::vector<cv::KeyPoint> keypoints;
_blob_detector->detect(image, keypoints);
// copying to the correct structure
std::vector<cv::Point2d> image_points;
for (auto & keypoint : keypoints) image_points.push_back(keypoint.pt);
cv::solvePnP(_model_points, image_points, _camera_matrix, _dist_coeffs, _rotation_vector, _translation_vector);
// no error
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | PJ127 |
