在 C++ 中使用 OpenCV 检测剪贴画或矢量图像

发布于 2024-11-24 02:51:37 字数 712 浏览 1 评论 0原文

我有一个使用 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

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

I have a process that detects similar images using SURF and I want to add a check to know which images are real camera photos and which ones are vectorial images like logos of map-screenshots.

Examples:

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

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

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

I tried looking at the grey histogram (and color histogram) but nothing gives me enough info to know which one are vectorials or not.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟─花易冷 2024-12-01 02:51:37

好的,解决了,下一个代码是清理直方图,获取灰度中的所有颜色并计算不同颜色的数量。也许将来我会测试使用组件直方图是否可以改进算法。

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;
}

Ok, solved it, the next code is cleaning the histogram, getting all colors in grey scale and counting the different colors. Maybe in the future I will test if working with the components histograms improves the algorithm.

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文