2011-07-14 22 views
1

我有一個使用SURF檢測相似圖像的過程,我想添加一張支票以知道哪些圖像是真實的相機照片,哪些是矢量圖像,如地圖屏幕截圖的徽標。在C++中使用OpenCV檢測剪貼畫或矢量圖像

例子

照片:http://images.gta-travel.com/HH/Images/J/TYO/TYO-NEW3-8.jpg

標誌:http://estaticos.transhotel.com/img/fotos/hoteles/000137/hft000137578_005.jpg

標誌:http://live.viajesurbis.com/vuweb/content/fichashotel/13127/HOTEL_13127_2.jpg

我試圖尋找在灰度直方圖(和彩色柱狀圖),但沒有給我足夠的信息知道哪一個是矢量或不是。

回答

1

好的,解決它,下一個代碼清理直方圖,獲取所有顏色的灰度和計算不同的顏色。也許在將來我會測試是否使用組件直方圖改進算法。

CvHistogram* wImage::getHistogram() { 
    IplImage* gray = cvCreateImage(cvGetSize(this->image), 8, 1); 

    CvHistogram* hist; 
    int hist_size = 256; 
    float range[] = {0, 256}; 
    float* ranges[] = {range}; 

    cvCvtColor(this->image, gray, CV_RGB2GRAY); 
    hist = cvCreateHist(1, &hist_size, CV_HIST_ARRAY, ranges, 1); 
    cvCalcHist(&gray, hist, 0, NULL); 

    return hist; 
} 

bool wImage::isVectorial() { 

    CvHistogram* hist = this->getHistogram(); 

    int height = 240; 

    float max_value = 0, min_value = 0; 
    cvGetMinMaxHistValue(hist, &min_value, &max_value); 

    int total = 0; 
    int colors = 0; 

    float value; 
    int normalized; 

    for(int i=0; i < 256; i++){ 
     value = cvQueryHistValue_1D(hist, i); 
     normalized = cvRound(value * height/max_value); 

     if(normalized < 2 || normalized > 230) { 
      continue; 
     } 

     colors++; 
     total += normalized; 
    } 

    if((total < 500 && colors < 100) || (total < 1000 && colors < 85)) { 
     return true; 
    } 

    return false; 
}