How to find the same cv::Mat in vector<cv::Mat>

webdeb

The title says everything..

For my little image recognition project, I am doing a matching between my queryDescriptors and the vectorOfTrainingDescriptors.

So, what I would like to add, is first to check if the same image was already used / exists in my training data..

I was thinking this should be a simple task, and tried the following:

int findTheSameMat(const cv::Mat MatQ, const vector<cv::Mat> MatV) {
    int result = -1;
    for (int i = 0; i < MatV.size(); i++) {
        if (cv::countNonZero(MatQ != MatV[i]) == 0) {
            result = i;
            break;
        }
    }

    return result;
}

.. But I get the following error message:

OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same type), nor 'array op scalar', nor 'scalar op array') in compare, file /tmp/opencv-HEsb4m/opencv-2.4.9/modules/core/src/arithm.cpp, line 2465 libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /tmp/opencv-HEsb4m/opencv-2.4.9/modules/core/src/arithm.cpp:2465: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same type), nor 'array op scalar', nor 'scalar op array' in function compare

This is strange, because the types of MatQ && MatV[i] should be the same.. They are defined as

Mat MatQ;
vector<Mat> MatV;

Any ideas? Because I am a C++ noob.

herohuyongtao

MatQ != MatV[i] requires that MatQ and MatV[i] are with the same size, i.e. same width and height.

To make it work, you can first check whether their sizes are the same. You only need to do the next check if they do have the same size. Like

if (MatQ.size() == MatV[i].size()) {
    if (cv::countNonZero(MatQ != MatV[i]) == 0) {
        result = i;
        break;
    }
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

cv :: Mat引数のOpenCVstd :: vector

分類Dev

vector <cv :: Mat>で同じcv :: Matを見つける方法

分類Dev

How to convert cv::Mat to pcl::pointcloud

分類Dev

Should I initialize a cv::Mat

分類Dev

How can I serialize cv::Mat objects using protobuf?

分類Dev

cv :: Mat :: t()とcv :: transpose()の違い

分類Dev

A better way to add text to ca cv::Mat than cv::putText()?

分類Dev

2 cv :: Matを比較する

分類Dev

openCV cv :: matリリース

分類Dev

cv :: Mat要素ごとの逆数

分類Dev

OpenCV 2.4 : Displaying a cv::Mat in MFC

分類Dev

cv :: Matとarma :: matの間の変換

分類Dev

'cv :: Mat *'から 'const cv :: Mat'に変換できません

分類Dev

cv :: Matの下部を別のcv :: Matにコピーする

分類Dev

How can I determine whether a cv::Mat is using internal or external data?

分類Dev

cv :: Matがvector <rectangle>を返すためのC ++スレッド非同期

分類Dev

cv :: MatをMFCCBitmapに変換する方法

分類Dev

cv :: Matをcv :: Vec3fに変換する方法は?

分類Dev

cv :: Scalarをcv :: Matに割り当てる方法は?

分類Dev

cv :: Matからarma :: matに変換します

分類Dev

cv :: multiplyなどのopencv関数をstd :: vector <cv :: Mat>と入力および出力引数として使用できますか?

分類Dev

cv :: MatをCV_8UC1に正しく変換する方法は?

分類Dev

あるcv :: Matを別のcv :: Matにプッシュすると、それがコピーされますか?

分類Dev

タイプ「Emgu.CV.Mat」を「Emgu.CV.Image <Emgu.CV.Structure.Bgr、byte>」に変換します

分類Dev

cv :: Mat.refcount OpenCV3.0にありません

分類Dev

OpenCV3.0でCvMat *をcv :: Matに変換する方法

分類Dev

OpenCvでのcv :: Matの外部(テンソル)積の計算

分類Dev

cv :: Matをpcl :: pointcloudに変換する方法

分類Dev

C ++でcv :: Matのメモリを完全に解放する方法

Related 関連記事

  1. 1

    cv :: Mat引数のOpenCVstd :: vector

  2. 2

    vector <cv :: Mat>で同じcv :: Matを見つける方法

  3. 3

    How to convert cv::Mat to pcl::pointcloud

  4. 4

    Should I initialize a cv::Mat

  5. 5

    How can I serialize cv::Mat objects using protobuf?

  6. 6

    cv :: Mat :: t()とcv :: transpose()の違い

  7. 7

    A better way to add text to ca cv::Mat than cv::putText()?

  8. 8

    2 cv :: Matを比較する

  9. 9

    openCV cv :: matリリース

  10. 10

    cv :: Mat要素ごとの逆数

  11. 11

    OpenCV 2.4 : Displaying a cv::Mat in MFC

  12. 12

    cv :: Matとarma :: matの間の変換

  13. 13

    'cv :: Mat *'から 'const cv :: Mat'に変換できません

  14. 14

    cv :: Matの下部を別のcv :: Matにコピーする

  15. 15

    How can I determine whether a cv::Mat is using internal or external data?

  16. 16

    cv :: Matがvector <rectangle>を返すためのC ++スレッド非同期

  17. 17

    cv :: MatをMFCCBitmapに変換する方法

  18. 18

    cv :: Matをcv :: Vec3fに変換する方法は?

  19. 19

    cv :: Scalarをcv :: Matに割り当てる方法は?

  20. 20

    cv :: Matからarma :: matに変換します

  21. 21

    cv :: multiplyなどのopencv関数をstd :: vector <cv :: Mat>と入力および出力引数として使用できますか?

  22. 22

    cv :: MatをCV_8UC1に正しく変換する方法は?

  23. 23

    あるcv :: Matを別のcv :: Matにプッシュすると、それがコピーされますか?

  24. 24

    タイプ「Emgu.CV.Mat」を「Emgu.CV.Image <Emgu.CV.Structure.Bgr、byte>」に変換します

  25. 25

    cv :: Mat.refcount OpenCV3.0にありません

  26. 26

    OpenCV3.0でCvMat *をcv :: Matに変換する方法

  27. 27

    OpenCvでのcv :: Matの外部(テンソル)積の計算

  28. 28

    cv :: Matをpcl :: pointcloudに変換する方法

  29. 29

    C ++でcv :: Matのメモリを完全に解放する方法

ホットタグ

アーカイブ