簡體   English   中英

OpenCV 錯誤:斷言失敗(channels() == CV_MAT_CN (dtype))

[英]OpenCV Error: Assertion failed (channels() == CV_MAT_CN (dtype))

我有很多時間試圖解決這個問題。 這是我的日志文件(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

我完全被難住了。 Java 代碼傳入從 .getNativeObjAddr() 調用生成的長值。

有誰知道這個錯誤? 我無法在 android 中跟蹤錯誤(jni c++)。

同樣的問題。 除了通道的灰度/顏色數量問題外,可能是您沒有將正確的結構發送到函數,在我的情況下是 std::vector<cv::Point2d> in cv::solvePnP()。

我做了:

    ...
    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)

有效的是發送一個簡單而正確的 std::vector 的 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM