ãã¹ãã°ã©ã ã®æ¯è¼
OpenCVã使ã£ã¦ãã¹ãã°ã©ã ã®æ¯è¼ãè¡ã£ã¦ã¿ãã
ã©ããããã¨ããã¨ãäºã¤ã®ç»åã®ãã¹ãã°ã©ã ãè¨ç®ãã¦ãããcvCompareHistãç¨ãã¦ããããæ¯è¼ããã°ããã
ä»åã¯ä»¥ä¸ã®äºã¤ã®ç»åã使ã£ã¦ã¿ããèªåã®æã®ç»åã§ãã
myhand1.jpg
myhand2.jpg
cvCompareHistã«ã¯åã¤ã®ã¡ã½ãã(CorrelationãChi-squareãIntersectionãBhattacharyya distance)ããµãã¼ãããã¦ããã
- Correlationãç¨ããã¨
- çµæãé«ãã»ããããããããã¦ãã
- å®ç§ãªãããã ã£ãå ´åã¯1
- å®ç§ãªãã¹ãããã®å ´åã¯-1
- Chi-squareãç¨ããã¨
- çµæãä½ãã»ããããããããã¦ãã
- å®ç§ãªãããã ã£ãå ´åã¯0
- å®ç§ãªãã¹ãããã ã£ãå ´åã¯ééã®ãªãå¤ãå¾ããã(ãã¹ãã°ã©ã ã®ãµã¤ãºã«ä¾åãã)
- Intersectionãç¨ããã¨
- çµæãé«ãã»ããããããããã¦ãã
- ãã¹ãã°ã©ã ã1ã«ãã¼ãã©ã¤ãºããã¦ããå ´å
- å®ç§ãªãããã ã£ãå ´åã¯1
- å®ç§ãªãã¹ãããã ã£ãå ´åã¯0
- Bhattacharyya distanceãç¨ããã¨
- çµæãä½ãã»ããããããããã¦ãã
- å®ç§ãªãããã ã£ãå ´åã¯0
- å®ç§ãªãã¹ãããã ã£ãå ´åã¯1
Learning OpenCVã«ããã¨ãéããæ±ããå ´åã«ã¯Intersectionãæ£ç¢ºããæ±ããå ´åã«ã¯Bhattacharyya distanceãChi-squareãç¨ããã®ãããã¨ã®ãã¨ã
#include <cv.h> #include <highgui.h> #include <stdio.h> int main(void) { IplImage *src1 = 0, *src2 = 0; IplImage *dst1[4] = {0, 0, 0, 0}, *dst2[4] = {0, 0, 0, 0}; CvHistogram *hist1, *hist2; int sch1 = 0, sch2 = 0; int hist_size = 256; float range_0[] = { 0, 256 }; float *ranges[] = { range_0 }; src1 = cvLoadImage("myhand1.jpg", CV_LOAD_IMAGE_COLOR); src2 = cvLoadImage("myhand2.jpg", CV_LOAD_IMAGE_COLOR); if(src1 == 0 || src2 == 0){ return -1; } sch1 = src1->nChannels; sch2 = src2->nChannels; if(sch1 != sch2){ return -1; } for(int i=0;i<sch1;i++) { dst1[i] = cvCreateImage (cvSize (src1->width, src1->height), src1->depth, 1); dst2[i] = cvCreateImage (cvSize (src2->width, src2->height), src2->depth, 1); } //ãã¹ãã°ã©ã æ§é ä½ãç¢ºä¿ hist1 = cvCreateHist (1, &hist_size, CV_HIST_ARRAY, ranges, 1); hist2 = cvCreateHist (1, &hist_size, CV_HIST_ARRAY, ranges, 1); //å ¥åç»åããã«ããã£ã³ãã«ã®å ´åï¼ç»åããã£ã³ãã«æ¯ã«åå² if (sch1 == 1) { cvCopy (src1, dst1[0], NULL); cvCopy (src2, dst2[0], NULL); }else{ cvSplit (src1, dst1[0], dst1[1], dst1[2], dst1[3]); cvSplit (src2, dst2[0], dst2[1], dst2[2], dst2[3]); } //ãã¹ãã°ã©ã ã®è¨ç® for(int i= 0;i<sch1;i++){ cvCalcHist (&dst1[i], hist1, 0, NULL); cvCalcHist (&dst2[i], hist2, 0, NULL); cvNormalizeHist(hist1, 1.0); cvNormalizeHist(hist2, 1.0); } printf("ãã¹ãã°ã©ã ã®æ¯è¼\n"); printf("Correlation(CV_COMP_CORREL) : %f\n",cvCompareHist( hist1, hist2, CV_COMP_CORREL)); printf("Chi-square(CV_COMP_CHSQR) : %f\n",cvCompareHist( hist1, hist2, CV_COMP_CHISQR)); printf("Intersection(CV_COMP_INTERSECT) : %f\n",cvCompareHist( hist1, hist2, CV_COMP_INTERSECT)); printf("Bhattacharyya distance(CV_COMP_BHATTACHARYYA) : %f\n",cvCompareHist( hist1, hist2, CV_COMP_BHATTACHARYYA)); return 0; }
ã»å®è¡çµæ
ãã¹ãã°ã©ã ã®æ¯è¼ Correlation(CV_COMP_CORREL) : 0.870168 Chi-square(CV_COMP_CHSQR) : 0.075862 Intersection(CV_COMP_INTERSECT) : 0.847536 Bhattacharyya distance(CV_COMP_BHATTACHARYYA) : 0.139961