V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
oneone
V2EX  ›  程序员

赚外快啦:现金200悬赏用C语言实现图片查找的简单函数

  •  
  •   oneone · 2013-08-26 14:45:34 +08:00 · 5172 次点击
    这是一个创建于 3901 天前的主题,其中的信息可能已经有所发展或是发生改变。
    就是需要实现这样几个函数:

    struct location {
    float x;
    float y;
    };

    1、从图片imageFindFrom中,查找所有的imageToFind,将找到的图片的左上角位置放在array<location>中返回。

    array<location> findImages(imageToFind, imageFindFrom);

    2、同上,只是查找中忽略colorValue这个颜色的像素点。

    array<location> findImagesIgnoreColor(imageFoFind, imageFindFrom, colorValue);

    3、从图片imageFindFrom中,按fuzzyValue模糊查找所有的imageToFind,将找到的图片的左上角位置放在array<location>中返回。模糊值为0到1,模糊查找即有多少百分比的“像素点-位置”匹配,即算匹配的。

    array<location> findImagesFuzzily(imageToFind, imageFindFrom, fuzzyValue);

    4、同上,只是查找中忽略colorValue这个颜色的像素点。
    array<location> findImagesFuzzilyIgnoreColor(imageToFind, imageFindFrom, colorValue, fuzzyValue);

    有意向的勇士可以加2744331610,期待!
    第 1 条附言  ·  2013-08-26 16:21:26 +08:00
    比如图片A的内容是一个围棋的棋盘,图片B的内容是一颗黑子。找图就是要从图片A中将所有的B图的坐标找出来。
    22 条回复    1970-01-01 08:00:00 +08:00
    dorentus
        1
    dorentus  
       2013-08-26 15:12:28 +08:00
    作业题?
    Keyes
        2
    Keyes  
       2013-08-26 15:20:16 +08:00
    @dorentus 看似是,不过这没看很懂……根据什么搜索图片……条件呢
    oneone
        3
    oneone  
    OP
       2013-08-26 15:28:34 +08:00
    @Keyes 就是找图片,比如图片A的内容是一个围棋的棋盘,图片B是的内容是以一颗黑子。找图就是要从图片A中将所有的B图的坐标找出来。
    icenan2
        4
    icenan2  
       2013-08-26 15:41:02 +08:00   ❤️ 1
    你这没说太明白嘛,用什么图像处理的库?
    passluo
        5
    passluo  
       2013-08-26 15:44:35 +08:00   ❤️ 1
    200。。。。外快。。。我觉得这还是发到猪八戒上去吧。。。
    felix021
        6
    felix021  
       2013-08-26 15:51:59 +08:00
    Python的话写起来应该会比较快。
    LetFoxRun
        7
    LetFoxRun  
       2013-08-26 15:58:40 +08:00
    需要图像处理的知识,不会。
    oneone
        8
    oneone  
    OP
       2013-08-26 16:07:07 +08:00
    @icenan2 随便
    oneone
        9
    oneone  
    OP
       2013-08-26 16:08:17 +08:00
    @passluo 你会吗?
    oneone
        10
    oneone  
    OP
       2013-08-26 16:15:05 +08:00
    @passluo 价钱可以商量
    jesse_luo
        11
    jesse_luo  
       2013-08-26 22:41:20 +08:00
    为什么觉得是C++……
    liuyl
        12
    liuyl  
       2013-08-26 22:49:32 +08:00
    模板匹配吧?拿opencv改一改就好了
    msg7086
        13
    msg7086  
       2013-08-27 04:41:30 +08:00
    以前图像处理课上是用matlab的矩阵运算来做的。

    如果是精确像素点匹配的话倒还是容易,直接像做strcmp那样比像素点就行了。

    如果是相似匹配的话,我觉得200肯定是拿不下来的,2000到20000应该差不多吧。
    raptor
        14
    raptor  
       2013-08-27 09:23:40 +08:00
    精确匹配除非是无损图像格式,用JPEG之类有损的话,必须相似匹配
    10iii
        15
    10iii  
       2013-08-27 10:24:44 +08:00   ❤️ 1
    说个思路吧,不管时间复杂度:
    struct image {
    int w;
    int h;
    int* buf;
    } imageFoFind, imageFindFrom;

    findImagesFuzzilyIgnoreColor(imageToFind, imageFindFrom, colorValue, fuzzyValue) {
    int i,j;
    for (i=0;i<imageFindFrom.w-imageToFind.w;i++)
    for (j=0;j<imageFindFrom.h-imageToFind.h;j++)
    if match(imageToFind, imageFindFrom, colorValue, fuzzyValue,i,j) location.push([i,j]);
    return location;
    }

    int match (imageToFind, imageFindFrom, colorValue, fuzzyValue,i,j) {
    int max=imageToFind.w*imageToFind.h*(1-fuzzyValue);
    int d=0,x,y;
    for (x=0;x<imageToFind.w;x++)
    for (y=0;y<imageToFind.h;y++) {
    if ((imageToFind.buf[x][y]!=imageFindFrom[i+x][j+y])&&(imageFindFrom[i+x][j+y]!=colorValue)&&(imageToFind.buf[x][y]!=colorValue)) d++;
    if d>max return 0;
    }
    return 1;
    }

    基本就这样吧。不排除语法错误,编译肯定通不过。
    oneone
        16
    oneone  
    OP
       2013-08-27 20:42:59 +08:00
    @10iii 实在是厉害又仗义,多谢了!
    pubby
        17
    pubby  
       2013-08-27 20:47:07 +08:00
    @oneone 难道B和A的比例是一样的,不用考虑缩放吗?
    oneone
        18
    oneone  
    OP
       2013-08-27 21:20:04 +08:00
    @pubby 如果考虑的话该怎么做呢?
    linzhi
        19
    linzhi  
       2013-08-27 22:04:30 +08:00
    @oneone SIFT特征提取 OpenCV
    msg7086
        20
    msg7086  
       2013-08-28 03:01:15 +08:00   ❤️ 1
    楼主有兴趣的话可以来读一下我们的课程PPT。有介绍最基本的SIFT和HOG算法之类的东西。

    http://web.engr.oregonstate.edu/~sinisa/courses/OSU/CS556/CS556Slides.html
    passluo
        21
    passluo  
       2013-08-28 03:08:00 +08:00 via Android
    看了大家的回答,对我之前的回复感动羞耻与忏悔…我太低俗了…sorry…
    oneone
        22
    oneone  
    OP
       2013-08-28 09:14:42 +08:00
    @msg7086 Thank you so much, that's very valuable and helpful.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2446 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 14:50 · PVG 22:50 · LAX 07:50 · JFK 10:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.