- #include "stdafx.h"
- #include <opencv2/OpenCV.hpp>
- #include <string>
- int _tmain(int argc, _TCHAR* argv[])
- { string strImageName = "F:\\base.jpg";
- IplImage *imgSrc, *imgTmp;
- imgSrc = cvLoadImage(strImageName.c_str(), 2 | 4);
- imgTmp = cvCreateImage(cvGetSize(imgSrc), IPL_DEPTH_8U, 1);
- cvSetZero(imgTmp);
- if (imgSrc->nChannels == 3)
- {
- cvCvtColor(imgSrc, imgTmp, CV_BGR2GRAY);
- }
- else
- {
- cvCopy(imgSrc, imgTmp);
- }
- CvMoments moments;
- CvHuMoments humoments;
- cvMoments(imgTmp, &moments, 0);
- cvGetHuMoments(&moments, &humoments);
- cout<<humoments.hu1<<" "<<humoments.hu2<<" "<<humoments.hu3<<" "<<humoments.hu4<<" "<<humoments.hu5<<" "<<humoments.hu6<<" "<<humoments.hu7<<endl;
- cvReleaseImage(&imgSrc);
- cvReleaseImage(&imgTmp);
- return 0;
- }
- /* Spatial and central moments */
- typedef struct CvMoments
- {
- double m00, m10, m01, m20, m11, m02, m30, m21, m12, m03; /* spatial moments */
- double mu20, mu11, mu02, mu30, mu21, mu12, mu03; /* central moments */
- double inv_sqrt_m00; /* m00 != 0 ? 1/sqrt(m00) : 0 */
- }
- CvMoments;
- /* Hu invariants */
- typedef struct CvHuMoments
- {
- double hu1, hu2, hu3, hu4, hu5, hu6, hu7; /* Hu invariants */
- }
- CvHuMoments;
除特别注明外,本站所有文章均为 赢咖4注册 原创,转载请注明出处来自利用Hu不变矩进行特征提取