1

我有一个使用 SURF 检测相似图像的过程,我想添加一个检查以了解哪些图像是真实的相机照片,哪些是矢量图像,如地图屏幕截图的徽标。

例子

照片: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

我尝试查看灰色直方图(和颜色直方图),但没有给我足够的信息来知道哪个是矢量图。

4

1 回答 1

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;
}
于 2011-07-15T09:05:42.327 回答