기본 이미지와 일치하는 이미지가 14 개인 이미지 (0 ~ 9 및 */- +)와 비교해야하는 기본 이미지 (숫자 또는 연산자)가 있습니다.히스토그램 비교를 사용한 이미지 일치 C++
기본 이미지의 막대 그래프를 만들고 루프를 사용하여 14 개의 이미지 막대 그래프 모두를 만들고 히스토그램을 정규화했습니다.
루프에서 새로 생성 된 히스토그램 각각에 대해 compareHist() 함수를 사용하여 기본 막대 그래프와 비교했습니다. 그리고 결과 double 값을 출력합니다.
I 값의 특정 집합을 얻고있다 : 상관 관계 또는 카이 제곱 또는 교차로 또는 Bhattacharyya의 방법을 사용하여
. 그리고 다른베이스을 사용할 때, 나는 여전히 같은 값들을 얻고 있습니다.
왜 내가이 문제가 발생합니까? 다른베이스에 다른 값을 얻기 위해 normalize 함수를 변경해야합니까?
CODE :
void matchHistogram(){
Mat src_base, hsv_base;
Mat src_test1, hsv_test1;
/// Histograms
MatND hist_base;
MatND hist_test1;
/// Using 30 bins for hue and 32 for saturation
int h_bins = 30; int s_bins = 32;
int histSize[] = { h_bins, s_bins };
// hue varies from 0 to 255, saturation from 0 to 180
float h_ranges[] = { 0, 255 };
float s_ranges[] = { 0, 180 };
const float* ranges[] = { h_ranges, s_ranges };
// Use the o-th and 1-st channels
int channels[] = { 0, 1 };
for(int i=0;i<noOfcropped;i++){ //get base image //noOfCropped is number of base images i'll compare to 14 images
cout<<" "<<i<<endl;
stringstream croppedimage;
croppedimage<<"CroppedImages/croppedImage"<<i;
croppedimage<<".jpg";
src_base = imread(croppedimage.str(), 1);
imshow(croppedimage.str(),src_base);
/// Convert to HSV
cvtColor(src_base, hsv_base, CV_BGR2HSV);
/// Calculate the histogram for the HSV images
calcHist(&hsv_base, 1, channels, Mat(), hist_base, 2, histSize, ranges);
normalize(hist_base, hist_base, 0, 1, NORM_MINMAX, -1, Mat());
for(int j=0;j<14;j++){//comparing 1 croppedimage with each different characters
cout<<" "<<j<<endl;
stringstream test1;
test1<<"ImagesToCompare/"<<j;
test1<<".jpg";
src_test1 = imread(test1.str(), 1);
/// Convert to HSV
cvtColor(src_test1, hsv_test1, CV_BGR2HSV);
/// Calculate the histogram for the HSV images
calcHist(&hsv_test1, 1, channels, Mat(), hist_test1, 2, histSize, ranges);
normalize(hist_test1, hist_test1, 0, 1,NORM_MINMAX, -1, Mat());
/// Apply the histogram comparison methods
int compare_method = 0;
//when 0 or 2, highest comparison values>> best match
//when 1 or 3, lowest comparison values>> best match
double base_test1 = compareHist(hist_base, hist_test1, compare_method);
cout<<base_test1<<endl;
}
}
}
1) 히스토그램을 사용해야하나요? 2) 이미지의 동일한 세트와 비교하여 정확한 사본 (너비, 높이, 해상도 등)을 비교하고 있습니까? – TheDarkKnight
히스토그램을 사용하고 싶지만 다른 간단한 방법이 있으면 구현하려고 할 수 있습니다. 그리고 처음에는 이미지가 같지 않습니다. 방정식 사진 (예 : 5 + 5) 각 요소는 5, +, 5로 추출되었습니다. (추출 부분으로 인해 이미지가 검정색으로 나타납니다 흰색 요소). 이제 각 요소는 14 개의 이미지 집합과 비교하기 위해 사용하는 이미지입니다. 14 이미지는 배경이 흰색이고 요소가 검은 색입니다. – user2919740