由於某些原因,谷歌沒有使用cvCalcPGH()的好例子,也沒有使用Freeman代碼進行輪廓匹配的其他好例子。所以,我儘量做到:cvCalcPGH用法與cvFindContours
#include "opencv2/opencv.hpp"
#include "opencv2/legacy/legacy.hpp"
int
main(int argc, char* argv[]) {
IplImage* g_gray = cvLoadImage("lisa.png",CV_LOAD_IMAGE_GRAYSCALE);
cvThreshold(g_gray, g_gray, 100, 255, CV_THRESH_BINARY);
CvMemStorage* storage=cvCreateMemStorage(0);
CvSeq* firstContour=NULL;
int a=cvFindContours(g_gray, storage, &firstContour,sizeof(CvChain),CV_RETR_LIST, CV_CHAIN_CODE);
CvHistogram *hist;
int h_bins = 30, s_bins = 30;
float h_ranges[] = { 0, 180 };
float s_ranges[] = { 0, 255 };
int hist_size[] = { h_bins, s_bins };
float* ranges[] = { h_ranges, s_ranges };
hist = cvCreateHist(2, hist_size, CV_HIST_ARRAY, ranges, 1);
if(CV_SEQ_ELTYPE(firstContour) != CV_32SC2) {
printf(":(\n");
}
cvCalcPGH((CvSeq *)firstContour,hist);
return 0;
}
cvFindContours()將運行證明,但cvCalcPGH()將失敗:
$ ./calcpgh
:(
OpenCV Error: Unsupported format or combination of formats (The contour is not valid or the point type is not supported) in cvCalcPGH, file /Users/tonu-samuel/OpenCV-2.4.2/modules/legacy/src/pgh.cpp, line 351
terminate called throwing an exceptionAbort trap: 6
$
OpenCV的是2.4.2,並表示斷言()是CV_SEQ_ELTYPE(contour) != CV_32SC2
我檢查也在我的代碼中。如何解決它不確定。