opencv下计算不变矩
#include "iostream" using namespace std; #include "cv.h" #include "highgui.h" const char* filename = "E:\\beichun_small.jpg"; int main(int argc, char* argv[]) { CvMoments moments; CvHuMoments hu_moments; IplImage* image = cvLoadImage(filename); if (!image) { std::cout << "Failed cvLoadImage\n"; return -1; } IplImage* gray = cvCreateImage(cvSize(image->width, image->height), image->depth, 1); if (!gray) { std::cout << "Failed cvCreateImage\n"; return -1; } cvCvtColor(image, gray, CV_RGB2GRAY); cvMoments(gray, &moments, 0); cvGetHuMoments(&moments, &hu_moments); cout << " " << hu_moments.hu1 << " " << hu_moments.hu2 << " " << hu_moments.hu3 << " " << hu_moments.hu4 << " " << hu_moments.hu5 << " " << hu_moments.hu6 << " " << hu_moments.hu7 << ".\n"; cvReleaseImage(&image); cvReleaseImage(&gray); }
只是简单地针对一张图像计算不变矩,具体的原理还没看呢!呵呵!