私は今opencvのmatchshapesを使って二つの画像の類似度を求めようとしています。
ソースコードはこちらです。
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/opencv_lib.hpp>
#include <stdio.h>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char *argv[])
{
//画像読み込み 画像1
Mat input1 = imread("image1.png");
if(!input1.data) return -1;
//画像読み込み 画像2
Mat input2 = imread("image2.png");
if(!input2.data) return -1;
cvtColor(input1, input1, CV_BGR2GRAY);//グレースケールに変換する
cvtColor(input2, input2, CV_BGR2GRAY);//グレースケールに変換する
threshold(input1, input1, 128, 255, THRESH_BINARY_INV);
threshold(input2, input2, 128, 255, THRESH_BINARY_INV);
input1.convertTo(input1, CV_32F);
input2.convertTo(input2, CV_32F);
cout << "input1" << input1.size() << endl;
cout << "input2" << input2.size() << endl;
cout << "version: " << CV_VERSION << endl;
double similarity = 0;
similarity = matchShapes(input1, input2, CV_CONTOURS_MATCH_I1, 0);
cout << "similarity" << similarity << endl;
}
OpenCV Error: Assertion failed (contour1.checkVector(2) >= 0 && contour2.checkVe
ctor(2) >= 0 && (contour1.depth() == CV_32F || contour1.depth() == CV_32S) && co
ntour1.depth() == contour2.depth()) in cv::matchShapes, file ..\..\..\..\opencv\
modules\imgproc\src\contours.cpp, line 1936
エラーの内容を見て、CV_32Fに変換したり、二つの画像の深度を揃えたりしましたが、改善しませんでした。
エラーの内容を検索して調べましたが、有用な情報を見つけることができませんでした。
このエラーの改善方法を知りたいです。
環境は以下の通りです。
OS:windows7 enterprise
言語:c++
opencv:version2.4.9
使用しているソフト:visual studio 2010
宜しくお願いします。