HU不变矩OPENCV计算方法
#include "cv.h"
#include "highgui.h"
#include <iostream>
using namespace std;
IplImage* oriImg;
IplImage* grayImg;
int Img2Gray(void)
{
if((oriImg = cvLoadImage("E://1.BMP", 1)) != 0 )
{ grayImg = cvCreateImage(cvSize(oriImg->width,oriImg->height),IPL_DEPTH_8U,1);
cvCvtColor(oriImg,grayImg,CV_BGR2GRAY);
return 1;}
return 0;
}
int main( int argc, char** argv )
{
int succees = 0;
succees = Img2Gray();
if(succees)
{
CvMoments moments;
CvHuMoments hu;
cvMoments(grayImg,&moments,0);
cvGetHuMoments(&moments, &hu);
cvNamedWindow( "Image", 1 );
cvShowImage( "Image", grayImg );
printf("%e\n%e\n%e\n%e\n%e\n%e\n%e\n",hu.hu1,hu.hu2,hu.hu3,hu.hu4,hu.hu5,hu.hu6,hu.hu7);
cvWaitKey(0);
cvReleaseImage( &oriImg );
cvReleaseImage( &grayImg );
cvDestroyWindow( "Image" );
}
return 0;
}