matchshapeができない

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
syokkupan
記事: 4
登録日時: 9年前

matchshapeができない

#1

投稿記事 by syokkupan » 8年前

こんにちは。
私は今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

宜しくお願いします。

kk

Re: matchshapeができない

#2

投稿記事 by kk » 8年前

CV_Assert(contour1.checkVector(2) >= 0 && contour2.checkVector(2) >= 0 &&
(contour1.depth() == CV_32F || contour1.depth() == CV_32S) &&
contour1.depth() == contour2.depth());
を対象のプログラム直下に書くとわかります。
私の場合は、checkVector(2)  = -1でした。

kk

Re: matchshapeができない

#3

投稿記事 by kk » 8年前

int Mat::checkVector(int _elemChannels, int _depth, bool _requireContinuous) const
{
return (depth() == _depth || _depth <= 0) &&
(isContinuous() || !_requireContinuous) &&
((dims == 2 && (((rows == 1 || cols == 1) && channels() == _elemChannels) ||
(cols == _elemChannels && channels() == 1))) ||
(dims == 3 && channels() == 1 && size.p[2] == _elemChannels && (size.p[0] == 1 || size.p[1] == 1) &&
(isContinuous() || step.p[1] == step.p[2]*size.p[2])))
? (int)(total()*channels()/_elemChannels) : -1;
}
ちなみにソースはこちらでした。

閉鎖

“C言語何でも質問掲示板” へ戻る